11 |
|
|
12 |
|
public class ConcurrentSkipListSetTest 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(ConcurrentSkipListSetTest.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 |
|
|
111 |
|
* The comparator used in constructor is used |
112 |
|
*/ |
113 |
|
public void testConstructor7() { |
114 |
< |
try { |
115 |
< |
MyReverseComparator cmp = new MyReverseComparator(); |
116 |
< |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(cmp); |
117 |
< |
assertEquals(cmp, q.comparator()); |
118 |
< |
Integer[] ints = new Integer[SIZE]; |
119 |
< |
for (int i = 0; i < SIZE; ++i) |
120 |
< |
ints[i] = new Integer(i); |
121 |
< |
q.addAll(Arrays.asList(ints)); |
122 |
< |
for (int i = SIZE-1; i >= 0; --i) |
127 |
< |
assertEquals(ints[i], q.pollFirst()); |
128 |
< |
} |
129 |
< |
finally {} |
114 |
> |
MyReverseComparator cmp = new MyReverseComparator(); |
115 |
> |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(cmp); |
116 |
> |
assertEquals(cmp, q.comparator()); |
117 |
> |
Integer[] ints = new Integer[SIZE]; |
118 |
> |
for (int i = 0; i < SIZE; ++i) |
119 |
> |
ints[i] = new Integer(i); |
120 |
> |
q.addAll(Arrays.asList(ints)); |
121 |
> |
for (int i = SIZE-1; i >= 0; --i) |
122 |
> |
assertEquals(ints[i], q.pollFirst()); |
123 |
|
} |
124 |
|
|
125 |
|
/** |
203 |
|
shouldThrow(); |
204 |
|
} catch (NullPointerException success) {} |
205 |
|
} |
206 |
+ |
|
207 |
|
/** |
208 |
|
* addAll of a collection with null elements throws NPE |
209 |
|
*/ |
215 |
|
shouldThrow(); |
216 |
|
} catch (NullPointerException success) {} |
217 |
|
} |
218 |
+ |
|
219 |
|
/** |
220 |
|
* addAll of a collection with any null elements throws NPE after |
221 |
|
* possibly adding some elements |
235 |
|
* Set contains all elements of successful addAll |
236 |
|
*/ |
237 |
|
public void testAddAll5() { |
238 |
< |
try { |
239 |
< |
Integer[] empty = new Integer[0]; |
240 |
< |
Integer[] ints = new Integer[SIZE]; |
241 |
< |
for (int i = 0; i < SIZE; ++i) |
242 |
< |
ints[i] = new Integer(SIZE-1-i); |
243 |
< |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
244 |
< |
assertFalse(q.addAll(Arrays.asList(empty))); |
245 |
< |
assertTrue(q.addAll(Arrays.asList(ints))); |
246 |
< |
for (int i = 0; i < SIZE; ++i) |
252 |
< |
assertEquals(new Integer(i), q.pollFirst()); |
253 |
< |
} |
254 |
< |
finally {} |
238 |
> |
Integer[] empty = new Integer[0]; |
239 |
> |
Integer[] ints = new Integer[SIZE]; |
240 |
> |
for (int i = 0; i < SIZE; ++i) |
241 |
> |
ints[i] = new Integer(SIZE-1-i); |
242 |
> |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
243 |
> |
assertFalse(q.addAll(Arrays.asList(empty))); |
244 |
> |
assertTrue(q.addAll(Arrays.asList(ints))); |
245 |
> |
for (int i = 0; i < SIZE; ++i) |
246 |
> |
assertEquals(i, q.pollFirst()); |
247 |
|
} |
248 |
|
|
249 |
|
/** |
252 |
|
public void testPollFirst() { |
253 |
|
ConcurrentSkipListSet q = populatedSet(SIZE); |
254 |
|
for (int i = 0; i < SIZE; ++i) { |
255 |
< |
assertEquals(i, ((Integer)q.pollFirst()).intValue()); |
255 |
> |
assertEquals(i, q.pollFirst()); |
256 |
|
} |
257 |
|
assertNull(q.pollFirst()); |
258 |
|
} |
263 |
|
public void testPollLast() { |
264 |
|
ConcurrentSkipListSet q = populatedSet(SIZE); |
265 |
|
for (int i = SIZE-1; i >= 0; --i) { |
266 |
< |
assertEquals(i, ((Integer)q.pollLast()).intValue()); |
266 |
> |
assertEquals(i, q.pollLast()); |
267 |
|
} |
268 |
|
assertNull(q.pollFirst()); |
269 |
|
} |
377 |
|
|
378 |
|
Object e4 = q.lower(zero); |
379 |
|
assertNull(e4); |
388 |
– |
|
380 |
|
} |
381 |
|
|
382 |
|
/** |
395 |
|
|
396 |
|
Object e4 = q.higher(six); |
397 |
|
assertNull(e4); |
407 |
– |
|
398 |
|
} |
399 |
|
|
400 |
|
/** |
413 |
|
|
414 |
|
Object e4 = q.floor(zero); |
415 |
|
assertNull(e4); |
426 |
– |
|
416 |
|
} |
417 |
|
|
418 |
|
/** |
431 |
|
|
432 |
|
Object e4 = q.ceiling(six); |
433 |
|
assertNull(e4); |
445 |
– |
|
434 |
|
} |
435 |
|
|
436 |
|
/** |
487 |
|
/** |
488 |
|
* iterator.remove removes current element |
489 |
|
*/ |
490 |
< |
public void testIteratorRemove () { |
490 |
> |
public void testIteratorRemove() { |
491 |
|
final ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
492 |
|
q.add(new Integer(2)); |
493 |
|
q.add(new Integer(1)); |
658 |
|
/** |
659 |
|
* Subsets of subsets subdivide correctly |
660 |
|
*/ |
661 |
< |
public void testRecursiveSubSets() { |
661 |
> |
public void testRecursiveSubSets() throws Exception { |
662 |
|
int setSize = 1000; |
663 |
|
Class cl = ConcurrentSkipListSet.class; |
664 |
|
|
677 |
|
0, setSize - 1, true); |
678 |
|
} |
679 |
|
|
680 |
< |
static NavigableSet<Integer> newSet(Class cl) { |
681 |
< |
NavigableSet<Integer> result = null; |
694 |
< |
try { |
695 |
< |
result = (NavigableSet<Integer>) cl.newInstance(); |
696 |
< |
} catch (Exception e) { |
697 |
< |
fail(); |
698 |
< |
} |
680 |
> |
static NavigableSet<Integer> newSet(Class cl) throws Exception { |
681 |
> |
NavigableSet<Integer> result = (NavigableSet<Integer>) cl.newInstance(); |
682 |
|
assertEquals(result.size(), 0); |
683 |
|
assertFalse(result.iterator().hasNext()); |
684 |
|
return result; |
741 |
|
} else { |
742 |
|
try { |
743 |
|
set.add(element); |
744 |
< |
fail(); |
745 |
< |
} catch (IllegalArgumentException e) { |
763 |
< |
// expected |
764 |
< |
} |
744 |
> |
shouldThrow(); |
745 |
> |
} catch (IllegalArgumentException success) {} |
746 |
|
} |
747 |
|
} |
748 |
|
} |
875 |
|
// BitSet should support this! Test would run much faster |
876 |
|
while (element >= min) { |
877 |
|
if (bs.get(element)) |
878 |
< |
return(element); |
878 |
> |
return element; |
879 |
|
element--; |
880 |
|
} |
881 |
|
return -1; |
941 |
|
assertEq(rs.last(), -1); |
942 |
|
try { |
943 |
|
set.first(); |
944 |
< |
fail(); |
945 |
< |
} catch (NoSuchElementException e) { |
965 |
< |
// expected |
966 |
< |
} |
944 |
> |
shouldThrow(); |
945 |
> |
} catch (NoSuchElementException success) {} |
946 |
|
try { |
947 |
|
set.last(); |
948 |
< |
fail(); |
949 |
< |
} catch (NoSuchElementException e) { |
971 |
< |
// expected |
972 |
< |
} |
948 |
> |
shouldThrow(); |
949 |
> |
} catch (NoSuchElementException success) {} |
950 |
|
} |
951 |
|
} |
952 |
|
|