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))); |
135 |
|
NavigableSet q = set0(); |
136 |
|
q.add(null); |
137 |
|
shouldThrow(); |
138 |
< |
} catch (NullPointerException success) { } |
138 |
> |
} catch (NullPointerException success) {} |
139 |
|
} |
140 |
|
|
141 |
|
/** |
165 |
|
q.add(new Object()); |
166 |
|
q.add(new Object()); |
167 |
|
shouldThrow(); |
168 |
< |
} |
169 |
< |
catch(ClassCastException success) {} |
168 |
> |
} catch (ClassCastException success) {} |
169 |
|
} |
170 |
|
|
171 |
|
|
177 |
|
NavigableSet q = set0(); |
178 |
|
q.addAll(null); |
179 |
|
shouldThrow(); |
180 |
< |
} |
182 |
< |
catch (NullPointerException success) {} |
180 |
> |
} catch (NullPointerException success) {} |
181 |
|
} |
182 |
|
/** |
183 |
|
* addAll of a collection with null elements throws NPE |
188 |
|
Integer[] ints = new Integer[SIZE]; |
189 |
|
q.addAll(Arrays.asList(ints)); |
190 |
|
shouldThrow(); |
191 |
< |
} |
194 |
< |
catch (NullPointerException success) {} |
191 |
> |
} catch (NullPointerException success) {} |
192 |
|
} |
193 |
|
/** |
194 |
|
* addAll of a collection with any null elements throws NPE after |
202 |
|
ints[i] = new Integer(i+SIZE); |
203 |
|
q.addAll(Arrays.asList(ints)); |
204 |
|
shouldThrow(); |
205 |
< |
} |
209 |
< |
catch (NullPointerException success) {} |
205 |
> |
} catch (NullPointerException success) {} |
206 |
|
} |
207 |
|
|
208 |
|
/** |
409 |
|
NavigableSet q = populatedSet(SIZE); |
410 |
|
Object[] o = q.toArray(); |
411 |
|
Arrays.sort(o); |
412 |
< |
for(int i = 0; i < o.length; i++) |
412 |
> |
for (int i = 0; i < o.length; i++) |
413 |
|
assertEquals(o[i], q.pollFirst()); |
414 |
|
} |
415 |
|
|
421 |
|
Integer[] ints = new Integer[SIZE]; |
422 |
|
ints = (Integer[])q.toArray(ints); |
423 |
|
Arrays.sort(ints); |
424 |
< |
for(int i = 0; i < ints.length; i++) |
424 |
> |
for (int i = 0; i < ints.length; i++) |
425 |
|
assertEquals(ints[i], q.pollFirst()); |
426 |
|
} |
427 |
|
|
432 |
|
NavigableSet q = populatedSet(SIZE); |
433 |
|
int i = 0; |
434 |
|
Iterator it = q.iterator(); |
435 |
< |
while(it.hasNext()) { |
435 |
> |
while (it.hasNext()) { |
436 |
|
assertTrue(q.contains(it.next())); |
437 |
|
++i; |
438 |
|
} |
446 |
|
NavigableSet q = set0(); |
447 |
|
int i = 0; |
448 |
|
Iterator it = q.iterator(); |
449 |
< |
while(it.hasNext()) { |
449 |
> |
while (it.hasNext()) { |
450 |
|
assertTrue(q.contains(it.next())); |
451 |
|
++i; |
452 |
|
} |
487 |
|
/** |
488 |
|
* A deserialized serialized set has same elements |
489 |
|
*/ |
490 |
< |
public void testSerialization() { |
490 |
> |
public void testSerialization() throws Exception { |
491 |
|
NavigableSet q = populatedSet(SIZE); |
492 |
< |
try { |
493 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
494 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
495 |
< |
out.writeObject(q); |
496 |
< |
out.close(); |
497 |
< |
|
498 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
499 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
500 |
< |
NavigableSet r = (NavigableSet)in.readObject(); |
501 |
< |
assertEquals(q.size(), r.size()); |
502 |
< |
while (!q.isEmpty()) |
507 |
< |
assertEquals(q.pollFirst(), r.pollFirst()); |
508 |
< |
} catch(Exception e){ |
509 |
< |
e.printStackTrace(); |
510 |
< |
unexpectedException(); |
511 |
< |
} |
492 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
493 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
494 |
> |
out.writeObject(q); |
495 |
> |
out.close(); |
496 |
> |
|
497 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
498 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
499 |
> |
NavigableSet r = (NavigableSet)in.readObject(); |
500 |
> |
assertEquals(q.size(), r.size()); |
501 |
> |
while (!q.isEmpty()) |
502 |
> |
assertEquals(q.pollFirst(), r.pollFirst()); |
503 |
|
} |
504 |
|
|
505 |
|
/** |
663 |
|
q.add(new Object()); |
664 |
|
q.add(new Object()); |
665 |
|
shouldThrow(); |
666 |
< |
} |
676 |
< |
catch(ClassCastException success) {} |
666 |
> |
} catch (ClassCastException success) {} |
667 |
|
} |
668 |
|
|
669 |
|
|
675 |
|
NavigableSet q = dset0(); |
676 |
|
q.addAll(null); |
677 |
|
shouldThrow(); |
678 |
< |
} |
689 |
< |
catch (NullPointerException success) {} |
678 |
> |
} catch (NullPointerException success) {} |
679 |
|
} |
680 |
|
/** |
681 |
|
* addAll of a collection with null elements throws NPE |
686 |
|
Integer[] ints = new Integer[SIZE]; |
687 |
|
q.addAll(Arrays.asList(ints)); |
688 |
|
shouldThrow(); |
689 |
< |
} |
701 |
< |
catch (NullPointerException success) {} |
689 |
> |
} catch (NullPointerException success) {} |
690 |
|
} |
691 |
|
/** |
692 |
|
* addAll of a collection with any null elements throws NPE after |
700 |
|
ints[i] = new Integer(i+SIZE); |
701 |
|
q.addAll(Arrays.asList(ints)); |
702 |
|
shouldThrow(); |
703 |
< |
} |
716 |
< |
catch (NullPointerException success) {} |
703 |
> |
} catch (NullPointerException success) {} |
704 |
|
} |
705 |
|
|
706 |
|
/** |
707 |
|
* Set contains all elements of successful addAll |
708 |
|
*/ |
709 |
|
public void testDescendingAddAll5() { |
710 |
< |
try { |
711 |
< |
Integer[] empty = new Integer[0]; |
712 |
< |
Integer[] ints = new Integer[SIZE]; |
713 |
< |
for (int i = 0; i < SIZE; ++i) |
714 |
< |
ints[i] = new Integer(SIZE-1- i); |
715 |
< |
NavigableSet q = dset0(); |
716 |
< |
assertFalse(q.addAll(Arrays.asList(empty))); |
717 |
< |
assertTrue(q.addAll(Arrays.asList(ints))); |
718 |
< |
for (int i = 0; i < SIZE; ++i) |
732 |
< |
assertEquals(new Integer(i), q.pollFirst()); |
733 |
< |
} |
734 |
< |
finally {} |
710 |
> |
Integer[] empty = new Integer[0]; |
711 |
> |
Integer[] ints = new Integer[SIZE]; |
712 |
> |
for (int i = 0; i < SIZE; ++i) |
713 |
> |
ints[i] = new Integer(SIZE-1- i); |
714 |
> |
NavigableSet q = dset0(); |
715 |
> |
assertFalse(q.addAll(Arrays.asList(empty))); |
716 |
> |
assertTrue(q.addAll(Arrays.asList(ints))); |
717 |
> |
for (int i = 0; i < SIZE; ++i) |
718 |
> |
assertEquals(new Integer(i), q.pollFirst()); |
719 |
|
} |
720 |
|
|
721 |
|
/** |
904 |
|
NavigableSet q = populatedSet(SIZE); |
905 |
|
Object[] o = q.toArray(); |
906 |
|
Arrays.sort(o); |
907 |
< |
for(int i = 0; i < o.length; i++) |
907 |
> |
for (int i = 0; i < o.length; i++) |
908 |
|
assertEquals(o[i], q.pollFirst()); |
909 |
|
} |
910 |
|
|
916 |
|
Integer[] ints = new Integer[SIZE]; |
917 |
|
ints = (Integer[])q.toArray(ints); |
918 |
|
Arrays.sort(ints); |
919 |
< |
for(int i = 0; i < ints.length; i++) |
919 |
> |
for (int i = 0; i < ints.length; i++) |
920 |
|
assertEquals(ints[i], q.pollFirst()); |
921 |
|
} |
922 |
|
|
927 |
|
NavigableSet q = populatedSet(SIZE); |
928 |
|
int i = 0; |
929 |
|
Iterator it = q.iterator(); |
930 |
< |
while(it.hasNext()) { |
930 |
> |
while (it.hasNext()) { |
931 |
|
assertTrue(q.contains(it.next())); |
932 |
|
++i; |
933 |
|
} |
941 |
|
NavigableSet q = dset0(); |
942 |
|
int i = 0; |
943 |
|
Iterator it = q.iterator(); |
944 |
< |
while(it.hasNext()) { |
944 |
> |
while (it.hasNext()) { |
945 |
|
assertTrue(q.contains(it.next())); |
946 |
|
++i; |
947 |
|
} |
982 |
|
/** |
983 |
|
* A deserialized serialized set has same elements |
984 |
|
*/ |
985 |
< |
public void testDescendingSerialization() { |
985 |
> |
public void testDescendingSerialization() throws Exception { |
986 |
|
NavigableSet q = populatedSet(SIZE); |
987 |
< |
try { |
988 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
989 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
990 |
< |
out.writeObject(q); |
991 |
< |
out.close(); |
992 |
< |
|
993 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
994 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
995 |
< |
NavigableSet r = (NavigableSet)in.readObject(); |
996 |
< |
assertEquals(q.size(), r.size()); |
997 |
< |
while (!q.isEmpty()) |
1014 |
< |
assertEquals(q.pollFirst(), r.pollFirst()); |
1015 |
< |
} catch(Exception e){ |
1016 |
< |
e.printStackTrace(); |
1017 |
< |
unexpectedException(); |
1018 |
< |
} |
987 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
988 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
989 |
> |
out.writeObject(q); |
990 |
> |
out.close(); |
991 |
> |
|
992 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
993 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
994 |
> |
NavigableSet r = (NavigableSet)in.readObject(); |
995 |
> |
assertEquals(q.size(), r.size()); |
996 |
> |
while (!q.isEmpty()) |
997 |
> |
assertEquals(q.pollFirst(), r.pollFirst()); |
998 |
|
} |
999 |
|
|
1000 |
|
/** |