1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
< |
import junit.framework.*; |
8 |
< |
import java.util.*; |
9 |
< |
import java.util.concurrent.*; |
10 |
< |
import java.io.*; |
7 |
> |
import java.util.Arrays; |
8 |
> |
import java.util.Comparator; |
9 |
> |
import java.util.Iterator; |
10 |
> |
import java.util.NavigableSet; |
11 |
> |
import java.util.SortedSet; |
12 |
> |
import java.util.concurrent.ConcurrentSkipListSet; |
13 |
> |
|
14 |
> |
import junit.framework.Test; |
15 |
> |
import junit.framework.TestSuite; |
16 |
|
|
17 |
|
public class ConcurrentSkipListSubSetTest extends JSR166TestCase { |
18 |
|
public static void main(String[] args) { |
19 |
< |
junit.textui.TestRunner.run (suite()); |
19 |
> |
junit.textui.TestRunner.run(suite()); |
20 |
|
} |
21 |
|
public static Test suite() { |
22 |
< |
return new TestSuite(ConcurrentSkipListSubSetTest.class); |
22 |
> |
return new TestSuite(ConcurrentSkipListSubSetTest.class); |
23 |
|
} |
24 |
|
|
25 |
|
static class MyReverseComparator implements Comparator { |
26 |
|
public int compare(Object x, Object y) { |
27 |
< |
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; |
27 |
> |
return ((Comparable)y).compareTo(x); |
28 |
|
} |
29 |
|
} |
30 |
|
|
31 |
|
/** |
32 |
< |
* Create a set of given size containing consecutive |
32 |
> |
* Returns a new set of given size containing consecutive |
33 |
|
* Integers 0 ... n. |
34 |
|
*/ |
35 |
< |
private NavigableSet populatedSet(int n) { |
36 |
< |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
35 |
> |
private NavigableSet<Integer> populatedSet(int n) { |
36 |
> |
ConcurrentSkipListSet<Integer> q = |
37 |
> |
new ConcurrentSkipListSet<Integer>(); |
38 |
|
assertTrue(q.isEmpty()); |
39 |
|
|
40 |
< |
for (int i = n-1; i >= 0; i-=2) |
41 |
< |
assertTrue(q.add(new Integer(i))); |
42 |
< |
for (int i = (n & 1); i < n; i+=2) |
43 |
< |
assertTrue(q.add(new Integer(i))); |
40 |
> |
for (int i = n-1; i >= 0; i -= 2) |
41 |
> |
assertTrue(q.add(new Integer(i))); |
42 |
> |
for (int i = (n & 1); i < n; i += 2) |
43 |
> |
assertTrue(q.add(new Integer(i))); |
44 |
|
assertTrue(q.add(new Integer(-n))); |
45 |
|
assertTrue(q.add(new Integer(n))); |
46 |
|
NavigableSet s = q.subSet(new Integer(0), true, new Integer(n), false); |
47 |
|
assertFalse(s.isEmpty()); |
48 |
< |
assertEquals(n, s.size()); |
48 |
> |
assertEquals(n, s.size()); |
49 |
|
return s; |
50 |
|
} |
51 |
|
|
52 |
|
/** |
53 |
< |
* Create set of first 5 ints |
53 |
> |
* Returns a new set of first 5 ints. |
54 |
|
*/ |
55 |
|
private NavigableSet set5() { |
56 |
|
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
63 |
|
q.add(zero); |
64 |
|
q.add(seven); |
65 |
|
NavigableSet s = q.subSet(one, true, seven, false); |
66 |
< |
assertEquals(5, s.size()); |
66 |
> |
assertEquals(5, s.size()); |
67 |
|
return s; |
68 |
|
} |
69 |
|
|
70 |
|
/** |
71 |
< |
* Create set of first 5 negative ints |
71 |
> |
* Returns a new set of first 5 negative ints. |
72 |
|
*/ |
73 |
|
private NavigableSet dset5() { |
74 |
|
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
79 |
|
q.add(m4); |
80 |
|
q.add(m5); |
81 |
|
NavigableSet s = q.descendingSet(); |
82 |
< |
assertEquals(5, s.size()); |
82 |
> |
assertEquals(5, s.size()); |
83 |
|
return s; |
84 |
|
} |
85 |
|
|
86 |
|
private static NavigableSet set0() { |
87 |
< |
ConcurrentSkipListSet set = new ConcurrentSkipListSet(); |
87 |
> |
ConcurrentSkipListSet set = new ConcurrentSkipListSet(); |
88 |
|
assertTrue(set.isEmpty()); |
89 |
|
return set.tailSet(m1, true); |
90 |
|
} |
91 |
|
|
92 |
|
private static NavigableSet dset0() { |
93 |
< |
ConcurrentSkipListSet set = new ConcurrentSkipListSet(); |
93 |
> |
ConcurrentSkipListSet set = new ConcurrentSkipListSet(); |
94 |
|
assertTrue(set.isEmpty()); |
95 |
|
return set; |
96 |
|
} |
102 |
|
assertEquals(0, set0().size()); |
103 |
|
} |
104 |
|
|
103 |
– |
|
105 |
|
/** |
106 |
|
* isEmpty is true before add, false after |
107 |
|
*/ |
135 |
|
* add(null) throws NPE |
136 |
|
*/ |
137 |
|
public void testAddNull() { |
138 |
< |
try { |
138 |
> |
try { |
139 |
|
NavigableSet q = set0(); |
140 |
|
q.add(null); |
141 |
|
shouldThrow(); |
142 |
< |
} catch (NullPointerException success) { } |
142 |
> |
} catch (NullPointerException success) {} |
143 |
|
} |
144 |
|
|
145 |
|
/** |
169 |
|
q.add(new Object()); |
170 |
|
q.add(new Object()); |
171 |
|
shouldThrow(); |
172 |
< |
} |
172 |
< |
catch (ClassCastException success) {} |
172 |
> |
} catch (ClassCastException success) {} |
173 |
|
} |
174 |
|
|
175 |
– |
|
175 |
|
/** |
176 |
|
* addAll(null) throws NPE |
177 |
|
*/ |
180 |
|
NavigableSet q = set0(); |
181 |
|
q.addAll(null); |
182 |
|
shouldThrow(); |
183 |
< |
} |
185 |
< |
catch (NullPointerException success) {} |
183 |
> |
} catch (NullPointerException success) {} |
184 |
|
} |
185 |
+ |
|
186 |
|
/** |
187 |
|
* addAll of a collection with null elements throws NPE |
188 |
|
*/ |
192 |
|
Integer[] ints = new Integer[SIZE]; |
193 |
|
q.addAll(Arrays.asList(ints)); |
194 |
|
shouldThrow(); |
195 |
< |
} |
197 |
< |
catch (NullPointerException success) {} |
195 |
> |
} catch (NullPointerException success) {} |
196 |
|
} |
197 |
+ |
|
198 |
|
/** |
199 |
|
* addAll of a collection with any null elements throws NPE after |
200 |
|
* possibly adding some elements |
207 |
|
ints[i] = new Integer(i+SIZE); |
208 |
|
q.addAll(Arrays.asList(ints)); |
209 |
|
shouldThrow(); |
210 |
< |
} |
212 |
< |
catch (NullPointerException success) {} |
210 |
> |
} catch (NullPointerException success) {} |
211 |
|
} |
212 |
|
|
213 |
|
/** |
214 |
|
* Set contains all elements of successful addAll |
215 |
|
*/ |
216 |
|
public void testAddAll5() { |
217 |
< |
try { |
218 |
< |
Integer[] empty = new Integer[0]; |
219 |
< |
Integer[] ints = new Integer[SIZE]; |
220 |
< |
for (int i = 0; i < SIZE; ++i) |
221 |
< |
ints[i] = new Integer(SIZE-1- i); |
222 |
< |
NavigableSet q = set0(); |
223 |
< |
assertFalse(q.addAll(Arrays.asList(empty))); |
224 |
< |
assertTrue(q.addAll(Arrays.asList(ints))); |
225 |
< |
for (int i = 0; i < SIZE; ++i) |
228 |
< |
assertEquals(new Integer(i), q.pollFirst()); |
229 |
< |
} |
230 |
< |
finally {} |
217 |
> |
Integer[] empty = new Integer[0]; |
218 |
> |
Integer[] ints = new Integer[SIZE]; |
219 |
> |
for (int i = 0; i < SIZE; ++i) |
220 |
> |
ints[i] = new Integer(SIZE-1- i); |
221 |
> |
NavigableSet q = set0(); |
222 |
> |
assertFalse(q.addAll(Arrays.asList(empty))); |
223 |
> |
assertTrue(q.addAll(Arrays.asList(ints))); |
224 |
> |
for (int i = 0; i < SIZE; ++i) |
225 |
> |
assertEquals(new Integer(i), q.pollFirst()); |
226 |
|
} |
227 |
|
|
228 |
|
/** |
231 |
|
public void testPoll() { |
232 |
|
NavigableSet q = populatedSet(SIZE); |
233 |
|
for (int i = 0; i < SIZE; ++i) { |
234 |
< |
assertEquals(i, ((Integer)q.pollFirst()).intValue()); |
234 |
> |
assertEquals(i, q.pollFirst()); |
235 |
|
} |
236 |
< |
assertNull(q.pollFirst()); |
236 |
> |
assertNull(q.pollFirst()); |
237 |
|
} |
238 |
|
|
239 |
|
/** |
241 |
|
*/ |
242 |
|
public void testRemoveElement() { |
243 |
|
NavigableSet q = populatedSet(SIZE); |
244 |
< |
for (int i = 1; i < SIZE; i+=2) { |
245 |
< |
assertTrue(q.remove(new Integer(i))); |
246 |
< |
} |
247 |
< |
for (int i = 0; i < SIZE; i+=2) { |
248 |
< |
assertTrue(q.remove(new Integer(i))); |
249 |
< |
assertFalse(q.remove(new Integer(i+1))); |
244 |
> |
for (int i = 1; i < SIZE; i += 2) { |
245 |
> |
assertTrue(q.contains(i)); |
246 |
> |
assertTrue(q.remove(i)); |
247 |
> |
assertFalse(q.contains(i)); |
248 |
> |
assertTrue(q.contains(i-1)); |
249 |
> |
} |
250 |
> |
for (int i = 0; i < SIZE; i += 2) { |
251 |
> |
assertTrue(q.contains(i)); |
252 |
> |
assertTrue(q.remove(i)); |
253 |
> |
assertFalse(q.contains(i)); |
254 |
> |
assertFalse(q.remove(i+1)); |
255 |
> |
assertFalse(q.contains(i+1)); |
256 |
|
} |
257 |
|
assertTrue(q.isEmpty()); |
258 |
|
} |
326 |
|
assertTrue(q.removeAll(p)); |
327 |
|
assertEquals(SIZE-i, q.size()); |
328 |
|
for (int j = 0; j < i; ++j) { |
329 |
< |
Integer I = (Integer)(p.pollFirst()); |
330 |
< |
assertFalse(q.contains(I)); |
329 |
> |
Integer x = (Integer)(p.pollFirst()); |
330 |
> |
assertFalse(q.contains(x)); |
331 |
|
} |
332 |
|
} |
333 |
|
} |
334 |
|
|
334 |
– |
|
335 |
– |
|
335 |
|
/** |
336 |
|
* lower returns preceding element |
337 |
|
*/ |
348 |
|
|
349 |
|
Object e4 = q.lower(zero); |
350 |
|
assertNull(e4); |
352 |
– |
|
351 |
|
} |
352 |
|
|
353 |
|
/** |
366 |
|
|
367 |
|
Object e4 = q.higher(six); |
368 |
|
assertNull(e4); |
371 |
– |
|
369 |
|
} |
370 |
|
|
371 |
|
/** |
384 |
|
|
385 |
|
Object e4 = q.floor(zero); |
386 |
|
assertNull(e4); |
390 |
– |
|
387 |
|
} |
388 |
|
|
389 |
|
/** |
402 |
|
|
403 |
|
Object e4 = q.ceiling(six); |
404 |
|
assertNull(e4); |
409 |
– |
|
405 |
|
} |
406 |
|
|
407 |
|
/** |
408 |
< |
* toArray contains all elements |
408 |
> |
* toArray contains all elements in sorted order |
409 |
|
*/ |
410 |
|
public void testToArray() { |
411 |
|
NavigableSet q = populatedSet(SIZE); |
412 |
< |
Object[] o = q.toArray(); |
413 |
< |
Arrays.sort(o); |
414 |
< |
for (int i = 0; i < o.length; i++) |
420 |
< |
assertEquals(o[i], q.pollFirst()); |
412 |
> |
Object[] o = q.toArray(); |
413 |
> |
for (int i = 0; i < o.length; i++) |
414 |
> |
assertSame(o[i], q.pollFirst()); |
415 |
|
} |
416 |
|
|
417 |
|
/** |
418 |
< |
* toArray(a) contains all elements |
418 |
> |
* toArray(a) contains all elements in sorted order |
419 |
|
*/ |
420 |
|
public void testToArray2() { |
421 |
< |
NavigableSet q = populatedSet(SIZE); |
422 |
< |
Integer[] ints = new Integer[SIZE]; |
423 |
< |
ints = (Integer[])q.toArray(ints); |
424 |
< |
Arrays.sort(ints); |
421 |
> |
NavigableSet<Integer> q = populatedSet(SIZE); |
422 |
> |
Integer[] ints = new Integer[SIZE]; |
423 |
> |
Integer[] array = q.toArray(ints); |
424 |
> |
assertSame(ints, array); |
425 |
|
for (int i = 0; i < ints.length; i++) |
426 |
< |
assertEquals(ints[i], q.pollFirst()); |
426 |
> |
assertSame(ints[i], q.pollFirst()); |
427 |
|
} |
428 |
|
|
429 |
|
/** |
432 |
|
public void testIterator() { |
433 |
|
NavigableSet q = populatedSet(SIZE); |
434 |
|
int i = 0; |
435 |
< |
Iterator it = q.iterator(); |
435 |
> |
Iterator it = q.iterator(); |
436 |
|
while (it.hasNext()) { |
437 |
|
assertTrue(q.contains(it.next())); |
438 |
|
++i; |
446 |
|
public void testEmptyIterator() { |
447 |
|
NavigableSet q = set0(); |
448 |
|
int i = 0; |
449 |
< |
Iterator it = q.iterator(); |
449 |
> |
Iterator it = q.iterator(); |
450 |
|
while (it.hasNext()) { |
451 |
|
assertTrue(q.contains(it.next())); |
452 |
|
++i; |
453 |
|
} |
454 |
< |
assertEquals(i, 0); |
454 |
> |
assertEquals(0, i); |
455 |
|
} |
456 |
|
|
457 |
|
/** |
458 |
|
* iterator.remove removes current element |
459 |
|
*/ |
460 |
< |
public void testIteratorRemove () { |
460 |
> |
public void testIteratorRemove() { |
461 |
|
final NavigableSet q = set0(); |
462 |
|
q.add(new Integer(2)); |
463 |
|
q.add(new Integer(1)); |
473 |
|
assertFalse(it.hasNext()); |
474 |
|
} |
475 |
|
|
482 |
– |
|
476 |
|
/** |
477 |
|
* toString contains toStrings of elements |
478 |
|
*/ |
480 |
|
NavigableSet q = populatedSet(SIZE); |
481 |
|
String s = q.toString(); |
482 |
|
for (int i = 0; i < SIZE; ++i) { |
483 |
< |
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
483 |
> |
assertTrue(s.contains(String.valueOf(i))); |
484 |
|
} |
485 |
|
} |
486 |
|
|
487 |
|
/** |
488 |
|
* A deserialized serialized set has same elements |
489 |
|
*/ |
490 |
< |
public void testSerialization() { |
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(); |
508 |
< |
assertEquals(q.size(), r.size()); |
509 |
< |
while (!q.isEmpty()) |
510 |
< |
assertEquals(q.pollFirst(), r.pollFirst()); |
511 |
< |
} catch (Exception e) { |
512 |
< |
e.printStackTrace(); |
513 |
< |
unexpectedException(); |
490 |
> |
public void testSerialization() throws Exception { |
491 |
> |
NavigableSet x = populatedSet(SIZE); |
492 |
> |
NavigableSet y = serialClone(x); |
493 |
> |
|
494 |
> |
assertNotSame(y, x); |
495 |
> |
assertEquals(x.size(), y.size()); |
496 |
> |
assertEquals(x, y); |
497 |
> |
assertEquals(y, x); |
498 |
> |
while (!x.isEmpty()) { |
499 |
> |
assertFalse(y.isEmpty()); |
500 |
> |
assertEquals(x.pollFirst(), y.pollFirst()); |
501 |
|
} |
502 |
+ |
assertTrue(y.isEmpty()); |
503 |
|
} |
504 |
|
|
505 |
|
/** |
640 |
|
* add(null) throws NPE |
641 |
|
*/ |
642 |
|
public void testDescendingAddNull() { |
643 |
< |
try { |
643 |
> |
try { |
644 |
|
NavigableSet q = dset0(); |
645 |
|
q.add(null); |
646 |
|
shouldThrow(); |
647 |
< |
} catch (NullPointerException success) { } |
647 |
> |
} catch (NullPointerException success) {} |
648 |
|
} |
649 |
|
|
650 |
|
/** |
674 |
|
q.add(new Object()); |
675 |
|
q.add(new Object()); |
676 |
|
shouldThrow(); |
677 |
< |
} |
690 |
< |
catch (ClassCastException success) {} |
677 |
> |
} catch (ClassCastException success) {} |
678 |
|
} |
679 |
|
|
693 |
– |
|
680 |
|
/** |
681 |
|
* addAll(null) throws NPE |
682 |
|
*/ |
685 |
|
NavigableSet q = dset0(); |
686 |
|
q.addAll(null); |
687 |
|
shouldThrow(); |
688 |
< |
} |
703 |
< |
catch (NullPointerException success) {} |
688 |
> |
} catch (NullPointerException success) {} |
689 |
|
} |
690 |
+ |
|
691 |
|
/** |
692 |
|
* addAll of a collection with null elements throws NPE |
693 |
|
*/ |
697 |
|
Integer[] ints = new Integer[SIZE]; |
698 |
|
q.addAll(Arrays.asList(ints)); |
699 |
|
shouldThrow(); |
700 |
< |
} |
715 |
< |
catch (NullPointerException success) {} |
700 |
> |
} catch (NullPointerException success) {} |
701 |
|
} |
702 |
+ |
|
703 |
|
/** |
704 |
|
* addAll of a collection with any null elements throws NPE after |
705 |
|
* possibly adding some elements |
712 |
|
ints[i] = new Integer(i+SIZE); |
713 |
|
q.addAll(Arrays.asList(ints)); |
714 |
|
shouldThrow(); |
715 |
< |
} |
730 |
< |
catch (NullPointerException success) {} |
715 |
> |
} catch (NullPointerException success) {} |
716 |
|
} |
717 |
|
|
718 |
|
/** |
719 |
|
* Set contains all elements of successful addAll |
720 |
|
*/ |
721 |
|
public void testDescendingAddAll5() { |
722 |
< |
try { |
723 |
< |
Integer[] empty = new Integer[0]; |
724 |
< |
Integer[] ints = new Integer[SIZE]; |
725 |
< |
for (int i = 0; i < SIZE; ++i) |
726 |
< |
ints[i] = new Integer(SIZE-1- i); |
727 |
< |
NavigableSet q = dset0(); |
728 |
< |
assertFalse(q.addAll(Arrays.asList(empty))); |
729 |
< |
assertTrue(q.addAll(Arrays.asList(ints))); |
730 |
< |
for (int i = 0; i < SIZE; ++i) |
746 |
< |
assertEquals(new Integer(i), q.pollFirst()); |
747 |
< |
} |
748 |
< |
finally {} |
722 |
> |
Integer[] empty = new Integer[0]; |
723 |
> |
Integer[] ints = new Integer[SIZE]; |
724 |
> |
for (int i = 0; i < SIZE; ++i) |
725 |
> |
ints[i] = new Integer(SIZE-1- i); |
726 |
> |
NavigableSet q = dset0(); |
727 |
> |
assertFalse(q.addAll(Arrays.asList(empty))); |
728 |
> |
assertTrue(q.addAll(Arrays.asList(ints))); |
729 |
> |
for (int i = 0; i < SIZE; ++i) |
730 |
> |
assertEquals(new Integer(i), q.pollFirst()); |
731 |
|
} |
732 |
|
|
733 |
|
/** |
736 |
|
public void testDescendingPoll() { |
737 |
|
NavigableSet q = populatedSet(SIZE); |
738 |
|
for (int i = 0; i < SIZE; ++i) { |
739 |
< |
assertEquals(i, ((Integer)q.pollFirst()).intValue()); |
739 |
> |
assertEquals(i, q.pollFirst()); |
740 |
|
} |
741 |
< |
assertNull(q.pollFirst()); |
741 |
> |
assertNull(q.pollFirst()); |
742 |
|
} |
743 |
|
|
744 |
|
/** |
746 |
|
*/ |
747 |
|
public void testDescendingRemoveElement() { |
748 |
|
NavigableSet q = populatedSet(SIZE); |
749 |
< |
for (int i = 1; i < SIZE; i+=2) { |
749 |
> |
for (int i = 1; i < SIZE; i += 2) { |
750 |
|
assertTrue(q.remove(new Integer(i))); |
751 |
|
} |
752 |
< |
for (int i = 0; i < SIZE; i+=2) { |
752 |
> |
for (int i = 0; i < SIZE; i += 2 ) { |
753 |
|
assertTrue(q.remove(new Integer(i))); |
754 |
|
assertFalse(q.remove(new Integer(i+1))); |
755 |
|
} |
825 |
|
assertTrue(q.removeAll(p)); |
826 |
|
assertEquals(SIZE-i, q.size()); |
827 |
|
for (int j = 0; j < i; ++j) { |
828 |
< |
Integer I = (Integer)(p.pollFirst()); |
829 |
< |
assertFalse(q.contains(I)); |
828 |
> |
Integer x = (Integer)(p.pollFirst()); |
829 |
> |
assertFalse(q.contains(x)); |
830 |
|
} |
831 |
|
} |
832 |
|
} |
833 |
|
|
852 |
– |
|
853 |
– |
|
834 |
|
/** |
835 |
|
* lower returns preceding element |
836 |
|
*/ |
847 |
|
|
848 |
|
Object e4 = q.lower(zero); |
849 |
|
assertNull(e4); |
870 |
– |
|
850 |
|
} |
851 |
|
|
852 |
|
/** |
865 |
|
|
866 |
|
Object e4 = q.higher(m6); |
867 |
|
assertNull(e4); |
889 |
– |
|
868 |
|
} |
869 |
|
|
870 |
|
/** |
883 |
|
|
884 |
|
Object e4 = q.floor(zero); |
885 |
|
assertNull(e4); |
908 |
– |
|
886 |
|
} |
887 |
|
|
888 |
|
/** |
901 |
|
|
902 |
|
Object e4 = q.ceiling(m6); |
903 |
|
assertNull(e4); |
927 |
– |
|
904 |
|
} |
905 |
|
|
906 |
|
/** |
908 |
|
*/ |
909 |
|
public void testDescendingToArray() { |
910 |
|
NavigableSet q = populatedSet(SIZE); |
911 |
< |
Object[] o = q.toArray(); |
911 |
> |
Object[] o = q.toArray(); |
912 |
|
Arrays.sort(o); |
913 |
< |
for (int i = 0; i < o.length; i++) |
914 |
< |
assertEquals(o[i], q.pollFirst()); |
913 |
> |
for (int i = 0; i < o.length; i++) |
914 |
> |
assertEquals(o[i], q.pollFirst()); |
915 |
|
} |
916 |
|
|
917 |
|
/** |
919 |
|
*/ |
920 |
|
public void testDescendingToArray2() { |
921 |
|
NavigableSet q = populatedSet(SIZE); |
922 |
< |
Integer[] ints = new Integer[SIZE]; |
923 |
< |
ints = (Integer[])q.toArray(ints); |
922 |
> |
Integer[] ints = new Integer[SIZE]; |
923 |
> |
assertSame(ints, q.toArray(ints)); |
924 |
|
Arrays.sort(ints); |
925 |
|
for (int i = 0; i < ints.length; i++) |
926 |
|
assertEquals(ints[i], q.pollFirst()); |
932 |
|
public void testDescendingIterator() { |
933 |
|
NavigableSet q = populatedSet(SIZE); |
934 |
|
int i = 0; |
935 |
< |
Iterator it = q.iterator(); |
935 |
> |
Iterator it = q.iterator(); |
936 |
|
while (it.hasNext()) { |
937 |
|
assertTrue(q.contains(it.next())); |
938 |
|
++i; |
946 |
|
public void testDescendingEmptyIterator() { |
947 |
|
NavigableSet q = dset0(); |
948 |
|
int i = 0; |
949 |
< |
Iterator it = q.iterator(); |
949 |
> |
Iterator it = q.iterator(); |
950 |
|
while (it.hasNext()) { |
951 |
|
assertTrue(q.contains(it.next())); |
952 |
|
++i; |
953 |
|
} |
954 |
< |
assertEquals(i, 0); |
954 |
> |
assertEquals(0, i); |
955 |
|
} |
956 |
|
|
957 |
|
/** |
958 |
|
* iterator.remove removes current element |
959 |
|
*/ |
960 |
< |
public void testDescendingIteratorRemove () { |
960 |
> |
public void testDescendingIteratorRemove() { |
961 |
|
final NavigableSet q = dset0(); |
962 |
|
q.add(new Integer(2)); |
963 |
|
q.add(new Integer(1)); |
973 |
|
assertFalse(it.hasNext()); |
974 |
|
} |
975 |
|
|
1000 |
– |
|
976 |
|
/** |
977 |
|
* toString contains toStrings of elements |
978 |
|
*/ |
980 |
|
NavigableSet q = populatedSet(SIZE); |
981 |
|
String s = q.toString(); |
982 |
|
for (int i = 0; i < SIZE; ++i) { |
983 |
< |
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
983 |
> |
assertTrue(s.contains(String.valueOf(i))); |
984 |
|
} |
985 |
|
} |
986 |
|
|
987 |
|
/** |
988 |
|
* A deserialized serialized set has same elements |
989 |
|
*/ |
990 |
< |
public void testDescendingSerialization() { |
991 |
< |
NavigableSet q = populatedSet(SIZE); |
992 |
< |
try { |
993 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
994 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
995 |
< |
out.writeObject(q); |
996 |
< |
out.close(); |
997 |
< |
|
998 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
999 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
1000 |
< |
NavigableSet r = (NavigableSet)in.readObject(); |
1026 |
< |
assertEquals(q.size(), r.size()); |
1027 |
< |
while (!q.isEmpty()) |
1028 |
< |
assertEquals(q.pollFirst(), r.pollFirst()); |
1029 |
< |
} catch (Exception e) { |
1030 |
< |
e.printStackTrace(); |
1031 |
< |
unexpectedException(); |
990 |
> |
public void testDescendingSerialization() throws Exception { |
991 |
> |
NavigableSet x = dset5(); |
992 |
> |
NavigableSet y = serialClone(x); |
993 |
> |
|
994 |
> |
assertNotSame(y, x); |
995 |
> |
assertEquals(x.size(), y.size()); |
996 |
> |
assertEquals(x, y); |
997 |
> |
assertEquals(y, x); |
998 |
> |
while (!x.isEmpty()) { |
999 |
> |
assertFalse(y.isEmpty()); |
1000 |
> |
assertEquals(x.pollFirst(), y.pollFirst()); |
1001 |
|
} |
1002 |
+ |
assertTrue(y.isEmpty()); |
1003 |
|
} |
1004 |
|
|
1005 |
|
/** |