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); |
18 |
|
} |
19 |
|
|
20 |
< |
static class MyReverseComparator implements Comparator { |
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(); |
35 |
|
TreeSet q = new TreeSet(); |
36 |
|
assertTrue(q.isEmpty()); |
37 |
|
|
38 |
< |
for(int i = n-1; i >= 0; i-=2) |
38 |
> |
for (int i = n-1; i >= 0; i-=2) |
39 |
|
assertTrue(q.add(new Integer(i))); |
40 |
< |
for(int i = (n & 1); i < n; i+=2) |
40 |
> |
for (int i = (n & 1); i < n; i+=2) |
41 |
|
assertTrue(q.add(new Integer(i))); |
42 |
|
assertTrue(q.add(new Integer(-n))); |
43 |
|
assertTrue(q.add(new Integer(n))); |
78 |
|
return s; |
79 |
|
} |
80 |
|
|
81 |
< |
private static NavigableSet set0() { |
81 |
> |
private static NavigableSet set0() { |
82 |
|
TreeSet set = new TreeSet(); |
83 |
|
assertTrue(set.isEmpty()); |
84 |
|
return set.tailSet(m1, false); |
85 |
|
} |
86 |
|
|
87 |
< |
private static NavigableSet dset0() { |
87 |
> |
private static NavigableSet dset0() { |
88 |
|
TreeSet set = new TreeSet(); |
89 |
|
assertTrue(set.isEmpty()); |
90 |
|
return set; |
91 |
|
} |
92 |
< |
|
92 |
> |
|
93 |
|
/** |
94 |
|
* A new set has unbounded capacity |
95 |
|
*/ |
135 |
|
NavigableSet q = set0(); |
136 |
|
q.add(null); |
137 |
|
shouldThrow(); |
138 |
< |
} catch (NullPointerException success) { } |
138 |
> |
} catch (NullPointerException success) { } |
139 |
|
} |
140 |
|
|
141 |
|
/** |
166 |
|
q.add(new Object()); |
167 |
|
shouldThrow(); |
168 |
|
} |
169 |
< |
catch(ClassCastException success) {} |
169 |
> |
catch (ClassCastException success) {} |
170 |
|
} |
171 |
|
|
172 |
|
|
252 |
|
} |
253 |
|
assertTrue(q.isEmpty()); |
254 |
|
} |
255 |
< |
|
255 |
> |
|
256 |
|
/** |
257 |
|
* contains(x) reports true when elements added but not yet removed |
258 |
|
*/ |
328 |
|
} |
329 |
|
} |
330 |
|
|
331 |
< |
|
331 |
> |
|
332 |
|
|
333 |
|
/** |
334 |
|
* lower returns preceding element |
413 |
|
NavigableSet q = populatedSet(SIZE); |
414 |
|
Object[] o = q.toArray(); |
415 |
|
Arrays.sort(o); |
416 |
< |
for(int i = 0; i < o.length; i++) |
416 |
> |
for (int i = 0; i < o.length; i++) |
417 |
|
assertEquals(o[i], q.pollFirst()); |
418 |
|
} |
419 |
|
|
425 |
|
Integer[] ints = new Integer[SIZE]; |
426 |
|
ints = (Integer[])q.toArray(ints); |
427 |
|
Arrays.sort(ints); |
428 |
< |
for(int i = 0; i < ints.length; i++) |
428 |
> |
for (int i = 0; i < ints.length; i++) |
429 |
|
assertEquals(ints[i], q.pollFirst()); |
430 |
|
} |
431 |
< |
|
431 |
> |
|
432 |
|
/** |
433 |
|
* iterator iterates through all elements |
434 |
|
*/ |
436 |
|
NavigableSet q = populatedSet(SIZE); |
437 |
|
int i = 0; |
438 |
|
Iterator it = q.iterator(); |
439 |
< |
while(it.hasNext()) { |
439 |
> |
while (it.hasNext()) { |
440 |
|
assertTrue(q.contains(it.next())); |
441 |
|
++i; |
442 |
|
} |
450 |
|
NavigableSet q = set0(); |
451 |
|
int i = 0; |
452 |
|
Iterator it = q.iterator(); |
453 |
< |
while(it.hasNext()) { |
453 |
> |
while (it.hasNext()) { |
454 |
|
assertTrue(q.contains(it.next())); |
455 |
|
++i; |
456 |
|
} |
486 |
|
for (int i = 0; i < SIZE; ++i) { |
487 |
|
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
488 |
|
} |
489 |
< |
} |
489 |
> |
} |
490 |
|
|
491 |
|
/** |
492 |
< |
* A deserialized serialized set has same elements |
492 |
> |
* A deserialized serialized set has same elements |
493 |
|
*/ |
494 |
|
public void testSerialization() { |
495 |
|
NavigableSet q = populatedSet(SIZE); |
503 |
|
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
504 |
|
NavigableSet r = (NavigableSet)in.readObject(); |
505 |
|
assertEquals(q.size(), r.size()); |
506 |
< |
while (!q.isEmpty()) |
506 |
> |
while (!q.isEmpty()) |
507 |
|
assertEquals(q.pollFirst(), r.pollFirst()); |
508 |
< |
} catch(Exception e){ |
508 |
> |
} catch (Exception e){ |
509 |
|
e.printStackTrace(); |
510 |
|
unexpectedException(); |
511 |
|
} |
673 |
|
q.add(new Object()); |
674 |
|
shouldThrow(); |
675 |
|
} |
676 |
< |
catch(ClassCastException success) {} |
676 |
> |
catch (ClassCastException success) {} |
677 |
|
} |
678 |
|
|
679 |
|
|
759 |
|
} |
760 |
|
assertTrue(q.isEmpty()); |
761 |
|
} |
762 |
< |
|
762 |
> |
|
763 |
|
/** |
764 |
|
* contains(x) reports true when elements added but not yet removed |
765 |
|
*/ |
835 |
|
} |
836 |
|
} |
837 |
|
|
838 |
< |
|
838 |
> |
|
839 |
|
|
840 |
|
/** |
841 |
|
* lower returns preceding element |
920 |
|
NavigableSet q = populatedSet(SIZE); |
921 |
|
Object[] o = q.toArray(); |
922 |
|
Arrays.sort(o); |
923 |
< |
for(int i = 0; i < o.length; i++) |
923 |
> |
for (int i = 0; i < o.length; i++) |
924 |
|
assertEquals(o[i], q.pollFirst()); |
925 |
|
} |
926 |
|
|
932 |
|
Integer[] ints = new Integer[SIZE]; |
933 |
|
ints = (Integer[])q.toArray(ints); |
934 |
|
Arrays.sort(ints); |
935 |
< |
for(int i = 0; i < ints.length; i++) |
935 |
> |
for (int i = 0; i < ints.length; i++) |
936 |
|
assertEquals(ints[i], q.pollFirst()); |
937 |
|
} |
938 |
< |
|
938 |
> |
|
939 |
|
/** |
940 |
|
* iterator iterates through all elements |
941 |
|
*/ |
943 |
|
NavigableSet q = populatedSet(SIZE); |
944 |
|
int i = 0; |
945 |
|
Iterator it = q.iterator(); |
946 |
< |
while(it.hasNext()) { |
946 |
> |
while (it.hasNext()) { |
947 |
|
assertTrue(q.contains(it.next())); |
948 |
|
++i; |
949 |
|
} |
957 |
|
NavigableSet q = dset0(); |
958 |
|
int i = 0; |
959 |
|
Iterator it = q.iterator(); |
960 |
< |
while(it.hasNext()) { |
960 |
> |
while (it.hasNext()) { |
961 |
|
assertTrue(q.contains(it.next())); |
962 |
|
++i; |
963 |
|
} |
993 |
|
for (int i = 0; i < SIZE; ++i) { |
994 |
|
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
995 |
|
} |
996 |
< |
} |
996 |
> |
} |
997 |
|
|
998 |
|
/** |
999 |
< |
* A deserialized serialized set has same elements |
999 |
> |
* A deserialized serialized set has same elements |
1000 |
|
*/ |
1001 |
|
public void testDescendingSerialization() { |
1002 |
|
NavigableSet q = populatedSet(SIZE); |
1010 |
|
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
1011 |
|
NavigableSet r = (NavigableSet)in.readObject(); |
1012 |
|
assertEquals(q.size(), r.size()); |
1013 |
< |
while (!q.isEmpty()) |
1013 |
> |
while (!q.isEmpty()) |
1014 |
|
assertEquals(q.pollFirst(), r.pollFirst()); |
1015 |
< |
} catch(Exception e){ |
1015 |
> |
} catch (Exception e){ |
1016 |
|
e.printStackTrace(); |
1017 |
|
unexpectedException(); |
1018 |
|
} |