5 |
|
*/ |
6 |
|
|
7 |
|
import junit.framework.*; |
8 |
< |
import java.util.*; |
9 |
< |
import java.util.concurrent.*; |
10 |
< |
import java.io.*; |
8 |
> |
import java.util.Arrays; |
9 |
> |
import java.util.Comparator; |
10 |
> |
import java.util.Iterator; |
11 |
> |
import java.util.NavigableSet; |
12 |
> |
import java.util.SortedSet; |
13 |
> |
import java.util.TreeSet; |
14 |
|
|
15 |
|
public class TreeSubSetTest extends JSR166TestCase { |
16 |
|
public static void main(String[] args) { |
96 |
|
assertEquals(0, set0().size()); |
97 |
|
} |
98 |
|
|
96 |
– |
|
99 |
|
/** |
100 |
|
* isEmpty is true before add, false after |
101 |
|
*/ |
166 |
|
} catch (ClassCastException success) {} |
167 |
|
} |
168 |
|
|
167 |
– |
|
169 |
|
/** |
170 |
|
* addAll(null) throws NPE |
171 |
|
*/ |
326 |
|
} |
327 |
|
} |
328 |
|
|
328 |
– |
|
329 |
– |
|
329 |
|
/** |
330 |
|
* lower returns preceding element |
331 |
|
*/ |
467 |
|
assertFalse(it.hasNext()); |
468 |
|
} |
469 |
|
|
471 |
– |
|
470 |
|
/** |
471 |
|
* toString contains toStrings of elements |
472 |
|
*/ |
474 |
|
NavigableSet q = populatedSet(SIZE); |
475 |
|
String s = q.toString(); |
476 |
|
for (int i = 0; i < SIZE; ++i) { |
477 |
< |
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
477 |
> |
assertTrue(s.contains(String.valueOf(i))); |
478 |
|
} |
479 |
|
} |
480 |
|
|
482 |
|
* A deserialized serialized set has same elements |
483 |
|
*/ |
484 |
|
public void testSerialization() throws Exception { |
485 |
< |
NavigableSet q = populatedSet(SIZE); |
486 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
487 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
488 |
< |
out.writeObject(q); |
489 |
< |
out.close(); |
490 |
< |
|
491 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
492 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
493 |
< |
NavigableSet r = (NavigableSet)in.readObject(); |
494 |
< |
assertEquals(q.size(), r.size()); |
495 |
< |
while (!q.isEmpty()) |
496 |
< |
assertEquals(q.pollFirst(), r.pollFirst()); |
485 |
> |
NavigableSet x = populatedSet(SIZE); |
486 |
> |
NavigableSet y = serialClone(x); |
487 |
> |
|
488 |
> |
assertTrue(x != y); |
489 |
> |
assertEquals(x.size(), y.size()); |
490 |
> |
assertEquals(x, y); |
491 |
> |
assertEquals(y, x); |
492 |
> |
while (!x.isEmpty()) { |
493 |
> |
assertFalse(y.isEmpty()); |
494 |
> |
assertEquals(x.pollFirst(), y.pollFirst()); |
495 |
> |
} |
496 |
> |
assertTrue(y.isEmpty()); |
497 |
|
} |
498 |
|
|
499 |
|
/** |
660 |
|
} catch (ClassCastException success) {} |
661 |
|
} |
662 |
|
|
665 |
– |
|
663 |
|
/** |
664 |
|
* addAll(null) throws NPE |
665 |
|
*/ |
814 |
|
} |
815 |
|
} |
816 |
|
|
820 |
– |
|
821 |
– |
|
817 |
|
/** |
818 |
|
* lower returns preceding element |
819 |
|
*/ |
956 |
|
assertFalse(it.hasNext()); |
957 |
|
} |
958 |
|
|
964 |
– |
|
959 |
|
/** |
960 |
|
* toString contains toStrings of elements |
961 |
|
*/ |
963 |
|
NavigableSet q = populatedSet(SIZE); |
964 |
|
String s = q.toString(); |
965 |
|
for (int i = 0; i < SIZE; ++i) { |
966 |
< |
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
966 |
> |
assertTrue(s.contains(String.valueOf(i))); |
967 |
|
} |
968 |
|
} |
969 |
|
|
971 |
|
* A deserialized serialized set has same elements |
972 |
|
*/ |
973 |
|
public void testDescendingSerialization() throws Exception { |
974 |
< |
NavigableSet q = populatedSet(SIZE); |
975 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
976 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
977 |
< |
out.writeObject(q); |
978 |
< |
out.close(); |
979 |
< |
|
980 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
981 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
982 |
< |
NavigableSet r = (NavigableSet)in.readObject(); |
983 |
< |
assertEquals(q.size(), r.size()); |
984 |
< |
while (!q.isEmpty()) |
985 |
< |
assertEquals(q.pollFirst(), r.pollFirst()); |
974 |
> |
NavigableSet x = dset5(); |
975 |
> |
NavigableSet y = serialClone(x); |
976 |
> |
|
977 |
> |
assertTrue(x != y); |
978 |
> |
assertEquals(x.size(), y.size()); |
979 |
> |
assertEquals(x.toString(), y.toString()); |
980 |
> |
assertEquals(x, y); |
981 |
> |
assertEquals(y, x); |
982 |
> |
while (!x.isEmpty()) { |
983 |
> |
assertFalse(y.isEmpty()); |
984 |
> |
assertEquals(x.pollFirst(), y.pollFirst()); |
985 |
> |
} |
986 |
> |
assertTrue(y.isEmpty()); |
987 |
|
} |
988 |
|
|
989 |
|
/** |