2 * (C) Copyright 2016 Pantheon Technologies, s.r.o. and others.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.opendaylight.yangtools.triemap;
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertNull;
20 import static org.junit.Assert.assertTrue;
22 import org.junit.Test;
24 public class TestDelete {
25 @Test(expected = NullPointerException.class)
26 public void testNullSimple() {
27 TrieMap.create().remove(null);
30 @Test(expected = NullPointerException.class)
31 public void testNullKey() {
32 TrieMap.create().remove(null, "");
35 @Test(expected = NullPointerException.class)
36 public void testNullValue() {
37 TrieMap.create().remove("", null);
40 @Test(expected = NullPointerException.class)
41 public void testNullBoth() {
42 TrieMap.create().remove(null, null);
46 public void testClear() {
47 final TrieMap<Integer, Integer> bt = TrieMap.create();
50 assertTrue(bt.isEmpty());
51 assertEquals(0, bt.size());
55 public void testDelete () {
56 final TrieMap<Integer, Integer> bt = TrieMap.create();
58 for (int i = 0; i < 10000; i++) {
59 assertNull(bt.put(Integer.valueOf(i), Integer.valueOf(i)));
60 assertEquals(Integer.valueOf(i), bt.get(Integer.valueOf(i)));
63 checkAddInsert(bt, 536);
64 checkAddInsert(bt, 4341);
65 checkAddInsert(bt, 8437);
67 for (int i = 0; i < 10000; i++) {
68 boolean removed = null != bt.remove(Integer.valueOf(i));
70 final Object lookup = bt.get(Integer.valueOf(i));
78 * Test if the Map.remove(Object, Object) method works correctly for hash collisions, which are handled by LNode.
81 public void testRemoveObjectLNode() {
82 final TrieMap<ZeroHashInt, ZeroHashInt> bt = TrieMap.create();
84 for (int i = 0; i < 100; i++) {
85 final ZeroHashInt v = new ZeroHashInt(i);
86 assertNull(bt.put(v, v));
89 for (int i = 0; i < 100; i++) {
90 final ZeroHashInt v = new ZeroHashInt(i);
91 assertTrue(bt.remove(v, v));
95 private static void checkAddInsert (final TrieMap<Integer, Integer> bt, final int k) {
96 final Integer v = Integer.valueOf(k);
98 Integer foundV = bt.get(v);
100 assertNull(bt.put (v, v));
102 assertEquals(v, foundV);
104 assertEquals(v, bt.put(v, Integer.valueOf(-1)));
105 assertEquals(Integer.valueOf(-1), bt.put(v, v));