4 |
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
– |
import junit.framework.*; |
7 |
|
import java.util.Arrays; |
8 |
|
import java.util.Comparator; |
9 |
|
import java.util.Iterator; |
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()); |
19 |
> |
main(suite(), args); |
20 |
|
} |
21 |
|
public static Test suite() { |
22 |
|
return new TestSuite(ConcurrentSkipListSubSetTest.class); |
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))); |
135 |
|
* add(null) throws NPE |
136 |
|
*/ |
137 |
|
public void testAddNull() { |
138 |
+ |
NavigableSet q = set0(); |
139 |
|
try { |
137 |
– |
NavigableSet q = set0(); |
140 |
|
q.add(null); |
141 |
|
shouldThrow(); |
142 |
|
} catch (NullPointerException success) {} |
163 |
|
* Add of non-Comparable throws CCE |
164 |
|
*/ |
165 |
|
public void testAddNonComparable() { |
166 |
+ |
NavigableSet q = set0(); |
167 |
|
try { |
165 |
– |
NavigableSet q = set0(); |
166 |
– |
q.add(new Object()); |
168 |
|
q.add(new Object()); |
169 |
|
q.add(new Object()); |
170 |
|
shouldThrow(); |
175 |
|
* addAll(null) throws NPE |
176 |
|
*/ |
177 |
|
public void testAddAll1() { |
178 |
+ |
NavigableSet q = set0(); |
179 |
|
try { |
178 |
– |
NavigableSet q = set0(); |
180 |
|
q.addAll(null); |
181 |
|
shouldThrow(); |
182 |
|
} catch (NullPointerException success) {} |
186 |
|
* addAll of a collection with null elements throws NPE |
187 |
|
*/ |
188 |
|
public void testAddAll2() { |
189 |
+ |
NavigableSet q = set0(); |
190 |
+ |
Integer[] ints = new Integer[SIZE]; |
191 |
|
try { |
189 |
– |
NavigableSet q = set0(); |
190 |
– |
Integer[] ints = new Integer[SIZE]; |
192 |
|
q.addAll(Arrays.asList(ints)); |
193 |
|
shouldThrow(); |
194 |
|
} catch (NullPointerException success) {} |
199 |
|
* possibly adding some elements |
200 |
|
*/ |
201 |
|
public void testAddAll3() { |
202 |
+ |
NavigableSet q = set0(); |
203 |
+ |
Integer[] ints = new Integer[SIZE]; |
204 |
+ |
for (int i = 0; i < SIZE-1; ++i) |
205 |
+ |
ints[i] = new Integer(i+SIZE); |
206 |
|
try { |
202 |
– |
NavigableSet q = set0(); |
203 |
– |
Integer[] ints = new Integer[SIZE]; |
204 |
– |
for (int i = 0; i < SIZE-1; ++i) |
205 |
– |
ints[i] = new Integer(i+SIZE); |
207 |
|
q.addAll(Arrays.asList(ints)); |
208 |
|
shouldThrow(); |
209 |
|
} catch (NullPointerException success) {} |
240 |
|
*/ |
241 |
|
public void testRemoveElement() { |
242 |
|
NavigableSet q = populatedSet(SIZE); |
243 |
< |
for (int i = 1; i < SIZE; i+=2) { |
243 |
> |
for (int i = 1; i < SIZE; i += 2) { |
244 |
|
assertTrue(q.contains(i)); |
245 |
|
assertTrue(q.remove(i)); |
246 |
|
assertFalse(q.contains(i)); |
247 |
|
assertTrue(q.contains(i-1)); |
248 |
|
} |
249 |
< |
for (int i = 0; i < SIZE; i+=2) { |
249 |
> |
for (int i = 0; i < SIZE; i += 2) { |
250 |
|
assertTrue(q.contains(i)); |
251 |
|
assertTrue(q.remove(i)); |
252 |
|
assertFalse(q.contains(i)); |
325 |
|
assertTrue(q.removeAll(p)); |
326 |
|
assertEquals(SIZE-i, q.size()); |
327 |
|
for (int j = 0; j < i; ++j) { |
328 |
< |
Integer I = (Integer)(p.pollFirst()); |
329 |
< |
assertFalse(q.contains(I)); |
328 |
> |
Integer x = (Integer)(p.pollFirst()); |
329 |
> |
assertFalse(q.contains(x)); |
330 |
|
} |
331 |
|
} |
332 |
|
} |
430 |
|
*/ |
431 |
|
public void testIterator() { |
432 |
|
NavigableSet q = populatedSet(SIZE); |
432 |
– |
int i = 0; |
433 |
|
Iterator it = q.iterator(); |
434 |
< |
while (it.hasNext()) { |
434 |
> |
int i; |
435 |
> |
for (i = 0; it.hasNext(); i++) |
436 |
|
assertTrue(q.contains(it.next())); |
436 |
– |
++i; |
437 |
– |
} |
437 |
|
assertEquals(i, SIZE); |
438 |
+ |
assertIteratorExhausted(it); |
439 |
|
} |
440 |
|
|
441 |
|
/** |
442 |
|
* iterator of empty set has no elements |
443 |
|
*/ |
444 |
|
public void testEmptyIterator() { |
445 |
< |
NavigableSet q = set0(); |
446 |
< |
int i = 0; |
447 |
< |
Iterator it = q.iterator(); |
448 |
< |
while (it.hasNext()) { |
449 |
< |
assertTrue(q.contains(it.next())); |
450 |
< |
++i; |
451 |
< |
} |
452 |
< |
assertEquals(0, i); |
445 |
> |
assertIteratorExhausted(set0().iterator()); |
446 |
|
} |
447 |
|
|
448 |
|
/** |
631 |
|
* add(null) throws NPE |
632 |
|
*/ |
633 |
|
public void testDescendingAddNull() { |
634 |
+ |
NavigableSet q = dset0(); |
635 |
|
try { |
642 |
– |
NavigableSet q = dset0(); |
636 |
|
q.add(null); |
637 |
|
shouldThrow(); |
638 |
|
} catch (NullPointerException success) {} |
659 |
|
* Add of non-Comparable throws CCE |
660 |
|
*/ |
661 |
|
public void testDescendingAddNonComparable() { |
662 |
+ |
NavigableSet q = dset0(); |
663 |
|
try { |
670 |
– |
NavigableSet q = dset0(); |
671 |
– |
q.add(new Object()); |
664 |
|
q.add(new Object()); |
665 |
|
q.add(new Object()); |
666 |
|
shouldThrow(); |
671 |
|
* addAll(null) throws NPE |
672 |
|
*/ |
673 |
|
public void testDescendingAddAll1() { |
674 |
+ |
NavigableSet q = dset0(); |
675 |
|
try { |
683 |
– |
NavigableSet q = dset0(); |
676 |
|
q.addAll(null); |
677 |
|
shouldThrow(); |
678 |
|
} catch (NullPointerException success) {} |
682 |
|
* addAll of a collection with null elements throws NPE |
683 |
|
*/ |
684 |
|
public void testDescendingAddAll2() { |
685 |
+ |
NavigableSet q = dset0(); |
686 |
+ |
Integer[] ints = new Integer[SIZE]; |
687 |
|
try { |
694 |
– |
NavigableSet q = dset0(); |
695 |
– |
Integer[] ints = new Integer[SIZE]; |
688 |
|
q.addAll(Arrays.asList(ints)); |
689 |
|
shouldThrow(); |
690 |
|
} catch (NullPointerException success) {} |
695 |
|
* possibly adding some elements |
696 |
|
*/ |
697 |
|
public void testDescendingAddAll3() { |
698 |
+ |
NavigableSet q = dset0(); |
699 |
+ |
Integer[] ints = new Integer[SIZE]; |
700 |
+ |
for (int i = 0; i < SIZE-1; ++i) |
701 |
+ |
ints[i] = new Integer(i+SIZE); |
702 |
|
try { |
707 |
– |
NavigableSet q = dset0(); |
708 |
– |
Integer[] ints = new Integer[SIZE]; |
709 |
– |
for (int i = 0; i < SIZE-1; ++i) |
710 |
– |
ints[i] = new Integer(i+SIZE); |
703 |
|
q.addAll(Arrays.asList(ints)); |
704 |
|
shouldThrow(); |
705 |
|
} catch (NullPointerException success) {} |
736 |
|
*/ |
737 |
|
public void testDescendingRemoveElement() { |
738 |
|
NavigableSet q = populatedSet(SIZE); |
739 |
< |
for (int i = 1; i < SIZE; i+=2) { |
739 |
> |
for (int i = 1; i < SIZE; i += 2) { |
740 |
|
assertTrue(q.remove(new Integer(i))); |
741 |
|
} |
742 |
< |
for (int i = 0; i < SIZE; i+=2) { |
742 |
> |
for (int i = 0; i < SIZE; i += 2 ) { |
743 |
|
assertTrue(q.remove(new Integer(i))); |
744 |
|
assertFalse(q.remove(new Integer(i+1))); |
745 |
|
} |
815 |
|
assertTrue(q.removeAll(p)); |
816 |
|
assertEquals(SIZE-i, q.size()); |
817 |
|
for (int j = 0; j < i; ++j) { |
818 |
< |
Integer I = (Integer)(p.pollFirst()); |
819 |
< |
assertFalse(q.contains(I)); |
818 |
> |
Integer x = (Integer)(p.pollFirst()); |
819 |
> |
assertFalse(q.contains(x)); |
820 |
|
} |
821 |
|
} |
822 |
|
} |