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 {
26 public void testDelete () {
27 final TrieMap<Integer, Integer> bt = new TrieMap<> ();
29 for (int i = 0; i < 10000; i++) {
30 assertNull(bt.put(Integer.valueOf(i), Integer.valueOf(i)));
31 assertEquals(Integer.valueOf(i), bt.lookup(Integer.valueOf(i)));
34 checkAddInsert(bt, 536);
35 checkAddInsert(bt, 4341);
36 checkAddInsert(bt, 8437);
38 for (int i = 0; i < 10000; i++) {
39 boolean removed = null != bt.remove(Integer.valueOf(i));
41 final Object lookup = bt.lookup (Integer.valueOf(i));
49 * Test if the Map.remove(Object, Object) method works correctly for hash collisions, which are handled by LNode.
52 public void testRemoveObjectLNode() {
53 final TrieMap<ZeroHashInt, ZeroHashInt> bt = new TrieMap<> ();
55 for (int i = 0; i < 100; i++) {
56 final ZeroHashInt v = new ZeroHashInt(i);
57 assertNull(bt.put(v, v));
60 for (int i = 0; i < 100; i++) {
61 final ZeroHashInt v = new ZeroHashInt(i);
62 assertTrue(bt.remove(v, v));
66 private static void checkAddInsert (final TrieMap<Integer, Integer> bt, final int k) {
67 final Integer v = Integer.valueOf(k);
69 Object foundV = bt.lookup(v);
71 assertNull(bt.put (v, v));
72 foundV = bt.lookup(v);
73 assertEquals(v, foundV);
75 assertEquals(v, bt.put(v, Integer.valueOf(-1)));
76 assertEquals(Integer.valueOf(-1), bt.put(v, v));