ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ConcurrentSkipListSubSetTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ConcurrentSkipListSubSetTest.java (file contents):
Revision 1.4 by dl, Thu Apr 20 20:35:00 2006 UTC vs.
Revision 1.29 by jsr166, Sat Jan 17 22:55:06 2015 UTC

# Line 1 | Line 1
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 {
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();
# Line 61 | Line 63 | public class ConcurrentSkipListSubSetTes
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();
# Line 77 | Line 79 | public class ConcurrentSkipListSubSetTes
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();
86 >    private static NavigableSet set0() {
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();
92 >    private static NavigableSet dset0() {
93 >        ConcurrentSkipListSet set = new ConcurrentSkipListSet();
94          assertTrue(set.isEmpty());
95          return set;
96      }
97 <
97 >
98      /**
99       * A new set has unbounded capacity
100       */
# Line 100 | Line 102 | public class ConcurrentSkipListSubSetTes
102          assertEquals(0, set0().size());
103      }
104  
103
105      /**
106       * isEmpty is true before add, false after
107       */
# Line 134 | Line 135 | public class ConcurrentSkipListSubSetTes
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      /**
# Line 168 | Line 169 | public class ConcurrentSkipListSubSetTes
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       */
# Line 181 | Line 180 | public class ConcurrentSkipListSubSetTes
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       */
# Line 193 | Line 192 | public class ConcurrentSkipListSubSetTes
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
# Line 208 | Line 207 | public class ConcurrentSkipListSubSetTes
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      /**
# Line 236 | Line 231 | public class ConcurrentSkipListSubSetTes
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      /**
# Line 246 | Line 241 | public class ConcurrentSkipListSubSetTes
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      }
259 <        
259 >
260      /**
261       * contains(x) reports true when elements added but not yet removed
262       */
# Line 325 | Line 326 | public class ConcurrentSkipListSubSetTes
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       */
# Line 349 | Line 348 | public class ConcurrentSkipListSubSetTes
348  
349          Object e4 = q.lower(zero);
350          assertNull(e4);
352
351      }
352  
353      /**
# Line 368 | Line 366 | public class ConcurrentSkipListSubSetTes
366  
367          Object e4 = q.higher(six);
368          assertNull(e4);
371
369      }
370  
371      /**
# Line 387 | Line 384 | public class ConcurrentSkipListSubSetTes
384  
385          Object e4 = q.floor(zero);
386          assertNull(e4);
390
387      }
388  
389      /**
# Line 406 | Line 402 | public class ConcurrentSkipListSubSetTes
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);
425 <        for(int i = 0; i < ints.length; i++)
426 <            assertEquals(ints[i], q.pollFirst());
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 >            assertSame(ints[i], q.pollFirst());
427      }
428 <    
428 >
429      /**
430       * iterator iterates through all elements
431       */
432      public void testIterator() {
433          NavigableSet q = populatedSet(SIZE);
434 <        int i = 0;
435 <        Iterator it = q.iterator();
436 <        while(it.hasNext()) {
434 >        Iterator it = q.iterator();
435 >        int i;
436 >        for (i = 0; it.hasNext(); i++)
437              assertTrue(q.contains(it.next()));
444            ++i;
445        }
438          assertEquals(i, SIZE);
439 +        assertIteratorExhausted(it);
440      }
441  
442      /**
443       * iterator of empty set has no elements
444       */
445      public void testEmptyIterator() {
446 <        NavigableSet q = set0();
454 <        int i = 0;
455 <        Iterator it = q.iterator();
456 <        while(it.hasNext()) {
457 <            assertTrue(q.contains(it.next()));
458 <            ++i;
459 <        }
460 <        assertEquals(i, 0);
446 >        assertIteratorExhausted(set0().iterator());
447      }
448  
449      /**
450       * iterator.remove removes current element
451       */
452 <    public void testIteratorRemove () {
452 >    public void testIteratorRemove() {
453          final NavigableSet q = set0();
454          q.add(new Integer(2));
455          q.add(new Integer(1));
# Line 479 | Line 465 | public class ConcurrentSkipListSubSetTes
465          assertFalse(it.hasNext());
466      }
467  
482
468      /**
469       * toString contains toStrings of elements
470       */
# Line 487 | Line 472 | public class ConcurrentSkipListSubSetTes
472          NavigableSet q = populatedSet(SIZE);
473          String s = q.toString();
474          for (int i = 0; i < SIZE; ++i) {
475 <            assertTrue(s.indexOf(String.valueOf(i)) >= 0);
475 >            assertTrue(s.contains(String.valueOf(i)));
476          }
477 <    }        
477 >    }
478  
479      /**
480 <     * A deserialized serialized set has same elements
480 >     * A deserialized serialized set has same elements
481       */
482 <    public void testSerialization() {
483 <        NavigableSet q = populatedSet(SIZE);
484 <        try {
485 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
486 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
487 <            out.writeObject(q);
488 <            out.close();
489 <
490 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
491 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
492 <            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();
482 >    public void testSerialization() throws Exception {
483 >        NavigableSet x = populatedSet(SIZE);
484 >        NavigableSet y = serialClone(x);
485 >
486 >        assertNotSame(y, x);
487 >        assertEquals(x.size(), y.size());
488 >        assertEquals(x, y);
489 >        assertEquals(y, x);
490 >        while (!x.isEmpty()) {
491 >            assertFalse(y.isEmpty());
492 >            assertEquals(x.pollFirst(), y.pollFirst());
493          }
494 +        assertTrue(y.isEmpty());
495      }
496  
497      /**
# Line 652 | Line 632 | public class ConcurrentSkipListSubSetTes
632       * add(null) throws NPE
633       */
634      public void testDescendingAddNull() {
635 <        try {
635 >        try {
636              NavigableSet q = dset0();
637              q.add(null);
638              shouldThrow();
639 <        } catch (NullPointerException success) { }  
639 >        } catch (NullPointerException success) {}
640      }
641  
642      /**
# Line 686 | Line 666 | public class ConcurrentSkipListSubSetTes
666              q.add(new Object());
667              q.add(new Object());
668              shouldThrow();
669 <        }
690 <        catch(ClassCastException success) {}
669 >        } catch (ClassCastException success) {}
670      }
671  
693
672      /**
673       * addAll(null) throws NPE
674       */
# Line 699 | Line 677 | public class ConcurrentSkipListSubSetTes
677              NavigableSet q = dset0();
678              q.addAll(null);
679              shouldThrow();
680 <        }
703 <        catch (NullPointerException success) {}
680 >        } catch (NullPointerException success) {}
681      }
682 +
683      /**
684       * addAll of a collection with null elements throws NPE
685       */
# Line 711 | Line 689 | public class ConcurrentSkipListSubSetTes
689              Integer[] ints = new Integer[SIZE];
690              q.addAll(Arrays.asList(ints));
691              shouldThrow();
692 <        }
715 <        catch (NullPointerException success) {}
692 >        } catch (NullPointerException success) {}
693      }
694 +
695      /**
696       * addAll of a collection with any null elements throws NPE after
697       * possibly adding some elements
# Line 726 | Line 704 | public class ConcurrentSkipListSubSetTes
704                  ints[i] = new Integer(i+SIZE);
705              q.addAll(Arrays.asList(ints));
706              shouldThrow();
707 <        }
730 <        catch (NullPointerException success) {}
707 >        } catch (NullPointerException success) {}
708      }
709  
710      /**
711       * Set contains all elements of successful addAll
712       */
713      public void testDescendingAddAll5() {
714 <        try {
715 <            Integer[] empty = new Integer[0];
716 <            Integer[] ints = new Integer[SIZE];
717 <            for (int i = 0; i < SIZE; ++i)
718 <                ints[i] = new Integer(SIZE-1- i);
719 <            NavigableSet q = dset0();
720 <            assertFalse(q.addAll(Arrays.asList(empty)));
721 <            assertTrue(q.addAll(Arrays.asList(ints)));
722 <            for (int i = 0; i < SIZE; ++i)
746 <                assertEquals(new Integer(i), q.pollFirst());
747 <        }
748 <        finally {}
714 >        Integer[] empty = new Integer[0];
715 >        Integer[] ints = new Integer[SIZE];
716 >        for (int i = 0; i < SIZE; ++i)
717 >            ints[i] = new Integer(SIZE-1- i);
718 >        NavigableSet q = dset0();
719 >        assertFalse(q.addAll(Arrays.asList(empty)));
720 >        assertTrue(q.addAll(Arrays.asList(ints)));
721 >        for (int i = 0; i < SIZE; ++i)
722 >            assertEquals(new Integer(i), q.pollFirst());
723      }
724  
725      /**
# Line 754 | Line 728 | public class ConcurrentSkipListSubSetTes
728      public void testDescendingPoll() {
729          NavigableSet q = populatedSet(SIZE);
730          for (int i = 0; i < SIZE; ++i) {
731 <            assertEquals(i, ((Integer)q.pollFirst()).intValue());
731 >            assertEquals(i, q.pollFirst());
732          }
733 <        assertNull(q.pollFirst());
733 >        assertNull(q.pollFirst());
734      }
735  
736      /**
# Line 764 | Line 738 | public class ConcurrentSkipListSubSetTes
738       */
739      public void testDescendingRemoveElement() {
740          NavigableSet q = populatedSet(SIZE);
741 <        for (int i = 1; i < SIZE; i+=2) {
741 >        for (int i = 1; i < SIZE; i += 2) {
742              assertTrue(q.remove(new Integer(i)));
743          }
744 <        for (int i = 0; i < SIZE; i+=2) {
744 >        for (int i = 0; i < SIZE; i += 2 ) {
745              assertTrue(q.remove(new Integer(i)));
746              assertFalse(q.remove(new Integer(i+1)));
747          }
748          assertTrue(q.isEmpty());
749      }
750 <        
750 >
751      /**
752       * contains(x) reports true when elements added but not yet removed
753       */
# Line 843 | Line 817 | public class ConcurrentSkipListSubSetTes
817              assertTrue(q.removeAll(p));
818              assertEquals(SIZE-i, q.size());
819              for (int j = 0; j < i; ++j) {
820 <                Integer I = (Integer)(p.pollFirst());
821 <                assertFalse(q.contains(I));
820 >                Integer x = (Integer)(p.pollFirst());
821 >                assertFalse(q.contains(x));
822              }
823          }
824      }
825  
852    
853
826      /**
827       * lower returns preceding element
828       */
# Line 867 | Line 839 | public class ConcurrentSkipListSubSetTes
839  
840          Object e4 = q.lower(zero);
841          assertNull(e4);
870
842      }
843  
844      /**
# Line 886 | Line 857 | public class ConcurrentSkipListSubSetTes
857  
858          Object e4 = q.higher(m6);
859          assertNull(e4);
889
860      }
861  
862      /**
# Line 905 | Line 875 | public class ConcurrentSkipListSubSetTes
875  
876          Object e4 = q.floor(zero);
877          assertNull(e4);
908
878      }
879  
880      /**
# Line 924 | Line 893 | public class ConcurrentSkipListSubSetTes
893  
894          Object e4 = q.ceiling(m6);
895          assertNull(e4);
927
896      }
897  
898      /**
# Line 932 | Line 900 | public class ConcurrentSkipListSubSetTes
900       */
901      public void testDescendingToArray() {
902          NavigableSet q = populatedSet(SIZE);
903 <        Object[] o = q.toArray();
903 >        Object[] o = q.toArray();
904          Arrays.sort(o);
905 <        for(int i = 0; i < o.length; i++)
906 <            assertEquals(o[i], q.pollFirst());
905 >        for (int i = 0; i < o.length; i++)
906 >            assertEquals(o[i], q.pollFirst());
907      }
908  
909      /**
# Line 943 | Line 911 | public class ConcurrentSkipListSubSetTes
911       */
912      public void testDescendingToArray2() {
913          NavigableSet q = populatedSet(SIZE);
914 <        Integer[] ints = new Integer[SIZE];
915 <        ints = (Integer[])q.toArray(ints);
914 >        Integer[] ints = new Integer[SIZE];
915 >        assertSame(ints, q.toArray(ints));
916          Arrays.sort(ints);
917 <        for(int i = 0; i < ints.length; i++)
917 >        for (int i = 0; i < ints.length; i++)
918              assertEquals(ints[i], q.pollFirst());
919      }
920 <    
920 >
921      /**
922       * iterator iterates through all elements
923       */
924      public void testDescendingIterator() {
925          NavigableSet q = populatedSet(SIZE);
926          int i = 0;
927 <        Iterator it = q.iterator();
928 <        while(it.hasNext()) {
927 >        Iterator it = q.iterator();
928 >        while (it.hasNext()) {
929              assertTrue(q.contains(it.next()));
930              ++i;
931          }
# Line 970 | Line 938 | public class ConcurrentSkipListSubSetTes
938      public void testDescendingEmptyIterator() {
939          NavigableSet q = dset0();
940          int i = 0;
941 <        Iterator it = q.iterator();
942 <        while(it.hasNext()) {
941 >        Iterator it = q.iterator();
942 >        while (it.hasNext()) {
943              assertTrue(q.contains(it.next()));
944              ++i;
945          }
946 <        assertEquals(i, 0);
946 >        assertEquals(0, i);
947      }
948  
949      /**
950       * iterator.remove removes current element
951       */
952 <    public void testDescendingIteratorRemove () {
952 >    public void testDescendingIteratorRemove() {
953          final NavigableSet q = dset0();
954          q.add(new Integer(2));
955          q.add(new Integer(1));
# Line 997 | Line 965 | public class ConcurrentSkipListSubSetTes
965          assertFalse(it.hasNext());
966      }
967  
1000
968      /**
969       * toString contains toStrings of elements
970       */
# Line 1005 | Line 972 | public class ConcurrentSkipListSubSetTes
972          NavigableSet q = populatedSet(SIZE);
973          String s = q.toString();
974          for (int i = 0; i < SIZE; ++i) {
975 <            assertTrue(s.indexOf(String.valueOf(i)) >= 0);
975 >            assertTrue(s.contains(String.valueOf(i)));
976          }
977 <    }        
977 >    }
978  
979      /**
980 <     * A deserialized serialized set has same elements
980 >     * A deserialized serialized set has same elements
981       */
982 <    public void testDescendingSerialization() {
983 <        NavigableSet q = populatedSet(SIZE);
984 <        try {
985 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
986 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
987 <            out.writeObject(q);
988 <            out.close();
989 <
990 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
991 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
992 <            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();
982 >    public void testDescendingSerialization() throws Exception {
983 >        NavigableSet x = dset5();
984 >        NavigableSet y = serialClone(x);
985 >
986 >        assertNotSame(y, x);
987 >        assertEquals(x.size(), y.size());
988 >        assertEquals(x, y);
989 >        assertEquals(y, x);
990 >        while (!x.isEmpty()) {
991 >            assertFalse(y.isEmpty());
992 >            assertEquals(x.pollFirst(), y.pollFirst());
993          }
994 +        assertTrue(y.isEmpty());
995      }
996  
997      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines