1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
|
import junit.framework.*; |
11 |
|
|
12 |
|
public class ConcurrentSkipListMapTest extends JSR166TestCase { |
13 |
|
public static void main(String[] args) { |
14 |
< |
junit.textui.TestRunner.run (suite()); |
14 |
> |
junit.textui.TestRunner.run(suite()); |
15 |
|
} |
16 |
|
public static Test suite() { |
17 |
|
return new TestSuite(ConcurrentSkipListMapTest.class); |
34 |
|
} |
35 |
|
|
36 |
|
/** |
37 |
< |
* clear removes all pairs |
37 |
> |
* clear removes all pairs |
38 |
|
*/ |
39 |
|
public void testClear() { |
40 |
|
ConcurrentSkipListMap map = map5(); |
52 |
|
} |
53 |
|
|
54 |
|
/** |
55 |
< |
* Maps with same contents are equal |
55 |
> |
* Maps with same contents are equal |
56 |
|
*/ |
57 |
|
public void testEquals() { |
58 |
|
ConcurrentSkipListMap map1 = map5(); |
65 |
|
} |
66 |
|
|
67 |
|
/** |
68 |
< |
* containsKey returns true for contained key |
68 |
> |
* containsKey returns true for contained key |
69 |
|
*/ |
70 |
|
public void testContainsKey() { |
71 |
|
ConcurrentSkipListMap map = map5(); |
74 |
|
} |
75 |
|
|
76 |
|
/** |
77 |
< |
* containsValue returns true for held values |
77 |
> |
* containsValue returns true for held values |
78 |
|
*/ |
79 |
|
public void testContainsValue() { |
80 |
|
ConcurrentSkipListMap map = map5(); |
83 |
|
} |
84 |
|
|
85 |
|
/** |
86 |
< |
* get returns the correct element at the given key, |
87 |
< |
* or null if not present |
86 |
> |
* get returns the correct element at the given key, |
87 |
> |
* or null if not present |
88 |
|
*/ |
89 |
|
public void testGet() { |
90 |
|
ConcurrentSkipListMap map = map5(); |
94 |
|
} |
95 |
|
|
96 |
|
/** |
97 |
< |
* isEmpty is true of empty map and false for non-empty |
97 |
> |
* isEmpty is true of empty map and false for non-empty |
98 |
|
*/ |
99 |
|
public void testIsEmpty() { |
100 |
|
ConcurrentSkipListMap empty = new ConcurrentSkipListMap(); |
104 |
|
} |
105 |
|
|
106 |
|
/** |
107 |
< |
* firstKey returns first key |
107 |
> |
* firstKey returns first key |
108 |
|
*/ |
109 |
|
public void testFirstKey() { |
110 |
|
ConcurrentSkipListMap map = map5(); |
112 |
|
} |
113 |
|
|
114 |
|
/** |
115 |
< |
* lastKey returns last key |
115 |
> |
* lastKey returns last key |
116 |
|
*/ |
117 |
|
public void testLastKey() { |
118 |
|
ConcurrentSkipListMap map = map5(); |
119 |
|
assertEquals(five, map.lastKey()); |
120 |
|
} |
121 |
|
|
122 |
– |
|
122 |
|
/** |
123 |
< |
* keySet.toArray returns contains all keys |
123 |
> |
* keySet.toArray returns contains all keys |
124 |
|
*/ |
125 |
|
public void testKeySetToArray() { |
126 |
|
ConcurrentSkipListMap map = map5(); |
133 |
|
} |
134 |
|
|
135 |
|
/** |
136 |
< |
* descendingkeySet.toArray returns contains all keys |
136 |
> |
* descendingkeySet.toArray returns contains all keys |
137 |
|
*/ |
138 |
|
public void testDescendingKeySetToArray() { |
139 |
|
ConcurrentSkipListMap map = map5(); |
146 |
|
} |
147 |
|
|
148 |
|
/** |
149 |
< |
* keySet returns a Set containing all the keys |
149 |
> |
* keySet returns a Set containing all the keys |
150 |
|
*/ |
151 |
|
public void testKeySet() { |
152 |
|
ConcurrentSkipListMap map = map5(); |
160 |
|
} |
161 |
|
|
162 |
|
/** |
163 |
< |
* keySet is ordered |
163 |
> |
* keySet is ordered |
164 |
|
*/ |
165 |
|
public void testKeySetOrder() { |
166 |
|
ConcurrentSkipListMap map = map5(); |
198 |
|
} |
199 |
|
|
200 |
|
/** |
201 |
< |
* descendingKeySet is ordered |
201 |
> |
* descendingKeySet is ordered |
202 |
|
*/ |
203 |
|
public void testDescendingKeySetOrder() { |
204 |
|
ConcurrentSkipListMap map = map5(); |
217 |
|
} |
218 |
|
|
219 |
|
/** |
220 |
< |
* descending iterator of descendingKeySet is ordered |
220 |
> |
* descending iterator of descendingKeySet is ordered |
221 |
|
*/ |
222 |
|
public void testDescendingKeySetDescendingIteratorOrder() { |
223 |
|
ConcurrentSkipListMap map = map5(); |
236 |
|
} |
237 |
|
|
238 |
|
/** |
239 |
< |
* Values.toArray contains all values |
239 |
> |
* Values.toArray contains all values |
240 |
|
*/ |
241 |
|
public void testValuesToArray() { |
242 |
|
ConcurrentSkipListMap map = map5(); |
304 |
|
} |
305 |
|
|
306 |
|
/** |
307 |
< |
* entrySet.toArray contains all entries |
307 |
> |
* entrySet.toArray contains all entries |
308 |
|
*/ |
309 |
|
public void testEntrySetToArray() { |
310 |
|
ConcurrentSkipListMap map = map5(); |
318 |
|
} |
319 |
|
|
320 |
|
/** |
321 |
< |
* descendingEntrySet.toArray contains all entries |
321 |
> |
* descendingEntrySet.toArray contains all entries |
322 |
|
*/ |
323 |
|
public void testDescendingEntrySetToArray() { |
324 |
|
ConcurrentSkipListMap map = map5(); |
332 |
|
} |
333 |
|
|
334 |
|
/** |
335 |
< |
* putAll adds all key-value pairs from the given map |
335 |
> |
* putAll adds all key-value pairs from the given map |
336 |
|
*/ |
337 |
|
public void testPutAll() { |
338 |
|
ConcurrentSkipListMap empty = new ConcurrentSkipListMap(); |
347 |
|
} |
348 |
|
|
349 |
|
/** |
350 |
< |
* putIfAbsent works when the given key is not present |
350 |
> |
* putIfAbsent works when the given key is not present |
351 |
|
*/ |
352 |
|
public void testPutIfAbsent() { |
353 |
|
ConcurrentSkipListMap map = map5(); |
356 |
|
} |
357 |
|
|
358 |
|
/** |
359 |
< |
* putIfAbsent does not add the pair if the key is already present |
359 |
> |
* putIfAbsent does not add the pair if the key is already present |
360 |
|
*/ |
361 |
|
public void testPutIfAbsent2() { |
362 |
|
ConcurrentSkipListMap map = map5(); |
364 |
|
} |
365 |
|
|
366 |
|
/** |
367 |
< |
* replace fails when the given key is not present |
367 |
> |
* replace fails when the given key is not present |
368 |
|
*/ |
369 |
|
public void testReplace() { |
370 |
|
ConcurrentSkipListMap map = map5(); |
373 |
|
} |
374 |
|
|
375 |
|
/** |
376 |
< |
* replace succeeds if the key is already present |
376 |
> |
* replace succeeds if the key is already present |
377 |
|
*/ |
378 |
|
public void testReplace2() { |
379 |
|
ConcurrentSkipListMap map = map5(); |
381 |
|
assertEquals("Z", map.get(one)); |
382 |
|
} |
383 |
|
|
385 |
– |
|
384 |
|
/** |
385 |
|
* replace value fails when the given key not mapped to expected value |
386 |
|
*/ |
401 |
|
assertEquals("Z", map.get(one)); |
402 |
|
} |
403 |
|
|
406 |
– |
|
404 |
|
/** |
405 |
< |
* remove removes the correct key-value pair from the map |
405 |
> |
* remove removes the correct key-value pair from the map |
406 |
|
*/ |
407 |
|
public void testRemove() { |
408 |
|
ConcurrentSkipListMap map = map5(); |
531 |
|
} |
532 |
|
|
533 |
|
|
537 |
– |
|
534 |
|
/** |
535 |
|
* lowerKey returns preceding element |
536 |
|
*/ |
658 |
|
} |
659 |
|
|
660 |
|
/** |
661 |
< |
* size returns the correct values |
661 |
> |
* size returns the correct values |
662 |
|
*/ |
663 |
|
public void testSize() { |
664 |
|
ConcurrentSkipListMap map = map5(); |
674 |
|
ConcurrentSkipListMap map = map5(); |
675 |
|
String s = map.toString(); |
676 |
|
for (int i = 1; i <= 5; ++i) { |
677 |
< |
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
677 |
> |
assertTrue(s.contains(String.valueOf(i))); |
678 |
|
} |
679 |
|
} |
680 |
|
|
713 |
|
} catch (NullPointerException success) {} |
714 |
|
} |
715 |
|
|
720 |
– |
|
716 |
|
/** |
717 |
|
* put(null,x) throws NPE |
718 |
|
*/ |
809 |
|
assertTrue(r.equals(q)); |
810 |
|
} |
811 |
|
|
817 |
– |
|
818 |
– |
|
812 |
|
/** |
813 |
|
* subMap returns map with keys in requested range |
814 |
|
*/ |
973 |
|
* Submaps of submaps subdivide correctly |
974 |
|
*/ |
975 |
|
public void testRecursiveSubMaps() throws Exception { |
976 |
< |
int mapSize = 1000; |
976 |
> |
int mapSize = expensiveTests ? 1000 : 100; |
977 |
|
Class cl = ConcurrentSkipListMap.class; |
978 |
|
NavigableMap<Integer, Integer> map = newMap(cl); |
979 |
|
bs = new BitSet(mapSize); |
1154 |
|
*/ |
1155 |
|
void check(NavigableMap<Integer, Integer> map, |
1156 |
|
final int min, final int max, final boolean ascending) { |
1157 |
< |
class ReferenceSet { |
1157 |
> |
class ReferenceSet { |
1158 |
|
int lower(int key) { |
1159 |
|
return ascending ? lowerAscending(key) : higherAscending(key); |
1160 |
|
} |
1185 |
|
// BitSet should support this! Test would run much faster |
1186 |
|
while (key >= min) { |
1187 |
|
if (bs.get(key)) |
1188 |
< |
return(key); |
1188 |
> |
return key; |
1189 |
|
key--; |
1190 |
|
} |
1191 |
|
return -1; |