1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 package org.eclipse.jgit.util;
45
46 import static org.junit.Assert.assertEquals;
47 import static org.junit.Assert.assertFalse;
48 import static org.junit.Assert.assertNull;
49 import static org.junit.Assert.assertSame;
50 import static org.junit.Assert.assertTrue;
51
52 import org.junit.Before;
53 import org.junit.Test;
54
55 public class LongMapTest {
56 private LongMap<Long> map;
57
58 @Before
59 public void setUp() throws Exception {
60 map = new LongMap<>();
61 }
62
63 @Test
64 public void testEmptyMap() {
65 assertFalse(map.containsKey(0));
66 assertFalse(map.containsKey(1));
67
68 assertNull(map.get(0));
69 assertNull(map.get(1));
70
71 assertNull(map.remove(0));
72 assertNull(map.remove(1));
73 }
74
75 @Test
76 public void testInsertMinValue() {
77 final Long min = Long.valueOf(Long.MIN_VALUE);
78 assertNull(map.put(Long.MIN_VALUE, min));
79 assertTrue(map.containsKey(Long.MIN_VALUE));
80 assertSame(min, map.get(Long.MIN_VALUE));
81 assertFalse(map.containsKey(Integer.MIN_VALUE));
82 }
83
84 @Test
85 public void testReplaceMaxValue() {
86 final Long min = Long.valueOf(Long.MAX_VALUE);
87 final Long one = Long.valueOf(1);
88 assertNull(map.put(Long.MAX_VALUE, min));
89 assertSame(min, map.get(Long.MAX_VALUE));
90 assertSame(min, map.put(Long.MAX_VALUE, one));
91 assertSame(one, map.get(Long.MAX_VALUE));
92 }
93
94 @Test
95 public void testRemoveOne() {
96 final long start = 1;
97 assertNull(map.put(start, Long.valueOf(start)));
98 assertEquals(Long.valueOf(start), map.remove(start));
99 assertFalse(map.containsKey(start));
100 }
101
102 @Test
103 public void testRemoveCollision1() {
104
105
106
107
108
109
110 assertNull(map.put(0, Long.valueOf(0)));
111 assertNull(map.put(1, Long.valueOf(1)));
112 assertEquals(Long.valueOf(0), map.remove(0));
113
114 assertFalse(map.containsKey(0));
115 assertTrue(map.containsKey(1));
116 }
117
118 @Test
119 public void testRemoveCollision2() {
120
121
122
123
124
125
126 assertNull(map.put(0, Long.valueOf(0)));
127 assertNull(map.put(1, Long.valueOf(1)));
128 assertEquals(Long.valueOf(1), map.remove(1));
129
130 assertTrue(map.containsKey(0));
131 assertFalse(map.containsKey(1));
132 }
133
134 @Test
135 public void testSmallMap() {
136 final long start = 12;
137 final long n = 8;
138 for (long i = start; i < start + n; i++)
139 assertNull(map.put(i, Long.valueOf(i)));
140 for (long i = start; i < start + n; i++)
141 assertEquals(Long.valueOf(i), map.get(i));
142 }
143
144 @Test
145 public void testLargeMap() {
146 final long start = Integer.MAX_VALUE;
147 final long n = 100000;
148 for (long i = start; i < start + n; i++)
149 assertNull(map.put(i, Long.valueOf(i)));
150 for (long i = start; i < start + n; i++)
151 assertEquals(Long.valueOf(i), map.get(i));
152 }
153 }