21 |
|
|
22 |
|
public class ConcurrentSkipListSetTest extends JSR166TestCase { |
23 |
|
public static void main(String[] args) { |
24 |
< |
junit.textui.TestRunner.run(suite()); |
24 |
> |
main(suite(), args); |
25 |
|
} |
26 |
|
public static Test suite() { |
27 |
|
return new TestSuite(ConcurrentSkipListSetTest.class); |
77 |
|
*/ |
78 |
|
public void testConstructor3() { |
79 |
|
try { |
80 |
< |
ConcurrentSkipListSet q = new ConcurrentSkipListSet((Collection)null); |
80 |
> |
new ConcurrentSkipListSet((Collection)null); |
81 |
|
shouldThrow(); |
82 |
|
} catch (NullPointerException success) {} |
83 |
|
} |
87 |
|
*/ |
88 |
|
public void testConstructor4() { |
89 |
|
try { |
90 |
< |
Integer[] ints = new Integer[SIZE]; |
91 |
< |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints)); |
90 |
> |
new ConcurrentSkipListSet(Arrays.asList(new Integer[SIZE])); |
91 |
|
shouldThrow(); |
92 |
|
} catch (NullPointerException success) {} |
93 |
|
} |
96 |
|
* Initializing from Collection with some null elements throws NPE |
97 |
|
*/ |
98 |
|
public void testConstructor5() { |
99 |
+ |
Integer[] ints = new Integer[SIZE]; |
100 |
+ |
for (int i = 0; i < SIZE - 1; ++i) |
101 |
+ |
ints[i] = new Integer(i); |
102 |
|
try { |
103 |
< |
Integer[] ints = new Integer[SIZE]; |
102 |
< |
for (int i = 0; i < SIZE-1; ++i) |
103 |
< |
ints[i] = new Integer(i); |
104 |
< |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints)); |
103 |
> |
new ConcurrentSkipListSet(Arrays.asList(ints)); |
104 |
|
shouldThrow(); |
105 |
|
} catch (NullPointerException success) {} |
106 |
|
} |
128 |
|
for (int i = 0; i < SIZE; ++i) |
129 |
|
ints[i] = new Integer(i); |
130 |
|
q.addAll(Arrays.asList(ints)); |
131 |
< |
for (int i = SIZE-1; i >= 0; --i) |
131 |
> |
for (int i = SIZE - 1; i >= 0; --i) |
132 |
|
assertEquals(ints[i], q.pollFirst()); |
133 |
|
} |
134 |
|
|
152 |
|
public void testSize() { |
153 |
|
ConcurrentSkipListSet q = populatedSet(SIZE); |
154 |
|
for (int i = 0; i < SIZE; ++i) { |
155 |
< |
assertEquals(SIZE-i, q.size()); |
155 |
> |
assertEquals(SIZE - i, q.size()); |
156 |
|
q.pollFirst(); |
157 |
|
} |
158 |
|
for (int i = 0; i < SIZE; ++i) { |
165 |
|
* add(null) throws NPE |
166 |
|
*/ |
167 |
|
public void testAddNull() { |
168 |
+ |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
169 |
|
try { |
170 |
– |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
170 |
|
q.add(null); |
171 |
|
shouldThrow(); |
172 |
|
} catch (NullPointerException success) {} |
194 |
|
* Add of non-Comparable throws CCE |
195 |
|
*/ |
196 |
|
public void testAddNonComparable() { |
197 |
+ |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
198 |
|
try { |
199 |
– |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
200 |
– |
q.add(new Object()); |
199 |
|
q.add(new Object()); |
200 |
|
q.add(new Object()); |
201 |
|
shouldThrow(); |
206 |
|
* addAll(null) throws NPE |
207 |
|
*/ |
208 |
|
public void testAddAll1() { |
209 |
+ |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
210 |
|
try { |
212 |
– |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
211 |
|
q.addAll(null); |
212 |
|
shouldThrow(); |
213 |
|
} catch (NullPointerException success) {} |
217 |
|
* addAll of a collection with null elements throws NPE |
218 |
|
*/ |
219 |
|
public void testAddAll2() { |
220 |
+ |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
221 |
+ |
Integer[] ints = new Integer[SIZE]; |
222 |
|
try { |
223 |
– |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
224 |
– |
Integer[] ints = new Integer[SIZE]; |
223 |
|
q.addAll(Arrays.asList(ints)); |
224 |
|
shouldThrow(); |
225 |
|
} catch (NullPointerException success) {} |
230 |
|
* possibly adding some elements |
231 |
|
*/ |
232 |
|
public void testAddAll3() { |
233 |
+ |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
234 |
+ |
Integer[] ints = new Integer[SIZE]; |
235 |
+ |
for (int i = 0; i < SIZE - 1; ++i) |
236 |
+ |
ints[i] = new Integer(i); |
237 |
|
try { |
236 |
– |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
237 |
– |
Integer[] ints = new Integer[SIZE]; |
238 |
– |
for (int i = 0; i < SIZE-1; ++i) |
239 |
– |
ints[i] = new Integer(i); |
238 |
|
q.addAll(Arrays.asList(ints)); |
239 |
|
shouldThrow(); |
240 |
|
} catch (NullPointerException success) {} |
247 |
|
Integer[] empty = new Integer[0]; |
248 |
|
Integer[] ints = new Integer[SIZE]; |
249 |
|
for (int i = 0; i < SIZE; ++i) |
250 |
< |
ints[i] = new Integer(SIZE-1-i); |
250 |
> |
ints[i] = new Integer(SIZE - 1 - i); |
251 |
|
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
252 |
|
assertFalse(q.addAll(Arrays.asList(empty))); |
253 |
|
assertTrue(q.addAll(Arrays.asList(ints))); |
271 |
|
*/ |
272 |
|
public void testPollLast() { |
273 |
|
ConcurrentSkipListSet q = populatedSet(SIZE); |
274 |
< |
for (int i = SIZE-1; i >= 0; --i) { |
274 |
> |
for (int i = SIZE - 1; i >= 0; --i) { |
275 |
|
assertEquals(i, q.pollLast()); |
276 |
|
} |
277 |
|
assertNull(q.pollFirst()); |
352 |
|
assertTrue(changed); |
353 |
|
|
354 |
|
assertTrue(q.containsAll(p)); |
355 |
< |
assertEquals(SIZE-i, q.size()); |
355 |
> |
assertEquals(SIZE - i, q.size()); |
356 |
|
p.pollFirst(); |
357 |
|
} |
358 |
|
} |
365 |
|
ConcurrentSkipListSet q = populatedSet(SIZE); |
366 |
|
ConcurrentSkipListSet p = populatedSet(i); |
367 |
|
assertTrue(q.removeAll(p)); |
368 |
< |
assertEquals(SIZE-i, q.size()); |
368 |
> |
assertEquals(SIZE - i, q.size()); |
369 |
|
for (int j = 0; j < i; ++j) { |
370 |
|
Integer x = (Integer)(p.pollFirst()); |
371 |
|
assertFalse(q.contains(x)); |
471 |
|
*/ |
472 |
|
public void testIterator() { |
473 |
|
ConcurrentSkipListSet q = populatedSet(SIZE); |
476 |
– |
int i = 0; |
474 |
|
Iterator it = q.iterator(); |
475 |
< |
while (it.hasNext()) { |
475 |
> |
int i; |
476 |
> |
for (i = 0; it.hasNext(); i++) |
477 |
|
assertTrue(q.contains(it.next())); |
480 |
– |
++i; |
481 |
– |
} |
478 |
|
assertEquals(i, SIZE); |
479 |
+ |
assertIteratorExhausted(it); |
480 |
|
} |
481 |
|
|
482 |
|
/** |
483 |
|
* iterator of empty set has no elements |
484 |
|
*/ |
485 |
|
public void testEmptyIterator() { |
486 |
< |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
487 |
< |
int i = 0; |
488 |
< |
Iterator it = q.iterator(); |
492 |
< |
while (it.hasNext()) { |
493 |
< |
assertTrue(q.contains(it.next())); |
494 |
< |
++i; |
495 |
< |
} |
496 |
< |
assertEquals(0, i); |
486 |
> |
NavigableSet s = new ConcurrentSkipListSet(); |
487 |
> |
assertIteratorExhausted(s.iterator()); |
488 |
> |
assertIteratorExhausted(s.descendingSet().iterator()); |
489 |
|
} |
490 |
|
|
491 |
|
/** |
724 |
|
// Add entries till we're back to original size |
725 |
|
while (set.size() < size) { |
726 |
|
int element = min + rnd.nextInt(rangeSize); |
727 |
< |
assertTrue(element >= min && element<= max); |
727 |
> |
assertTrue(element >= min && element <= max); |
728 |
|
put(set, element, bs); |
729 |
|
} |
730 |
|
} |
750 |
|
// Add entries till we're back to original size |
751 |
|
while (set.size() < size) { |
752 |
|
int element = min - 5 + rnd.nextInt(rangeSize + 10); |
753 |
< |
if (element >= min && element<= max) { |
753 |
> |
if (element >= min && element <= max) { |
754 |
|
put(set, element, bs); |
755 |
|
} else { |
756 |
|
try { |
974 |
|
} |
975 |
|
|
976 |
|
static boolean eq(Integer i, int j) { |
977 |
< |
return i == null ? j == -1 : i == j; |
977 |
> |
return (i == null) ? j == -1 : i == j; |
978 |
|
} |
979 |
|
|
980 |
|
} |