4 |
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
– |
import junit.framework.*; |
7 |
|
import java.util.Arrays; |
8 |
|
import java.util.BitSet; |
9 |
|
import java.util.Collection; |
16 |
|
import java.util.SortedSet; |
17 |
|
import java.util.concurrent.ConcurrentSkipListSet; |
18 |
|
|
19 |
+ |
import junit.framework.Test; |
20 |
+ |
import junit.framework.TestSuite; |
21 |
+ |
|
22 |
|
public class ConcurrentSkipListSetTest extends JSR166TestCase { |
23 |
|
public static void main(String[] args) { |
24 |
|
junit.textui.TestRunner.run(suite()); |
41 |
|
ConcurrentSkipListSet<Integer> q = |
42 |
|
new ConcurrentSkipListSet<Integer>(); |
43 |
|
assertTrue(q.isEmpty()); |
44 |
< |
for (int i = n-1; i >= 0; i-=2) |
44 |
> |
for (int i = n-1; i >= 0; i -= 2) |
45 |
|
assertTrue(q.add(new Integer(i))); |
46 |
< |
for (int i = (n & 1); i < n; i+=2) |
46 |
> |
for (int i = (n & 1); i < n; i += 2) |
47 |
|
assertTrue(q.add(new Integer(i))); |
48 |
|
assertFalse(q.isEmpty()); |
49 |
|
assertEquals(n, q.size()); |
284 |
|
*/ |
285 |
|
public void testRemoveElement() { |
286 |
|
ConcurrentSkipListSet q = populatedSet(SIZE); |
287 |
< |
for (int i = 1; i < SIZE; i+=2) { |
287 |
> |
for (int i = 1; i < SIZE; i += 2) { |
288 |
|
assertTrue(q.contains(i)); |
289 |
|
assertTrue(q.remove(i)); |
290 |
|
assertFalse(q.contains(i)); |
291 |
|
assertTrue(q.contains(i-1)); |
292 |
|
} |
293 |
< |
for (int i = 0; i < SIZE; i+=2) { |
293 |
> |
for (int i = 0; i < SIZE; i += 2) { |
294 |
|
assertTrue(q.contains(i)); |
295 |
|
assertTrue(q.remove(i)); |
296 |
|
assertFalse(q.contains(i)); |
369 |
|
assertTrue(q.removeAll(p)); |
370 |
|
assertEquals(SIZE-i, q.size()); |
371 |
|
for (int j = 0; j < i; ++j) { |
372 |
< |
Integer I = (Integer)(p.pollFirst()); |
373 |
< |
assertFalse(q.contains(I)); |
372 |
> |
Integer x = (Integer)(p.pollFirst()); |
373 |
> |
assertFalse(q.contains(x)); |
374 |
|
} |
375 |
|
} |
376 |
|
} |
473 |
|
*/ |
474 |
|
public void testIterator() { |
475 |
|
ConcurrentSkipListSet q = populatedSet(SIZE); |
474 |
– |
int i = 0; |
476 |
|
Iterator it = q.iterator(); |
477 |
< |
while (it.hasNext()) { |
477 |
> |
int i; |
478 |
> |
for (i = 0; it.hasNext(); i++) |
479 |
|
assertTrue(q.contains(it.next())); |
478 |
– |
++i; |
479 |
– |
} |
480 |
|
assertEquals(i, SIZE); |
481 |
+ |
assertIteratorExhausted(it); |
482 |
|
} |
483 |
|
|
484 |
|
/** |
485 |
|
* iterator of empty set has no elements |
486 |
|
*/ |
487 |
|
public void testEmptyIterator() { |
488 |
< |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
489 |
< |
int i = 0; |
490 |
< |
Iterator it = q.iterator(); |
490 |
< |
while (it.hasNext()) { |
491 |
< |
assertTrue(q.contains(it.next())); |
492 |
< |
++i; |
493 |
< |
} |
494 |
< |
assertEquals(0, i); |
488 |
> |
NavigableSet s = new ConcurrentSkipListSet(); |
489 |
> |
assertIteratorExhausted(s.iterator()); |
490 |
> |
assertIteratorExhausted(s.descendingSet().iterator()); |
491 |
|
} |
492 |
|
|
493 |
|
/** |
527 |
|
NavigableSet x = populatedSet(SIZE); |
528 |
|
NavigableSet y = serialClone(x); |
529 |
|
|
530 |
< |
assertTrue(x != y); |
530 |
> |
assertNotSame(x, y); |
531 |
|
assertEquals(x.size(), y.size()); |
532 |
|
assertEquals(x, y); |
533 |
|
assertEquals(y, x); |
726 |
|
// Add entries till we're back to original size |
727 |
|
while (set.size() < size) { |
728 |
|
int element = min + rnd.nextInt(rangeSize); |
729 |
< |
assertTrue(element >= min && element<= max); |
729 |
> |
assertTrue(element >= min && element <= max); |
730 |
|
put(set, element, bs); |
731 |
|
} |
732 |
|
} |
752 |
|
// Add entries till we're back to original size |
753 |
|
while (set.size() < size) { |
754 |
|
int element = min - 5 + rnd.nextInt(rangeSize + 10); |
755 |
< |
if (element >= min && element<= max) { |
755 |
> |
if (element >= min && element <= max) { |
756 |
|
put(set, element, bs); |
757 |
|
} else { |
758 |
|
try { |