11 |
|
|
12 |
|
public class ConcurrentSkipListSubSetTest extends JSR166TestCase { |
13 |
|
public static void main(String[] args) { |
14 |
< |
junit.textui.TestRunner.run (suite()); |
14 |
> |
junit.textui.TestRunner.run(suite()); |
15 |
|
} |
16 |
|
public static Test suite() { |
17 |
|
return new TestSuite(ConcurrentSkipListSubSetTest.class); |
19 |
|
|
20 |
|
static class MyReverseComparator implements Comparator { |
21 |
|
public int compare(Object x, Object y) { |
22 |
< |
int i = ((Integer)x).intValue(); |
23 |
< |
int j = ((Integer)y).intValue(); |
24 |
< |
if (i < j) return 1; |
25 |
< |
if (i > j) return -1; |
26 |
< |
return 0; |
22 |
> |
return ((Comparable)y).compareTo(x); |
23 |
|
} |
24 |
|
} |
25 |
|
|
27 |
|
* Create a set of given size containing consecutive |
28 |
|
* Integers 0 ... n. |
29 |
|
*/ |
30 |
< |
private NavigableSet populatedSet(int n) { |
31 |
< |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
30 |
> |
private NavigableSet<Integer> populatedSet(int n) { |
31 |
> |
ConcurrentSkipListSet<Integer> q = |
32 |
> |
new ConcurrentSkipListSet<Integer>(); |
33 |
|
assertTrue(q.isEmpty()); |
34 |
|
|
35 |
|
for (int i = n-1; i >= 0; i-=2) |
179 |
|
shouldThrow(); |
180 |
|
} catch (NullPointerException success) {} |
181 |
|
} |
182 |
+ |
|
183 |
|
/** |
184 |
|
* addAll of a collection with null elements throws NPE |
185 |
|
*/ |
191 |
|
shouldThrow(); |
192 |
|
} catch (NullPointerException success) {} |
193 |
|
} |
194 |
+ |
|
195 |
|
/** |
196 |
|
* addAll of a collection with any null elements throws NPE after |
197 |
|
* possibly adding some elements |
228 |
|
public void testPoll() { |
229 |
|
NavigableSet q = populatedSet(SIZE); |
230 |
|
for (int i = 0; i < SIZE; ++i) { |
231 |
< |
assertEquals(i, ((Integer)q.pollFirst()).intValue()); |
231 |
> |
assertEquals(i, q.pollFirst()); |
232 |
|
} |
233 |
|
assertNull(q.pollFirst()); |
234 |
|
} |
341 |
|
|
342 |
|
Object e4 = q.lower(zero); |
343 |
|
assertNull(e4); |
345 |
– |
|
344 |
|
} |
345 |
|
|
346 |
|
/** |
359 |
|
|
360 |
|
Object e4 = q.higher(six); |
361 |
|
assertNull(e4); |
364 |
– |
|
362 |
|
} |
363 |
|
|
364 |
|
/** |
377 |
|
|
378 |
|
Object e4 = q.floor(zero); |
379 |
|
assertNull(e4); |
383 |
– |
|
380 |
|
} |
381 |
|
|
382 |
|
/** |
395 |
|
|
396 |
|
Object e4 = q.ceiling(six); |
397 |
|
assertNull(e4); |
402 |
– |
|
398 |
|
} |
399 |
|
|
400 |
|
/** |
401 |
< |
* toArray contains all elements |
401 |
> |
* toArray contains all elements in sorted order |
402 |
|
*/ |
403 |
|
public void testToArray() { |
404 |
|
NavigableSet q = populatedSet(SIZE); |
405 |
|
Object[] o = q.toArray(); |
411 |
– |
Arrays.sort(o); |
406 |
|
for (int i = 0; i < o.length; i++) |
407 |
< |
assertEquals(o[i], q.pollFirst()); |
407 |
> |
assertSame(o[i], q.pollFirst()); |
408 |
|
} |
409 |
|
|
410 |
|
/** |
411 |
< |
* toArray(a) contains all elements |
411 |
> |
* toArray(a) contains all elements in sorted order |
412 |
|
*/ |
413 |
|
public void testToArray2() { |
414 |
< |
NavigableSet q = populatedSet(SIZE); |
414 |
> |
NavigableSet<Integer> q = populatedSet(SIZE); |
415 |
|
Integer[] ints = new Integer[SIZE]; |
416 |
< |
ints = (Integer[])q.toArray(ints); |
417 |
< |
Arrays.sort(ints); |
416 |
> |
Integer[] array = q.toArray(ints); |
417 |
> |
assertSame(ints, array); |
418 |
|
for (int i = 0; i < ints.length; i++) |
419 |
< |
assertEquals(ints[i], q.pollFirst()); |
419 |
> |
assertSame(ints[i], q.pollFirst()); |
420 |
|
} |
421 |
|
|
422 |
|
/** |
450 |
|
/** |
451 |
|
* iterator.remove removes current element |
452 |
|
*/ |
453 |
< |
public void testIteratorRemove () { |
453 |
> |
public void testIteratorRemove() { |
454 |
|
final NavigableSet q = set0(); |
455 |
|
q.add(new Integer(2)); |
456 |
|
q.add(new Integer(1)); |
682 |
|
shouldThrow(); |
683 |
|
} catch (NullPointerException success) {} |
684 |
|
} |
685 |
+ |
|
686 |
|
/** |
687 |
|
* addAll of a collection with null elements throws NPE |
688 |
|
*/ |
694 |
|
shouldThrow(); |
695 |
|
} catch (NullPointerException success) {} |
696 |
|
} |
697 |
+ |
|
698 |
|
/** |
699 |
|
* addAll of a collection with any null elements throws NPE after |
700 |
|
* possibly adding some elements |
731 |
|
public void testDescendingPoll() { |
732 |
|
NavigableSet q = populatedSet(SIZE); |
733 |
|
for (int i = 0; i < SIZE; ++i) { |
734 |
< |
assertEquals(i, ((Integer)q.pollFirst()).intValue()); |
734 |
> |
assertEquals(i, q.pollFirst()); |
735 |
|
} |
736 |
|
assertNull(q.pollFirst()); |
737 |
|
} |
844 |
|
|
845 |
|
Object e4 = q.lower(zero); |
846 |
|
assertNull(e4); |
851 |
– |
|
847 |
|
} |
848 |
|
|
849 |
|
/** |
862 |
|
|
863 |
|
Object e4 = q.higher(m6); |
864 |
|
assertNull(e4); |
870 |
– |
|
865 |
|
} |
866 |
|
|
867 |
|
/** |
880 |
|
|
881 |
|
Object e4 = q.floor(zero); |
882 |
|
assertNull(e4); |
889 |
– |
|
883 |
|
} |
884 |
|
|
885 |
|
/** |
898 |
|
|
899 |
|
Object e4 = q.ceiling(m6); |
900 |
|
assertNull(e4); |
908 |
– |
|
901 |
|
} |
902 |
|
|
903 |
|
/** |
917 |
|
public void testDescendingToArray2() { |
918 |
|
NavigableSet q = populatedSet(SIZE); |
919 |
|
Integer[] ints = new Integer[SIZE]; |
920 |
< |
ints = (Integer[])q.toArray(ints); |
920 |
> |
assertSame(ints, q.toArray(ints)); |
921 |
|
Arrays.sort(ints); |
922 |
|
for (int i = 0; i < ints.length; i++) |
923 |
|
assertEquals(ints[i], q.pollFirst()); |
954 |
|
/** |
955 |
|
* iterator.remove removes current element |
956 |
|
*/ |
957 |
< |
public void testDescendingIteratorRemove () { |
957 |
> |
public void testDescendingIteratorRemove() { |
958 |
|
final NavigableSet q = dset0(); |
959 |
|
q.add(new Integer(2)); |
960 |
|
q.add(new Integer(1)); |