11 |
|
|
12 |
|
public class TreeSubSetTest 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(TreeSubSetTest.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 |
|
|
100 |
|
public void testEmpty() { |
101 |
|
NavigableSet q = set0(); |
102 |
|
assertTrue(q.isEmpty()); |
103 |
< |
q.add(new Integer(1)); |
103 |
> |
assertTrue(q.add(new Integer(1))); |
104 |
|
assertFalse(q.isEmpty()); |
105 |
< |
q.add(new Integer(2)); |
105 |
> |
assertTrue(q.add(new Integer(2))); |
106 |
|
q.pollFirst(); |
107 |
|
q.pollFirst(); |
108 |
|
assertTrue(q.isEmpty()); |
175 |
|
shouldThrow(); |
176 |
|
} catch (NullPointerException success) {} |
177 |
|
} |
178 |
+ |
|
179 |
|
/** |
180 |
|
* addAll of a collection with null elements throws NPE |
181 |
|
*/ |
187 |
|
shouldThrow(); |
188 |
|
} catch (NullPointerException success) {} |
189 |
|
} |
190 |
+ |
|
191 |
|
/** |
192 |
|
* addAll of a collection with any null elements throws NPE after |
193 |
|
* possibly adding some elements |
207 |
|
* Set contains all elements of successful addAll |
208 |
|
*/ |
209 |
|
public void testAddAll5() { |
210 |
< |
try { |
211 |
< |
Integer[] empty = new Integer[0]; |
212 |
< |
Integer[] ints = new Integer[SIZE]; |
213 |
< |
for (int i = 0; i < SIZE; ++i) |
214 |
< |
ints[i] = new Integer(SIZE-1- i); |
215 |
< |
NavigableSet q = set0(); |
216 |
< |
assertFalse(q.addAll(Arrays.asList(empty))); |
217 |
< |
assertTrue(q.addAll(Arrays.asList(ints))); |
218 |
< |
for (int i = 0; i < SIZE; ++i) |
221 |
< |
assertEquals(new Integer(i), q.pollFirst()); |
222 |
< |
} |
223 |
< |
finally {} |
210 |
> |
Integer[] empty = new Integer[0]; |
211 |
> |
Integer[] ints = new Integer[SIZE]; |
212 |
> |
for (int i = 0; i < SIZE; ++i) |
213 |
> |
ints[i] = new Integer(SIZE-1- i); |
214 |
> |
NavigableSet q = set0(); |
215 |
> |
assertFalse(q.addAll(Arrays.asList(empty))); |
216 |
> |
assertTrue(q.addAll(Arrays.asList(ints))); |
217 |
> |
for (int i = 0; i < SIZE; ++i) |
218 |
> |
assertEquals(new Integer(i), q.pollFirst()); |
219 |
|
} |
220 |
|
|
221 |
|
/** |
224 |
|
public void testPoll() { |
225 |
|
NavigableSet q = populatedSet(SIZE); |
226 |
|
for (int i = 0; i < SIZE; ++i) { |
227 |
< |
assertEquals(i, ((Integer)q.pollFirst()).intValue()); |
227 |
> |
assertEquals(i, q.pollFirst()); |
228 |
|
} |
229 |
|
assertNull(q.pollFirst()); |
230 |
|
} |
264 |
|
q.clear(); |
265 |
|
assertTrue(q.isEmpty()); |
266 |
|
assertEquals(0, q.size()); |
267 |
< |
q.add(new Integer(1)); |
267 |
> |
assertTrue(q.add(new Integer(1))); |
268 |
|
assertFalse(q.isEmpty()); |
269 |
|
q.clear(); |
270 |
|
assertTrue(q.isEmpty()); |
337 |
|
|
338 |
|
Object e4 = q.lower(zero); |
339 |
|
assertNull(e4); |
345 |
– |
|
340 |
|
} |
341 |
|
|
342 |
|
/** |
355 |
|
|
356 |
|
Object e4 = q.higher(six); |
357 |
|
assertNull(e4); |
364 |
– |
|
358 |
|
} |
359 |
|
|
360 |
|
/** |
373 |
|
|
374 |
|
Object e4 = q.floor(zero); |
375 |
|
assertNull(e4); |
383 |
– |
|
376 |
|
} |
377 |
|
|
378 |
|
/** |
391 |
|
|
392 |
|
Object e4 = q.ceiling(six); |
393 |
|
assertNull(e4); |
402 |
– |
|
394 |
|
} |
395 |
|
|
396 |
|
/** |
447 |
|
/** |
448 |
|
* iterator.remove removes current element |
449 |
|
*/ |
450 |
< |
public void testIteratorRemove () { |
450 |
> |
public void testIteratorRemove() { |
451 |
|
final NavigableSet q = set0(); |
452 |
|
q.add(new Integer(2)); |
453 |
|
q.add(new Integer(1)); |
458 |
|
it.remove(); |
459 |
|
|
460 |
|
it = q.iterator(); |
461 |
< |
assertEquals(it.next(), new Integer(2)); |
462 |
< |
assertEquals(it.next(), new Integer(3)); |
461 |
> |
assertEquals(it.next(), 2); |
462 |
> |
assertEquals(it.next(), 3); |
463 |
|
assertFalse(it.hasNext()); |
464 |
|
} |
465 |
|
|
668 |
|
shouldThrow(); |
669 |
|
} catch (NullPointerException success) {} |
670 |
|
} |
671 |
+ |
|
672 |
|
/** |
673 |
|
* addAll of a collection with null elements throws NPE |
674 |
|
*/ |
680 |
|
shouldThrow(); |
681 |
|
} catch (NullPointerException success) {} |
682 |
|
} |
683 |
+ |
|
684 |
|
/** |
685 |
|
* addAll of a collection with any null elements throws NPE after |
686 |
|
* possibly adding some elements |
717 |
|
public void testDescendingPoll() { |
718 |
|
NavigableSet q = populatedSet(SIZE); |
719 |
|
for (int i = 0; i < SIZE; ++i) { |
720 |
< |
assertEquals(i, ((Integer)q.pollFirst()).intValue()); |
720 |
> |
assertEquals(i, q.pollFirst()); |
721 |
|
} |
722 |
|
assertNull(q.pollFirst()); |
723 |
|
} |
757 |
|
q.clear(); |
758 |
|
assertTrue(q.isEmpty()); |
759 |
|
assertEquals(0, q.size()); |
760 |
< |
q.add(new Integer(1)); |
760 |
> |
assertTrue(q.add(new Integer(1))); |
761 |
|
assertFalse(q.isEmpty()); |
762 |
|
q.clear(); |
763 |
|
assertTrue(q.isEmpty()); |
830 |
|
|
831 |
|
Object e4 = q.lower(zero); |
832 |
|
assertNull(e4); |
840 |
– |
|
833 |
|
} |
834 |
|
|
835 |
|
/** |
848 |
|
|
849 |
|
Object e4 = q.higher(m6); |
850 |
|
assertNull(e4); |
859 |
– |
|
851 |
|
} |
852 |
|
|
853 |
|
/** |
866 |
|
|
867 |
|
Object e4 = q.floor(zero); |
868 |
|
assertNull(e4); |
878 |
– |
|
869 |
|
} |
870 |
|
|
871 |
|
/** |
884 |
|
|
885 |
|
Object e4 = q.ceiling(m6); |
886 |
|
assertNull(e4); |
897 |
– |
|
887 |
|
} |
888 |
|
|
889 |
|
/** |
940 |
|
/** |
941 |
|
* iterator.remove removes current element |
942 |
|
*/ |
943 |
< |
public void testDescendingIteratorRemove () { |
943 |
> |
public void testDescendingIteratorRemove() { |
944 |
|
final NavigableSet q = dset0(); |
945 |
|
q.add(new Integer(2)); |
946 |
|
q.add(new Integer(1)); |
951 |
|
it.remove(); |
952 |
|
|
953 |
|
it = q.iterator(); |
954 |
< |
assertEquals(it.next(), new Integer(2)); |
955 |
< |
assertEquals(it.next(), new Integer(3)); |
954 |
> |
assertEquals(it.next(), 2); |
955 |
> |
assertEquals(it.next(), 3); |
956 |
|
assertFalse(it.hasNext()); |
957 |
|
} |
958 |
|
|