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); |
30 |
|
|
31 |
|
/** |
32 |
|
* Returns a new set of given size containing consecutive |
33 |
< |
* Integers 0 ... n. |
33 |
> |
* Integers 0 ... n - 1. |
34 |
|
*/ |
35 |
|
private NavigableSet<Integer> populatedSet(int n) { |
36 |
|
ConcurrentSkipListSet<Integer> q = |
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) |
43 |
|
assertTrue(q.add(new Integer(i))); |
122 |
|
public void testSize() { |
123 |
|
NavigableSet q = populatedSet(SIZE); |
124 |
|
for (int i = 0; i < SIZE; ++i) { |
125 |
< |
assertEquals(SIZE-i, q.size()); |
125 |
> |
assertEquals(SIZE - i, q.size()); |
126 |
|
q.pollFirst(); |
127 |
|
} |
128 |
|
for (int i = 0; i < SIZE; ++i) { |
167 |
|
try { |
168 |
|
q.add(new Object()); |
169 |
|
q.add(new Object()); |
170 |
– |
q.add(new Object()); |
170 |
|
shouldThrow(); |
171 |
|
} catch (ClassCastException success) {} |
172 |
|
} |
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); |
204 |
> |
for (int i = 0; i < SIZE - 1; ++i) |
205 |
> |
ints[i] = new Integer(i + SIZE); |
206 |
|
try { |
207 |
|
q.addAll(Arrays.asList(ints)); |
208 |
|
shouldThrow(); |
216 |
|
Integer[] empty = new Integer[0]; |
217 |
|
Integer[] ints = new Integer[SIZE]; |
218 |
|
for (int i = 0; i < SIZE; ++i) |
219 |
< |
ints[i] = new Integer(SIZE-1- i); |
219 |
> |
ints[i] = new Integer(SIZE - 1 - i); |
220 |
|
NavigableSet q = set0(); |
221 |
|
assertFalse(q.addAll(Arrays.asList(empty))); |
222 |
|
assertTrue(q.addAll(Arrays.asList(ints))); |
244 |
|
assertTrue(q.contains(i)); |
245 |
|
assertTrue(q.remove(i)); |
246 |
|
assertFalse(q.contains(i)); |
247 |
< |
assertTrue(q.contains(i-1)); |
247 |
> |
assertTrue(q.contains(i - 1)); |
248 |
|
} |
249 |
|
for (int i = 0; i < SIZE; i += 2) { |
250 |
|
assertTrue(q.contains(i)); |
251 |
|
assertTrue(q.remove(i)); |
252 |
|
assertFalse(q.contains(i)); |
253 |
< |
assertFalse(q.remove(i+1)); |
254 |
< |
assertFalse(q.contains(i+1)); |
253 |
> |
assertFalse(q.remove(i + 1)); |
254 |
> |
assertFalse(q.contains(i + 1)); |
255 |
|
} |
256 |
|
assertTrue(q.isEmpty()); |
257 |
|
} |
310 |
|
assertTrue(changed); |
311 |
|
|
312 |
|
assertTrue(q.containsAll(p)); |
313 |
< |
assertEquals(SIZE-i, q.size()); |
313 |
> |
assertEquals(SIZE - i, q.size()); |
314 |
|
p.pollFirst(); |
315 |
|
} |
316 |
|
} |
323 |
|
NavigableSet q = populatedSet(SIZE); |
324 |
|
NavigableSet p = populatedSet(i); |
325 |
|
assertTrue(q.removeAll(p)); |
326 |
< |
assertEquals(SIZE-i, q.size()); |
326 |
> |
assertEquals(SIZE - i, q.size()); |
327 |
|
for (int j = 0; j < i; ++j) { |
328 |
|
Integer x = (Integer)(p.pollFirst()); |
329 |
|
assertFalse(q.contains(x)); |
618 |
|
public void testDescendingSize() { |
619 |
|
NavigableSet q = populatedSet(SIZE); |
620 |
|
for (int i = 0; i < SIZE; ++i) { |
621 |
< |
assertEquals(SIZE-i, q.size()); |
621 |
> |
assertEquals(SIZE - i, q.size()); |
622 |
|
q.pollFirst(); |
623 |
|
} |
624 |
|
for (int i = 0; i < SIZE; ++i) { |
663 |
|
try { |
664 |
|
q.add(new Object()); |
665 |
|
q.add(new Object()); |
667 |
– |
q.add(new Object()); |
666 |
|
shouldThrow(); |
667 |
|
} catch (ClassCastException success) {} |
668 |
|
} |
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); |
700 |
> |
for (int i = 0; i < SIZE - 1; ++i) |
701 |
> |
ints[i] = new Integer(i + SIZE); |
702 |
|
try { |
703 |
|
q.addAll(Arrays.asList(ints)); |
704 |
|
shouldThrow(); |
712 |
|
Integer[] empty = new Integer[0]; |
713 |
|
Integer[] ints = new Integer[SIZE]; |
714 |
|
for (int i = 0; i < SIZE; ++i) |
715 |
< |
ints[i] = new Integer(SIZE-1- i); |
715 |
> |
ints[i] = new Integer(SIZE - 1 - i); |
716 |
|
NavigableSet q = dset0(); |
717 |
|
assertFalse(q.addAll(Arrays.asList(empty))); |
718 |
|
assertTrue(q.addAll(Arrays.asList(ints))); |
741 |
|
} |
742 |
|
for (int i = 0; i < SIZE; i += 2 ) { |
743 |
|
assertTrue(q.remove(new Integer(i))); |
744 |
< |
assertFalse(q.remove(new Integer(i+1))); |
744 |
> |
assertFalse(q.remove(new Integer(i + 1))); |
745 |
|
} |
746 |
|
assertTrue(q.isEmpty()); |
747 |
|
} |
800 |
|
assertTrue(changed); |
801 |
|
|
802 |
|
assertTrue(q.containsAll(p)); |
803 |
< |
assertEquals(SIZE-i, q.size()); |
803 |
> |
assertEquals(SIZE - i, q.size()); |
804 |
|
p.pollFirst(); |
805 |
|
} |
806 |
|
} |
813 |
|
NavigableSet q = populatedSet(SIZE); |
814 |
|
NavigableSet p = populatedSet(i); |
815 |
|
assertTrue(q.removeAll(p)); |
816 |
< |
assertEquals(SIZE-i, q.size()); |
816 |
> |
assertEquals(SIZE - i, q.size()); |
817 |
|
for (int j = 0; j < i; ++j) { |
818 |
|
Integer x = (Integer)(p.pollFirst()); |
819 |
|
assertFalse(q.contains(x)); |