4 |
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
– |
import junit.framework.*; |
7 |
|
import java.util.Arrays; |
9 |
– |
import java.util.BitSet; |
10 |
– |
import java.util.Collection; |
8 |
|
import java.util.Comparator; |
9 |
|
import java.util.Iterator; |
10 |
|
import java.util.NavigableSet; |
14 |
– |
import java.util.NoSuchElementException; |
15 |
– |
import java.util.Random; |
16 |
– |
import java.util.Set; |
11 |
|
import java.util.SortedSet; |
12 |
|
import java.util.concurrent.ConcurrentSkipListSet; |
13 |
|
|
14 |
+ |
import junit.framework.Test; |
15 |
+ |
import junit.framework.TestSuite; |
16 |
+ |
|
17 |
|
public class ConcurrentSkipListSubSetTest extends JSR166TestCase { |
18 |
|
public static void main(String[] args) { |
19 |
|
junit.textui.TestRunner.run(suite()); |
29 |
|
} |
30 |
|
|
31 |
|
/** |
32 |
< |
* Create a set of given size containing consecutive |
32 |
> |
* Returns a new set of given size containing consecutive |
33 |
|
* Integers 0 ... n. |
34 |
|
*/ |
35 |
|
private NavigableSet<Integer> populatedSet(int n) { |
37 |
|
new ConcurrentSkipListSet<Integer>(); |
38 |
|
assertTrue(q.isEmpty()); |
39 |
|
|
40 |
< |
for (int i = n-1; i >= 0; i-=2) |
40 |
> |
for (int i = n-1; i >= 0; i -= 2) |
41 |
|
assertTrue(q.add(new Integer(i))); |
42 |
< |
for (int i = (n & 1); i < n; i+=2) |
42 |
> |
for (int i = (n & 1); i < n; i += 2) |
43 |
|
assertTrue(q.add(new Integer(i))); |
44 |
|
assertTrue(q.add(new Integer(-n))); |
45 |
|
assertTrue(q.add(new Integer(n))); |
50 |
|
} |
51 |
|
|
52 |
|
/** |
53 |
< |
* Create set of first 5 ints |
53 |
> |
* Returns a new set of first 5 ints. |
54 |
|
*/ |
55 |
|
private NavigableSet set5() { |
56 |
|
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
68 |
|
} |
69 |
|
|
70 |
|
/** |
71 |
< |
* Create set of first 5 negative ints |
71 |
> |
* Returns a new set of first 5 negative ints. |
72 |
|
*/ |
73 |
|
private NavigableSet dset5() { |
74 |
|
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
241 |
|
*/ |
242 |
|
public void testRemoveElement() { |
243 |
|
NavigableSet q = populatedSet(SIZE); |
244 |
< |
for (int i = 1; i < SIZE; i+=2) { |
244 |
> |
for (int i = 1; i < SIZE; i += 2) { |
245 |
|
assertTrue(q.contains(i)); |
246 |
|
assertTrue(q.remove(i)); |
247 |
|
assertFalse(q.contains(i)); |
248 |
|
assertTrue(q.contains(i-1)); |
249 |
|
} |
250 |
< |
for (int i = 0; i < SIZE; i+=2) { |
250 |
> |
for (int i = 0; i < SIZE; i += 2) { |
251 |
|
assertTrue(q.contains(i)); |
252 |
|
assertTrue(q.remove(i)); |
253 |
|
assertFalse(q.contains(i)); |
326 |
|
assertTrue(q.removeAll(p)); |
327 |
|
assertEquals(SIZE-i, q.size()); |
328 |
|
for (int j = 0; j < i; ++j) { |
329 |
< |
Integer I = (Integer)(p.pollFirst()); |
330 |
< |
assertFalse(q.contains(I)); |
329 |
> |
Integer x = (Integer)(p.pollFirst()); |
330 |
> |
assertFalse(q.contains(x)); |
331 |
|
} |
332 |
|
} |
333 |
|
} |
451 |
|
assertTrue(q.contains(it.next())); |
452 |
|
++i; |
453 |
|
} |
454 |
< |
assertEquals(i, 0); |
454 |
> |
assertEquals(0, i); |
455 |
|
} |
456 |
|
|
457 |
|
/** |
491 |
|
NavigableSet x = populatedSet(SIZE); |
492 |
|
NavigableSet y = serialClone(x); |
493 |
|
|
494 |
< |
assertTrue(x != y); |
494 |
> |
assertNotSame(y, x); |
495 |
|
assertEquals(x.size(), y.size()); |
496 |
|
assertEquals(x, y); |
497 |
|
assertEquals(y, x); |
746 |
|
*/ |
747 |
|
public void testDescendingRemoveElement() { |
748 |
|
NavigableSet q = populatedSet(SIZE); |
749 |
< |
for (int i = 1; i < SIZE; i+=2) { |
749 |
> |
for (int i = 1; i < SIZE; i += 2) { |
750 |
|
assertTrue(q.remove(new Integer(i))); |
751 |
|
} |
752 |
< |
for (int i = 0; i < SIZE; i+=2) { |
752 |
> |
for (int i = 0; i < SIZE; i += 2 ) { |
753 |
|
assertTrue(q.remove(new Integer(i))); |
754 |
|
assertFalse(q.remove(new Integer(i+1))); |
755 |
|
} |
825 |
|
assertTrue(q.removeAll(p)); |
826 |
|
assertEquals(SIZE-i, q.size()); |
827 |
|
for (int j = 0; j < i; ++j) { |
828 |
< |
Integer I = (Integer)(p.pollFirst()); |
829 |
< |
assertFalse(q.contains(I)); |
828 |
> |
Integer x = (Integer)(p.pollFirst()); |
829 |
> |
assertFalse(q.contains(x)); |
830 |
|
} |
831 |
|
} |
832 |
|
} |
951 |
|
assertTrue(q.contains(it.next())); |
952 |
|
++i; |
953 |
|
} |
954 |
< |
assertEquals(i, 0); |
954 |
> |
assertEquals(0, i); |
955 |
|
} |
956 |
|
|
957 |
|
/** |
991 |
|
NavigableSet x = dset5(); |
992 |
|
NavigableSet y = serialClone(x); |
993 |
|
|
994 |
< |
assertTrue(x != y); |
994 |
> |
assertNotSame(y, x); |
995 |
|
assertEquals(x.size(), y.size()); |
996 |
|
assertEquals(x, y); |
997 |
|
assertEquals(y, x); |