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.5 by jsr166, Mon Nov 2 20:28:31 2009 UTC vs.
Revision 1.10 by jsr166, Sat Nov 21 10:29:50 2009 UTC

# Line 11 | Line 11 | import java.io.*;
11  
12   public class ConcurrentSkipListSubSetTest 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(ConcurrentSkipListSubSetTest.class);
17 >        return new TestSuite(ConcurrentSkipListSubSetTest.class);
18      }
19  
20      static class MyReverseComparator implements Comparator {
# Line 35 | Line 35 | public class ConcurrentSkipListSubSetTes
35          ConcurrentSkipListSet q = new ConcurrentSkipListSet();
36          assertTrue(q.isEmpty());
37  
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)
41 <            assertTrue(q.add(new Integer(i)));
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)
41 >            assertTrue(q.add(new Integer(i)));
42          assertTrue(q.add(new Integer(-n)));
43          assertTrue(q.add(new Integer(n)));
44          NavigableSet s = q.subSet(new Integer(0), true, new Integer(n), false);
45          assertFalse(s.isEmpty());
46 <        assertEquals(n, s.size());
46 >        assertEquals(n, s.size());
47          return s;
48      }
49  
# Line 61 | Line 61 | public class ConcurrentSkipListSubSetTes
61          q.add(zero);
62          q.add(seven);
63          NavigableSet s = q.subSet(one, true, seven, false);
64 <        assertEquals(5, s.size());
64 >        assertEquals(5, s.size());
65          return s;
66      }
67  
# Line 77 | Line 77 | public class ConcurrentSkipListSubSetTes
77          q.add(m4);
78          q.add(m5);
79          NavigableSet s = q.descendingSet();
80 <        assertEquals(5, s.size());
80 >        assertEquals(5, s.size());
81          return s;
82      }
83  
84      private static NavigableSet set0() {
85 <        ConcurrentSkipListSet set = new ConcurrentSkipListSet();
85 >        ConcurrentSkipListSet set = new ConcurrentSkipListSet();
86          assertTrue(set.isEmpty());
87          return set.tailSet(m1, true);
88      }
89  
90      private static NavigableSet dset0() {
91 <        ConcurrentSkipListSet set = new ConcurrentSkipListSet();
91 >        ConcurrentSkipListSet set = new ConcurrentSkipListSet();
92          assertTrue(set.isEmpty());
93          return set;
94      }
# Line 134 | Line 134 | public class ConcurrentSkipListSubSetTes
134       * add(null) throws NPE
135       */
136      public void testAddNull() {
137 <        try {
137 >        try {
138              NavigableSet q = set0();
139              q.add(null);
140              shouldThrow();
141 <        } catch (NullPointerException success) { }
141 >        } catch (NullPointerException success) {}
142      }
143  
144      /**
# Line 168 | Line 168 | public class ConcurrentSkipListSubSetTes
168              q.add(new Object());
169              q.add(new Object());
170              shouldThrow();
171 <        }
172 <        catch(ClassCastException success) {}
171 >        } catch (ClassCastException success) {}
172      }
173  
174  
# 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       * addAll of a collection with null elements throws NPE
# Line 193 | Line 191 | public class ConcurrentSkipListSubSetTes
191              Integer[] ints = new Integer[SIZE];
192              q.addAll(Arrays.asList(ints));
193              shouldThrow();
194 <        }
197 <        catch (NullPointerException success) {}
194 >        } catch (NullPointerException success) {}
195      }
196      /**
197       * addAll of a collection with any null elements throws NPE after
# Line 208 | Line 205 | public class ConcurrentSkipListSubSetTes
205                  ints[i] = new Integer(i+SIZE);
206              q.addAll(Arrays.asList(ints));
207              shouldThrow();
208 <        }
212 <        catch (NullPointerException success) {}
208 >        } catch (NullPointerException success) {}
209      }
210  
211      /**
212       * Set contains all elements of successful addAll
213       */
214      public void testAddAll5() {
215 <        try {
216 <            Integer[] empty = new Integer[0];
217 <            Integer[] ints = new Integer[SIZE];
218 <            for (int i = 0; i < SIZE; ++i)
219 <                ints[i] = new Integer(SIZE-1- i);
220 <            NavigableSet q = set0();
221 <            assertFalse(q.addAll(Arrays.asList(empty)));
222 <            assertTrue(q.addAll(Arrays.asList(ints)));
223 <            for (int i = 0; i < SIZE; ++i)
228 <                assertEquals(new Integer(i), q.pollFirst());
229 <        }
230 <        finally {}
215 >        Integer[] empty = new Integer[0];
216 >        Integer[] ints = new Integer[SIZE];
217 >        for (int i = 0; i < SIZE; ++i)
218 >            ints[i] = new Integer(SIZE-1- i);
219 >        NavigableSet q = set0();
220 >        assertFalse(q.addAll(Arrays.asList(empty)));
221 >        assertTrue(q.addAll(Arrays.asList(ints)));
222 >        for (int i = 0; i < SIZE; ++i)
223 >            assertEquals(new Integer(i), q.pollFirst());
224      }
225  
226      /**
# Line 238 | Line 231 | public class ConcurrentSkipListSubSetTes
231          for (int i = 0; i < SIZE; ++i) {
232              assertEquals(i, ((Integer)q.pollFirst()).intValue());
233          }
234 <        assertNull(q.pollFirst());
234 >        assertNull(q.pollFirst());
235      }
236  
237      /**
# Line 414 | Line 407 | public class ConcurrentSkipListSubSetTes
407       */
408      public void testToArray() {
409          NavigableSet q = populatedSet(SIZE);
410 <        Object[] o = q.toArray();
410 >        Object[] o = q.toArray();
411          Arrays.sort(o);
412 <        for(int i = 0; i < o.length; i++)
413 <            assertEquals(o[i], q.pollFirst());
412 >        for (int i = 0; i < o.length; i++)
413 >            assertEquals(o[i], q.pollFirst());
414      }
415  
416      /**
# Line 425 | Line 418 | public class ConcurrentSkipListSubSetTes
418       */
419      public void testToArray2() {
420          NavigableSet q = populatedSet(SIZE);
421 <        Integer[] ints = new Integer[SIZE];
422 <        ints = (Integer[])q.toArray(ints);
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  
# Line 438 | Line 431 | public class ConcurrentSkipListSubSetTes
431      public void testIterator() {
432          NavigableSet q = populatedSet(SIZE);
433          int i = 0;
434 <        Iterator it = q.iterator();
435 <        while(it.hasNext()) {
434 >        Iterator it = q.iterator();
435 >        while (it.hasNext()) {
436              assertTrue(q.contains(it.next()));
437              ++i;
438          }
# Line 452 | Line 445 | public class ConcurrentSkipListSubSetTes
445      public void testEmptyIterator() {
446          NavigableSet q = set0();
447          int i = 0;
448 <        Iterator it = q.iterator();
449 <        while(it.hasNext()) {
448 >        Iterator it = q.iterator();
449 >        while (it.hasNext()) {
450              assertTrue(q.contains(it.next()));
451              ++i;
452          }
# Line 494 | Line 487 | public class ConcurrentSkipListSubSetTes
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())
510 <                assertEquals(q.pollFirst(), r.pollFirst());
511 <        } catch(Exception e){
512 <            e.printStackTrace();
513 <            unexpectedException();
514 <        }
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      /**
# Line 652 | Line 640 | public class ConcurrentSkipListSubSetTes
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      /**
# Line 686 | Line 674 | public class ConcurrentSkipListSubSetTes
674              q.add(new Object());
675              q.add(new Object());
676              shouldThrow();
677 <        }
690 <        catch(ClassCastException success) {}
677 >        } catch (ClassCastException success) {}
678      }
679  
680  
# Line 699 | Line 686 | public class ConcurrentSkipListSubSetTes
686              NavigableSet q = dset0();
687              q.addAll(null);
688              shouldThrow();
689 <        }
703 <        catch (NullPointerException success) {}
689 >        } catch (NullPointerException success) {}
690      }
691      /**
692       * addAll of a collection with null elements throws NPE
# Line 711 | Line 697 | public class ConcurrentSkipListSubSetTes
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       * addAll of a collection with any null elements throws NPE after
# Line 726 | Line 711 | public class ConcurrentSkipListSubSetTes
711                  ints[i] = new Integer(i+SIZE);
712              q.addAll(Arrays.asList(ints));
713              shouldThrow();
714 <        }
730 <        catch (NullPointerException success) {}
714 >        } catch (NullPointerException success) {}
715      }
716  
717      /**
718       * Set contains all elements of successful addAll
719       */
720      public void testDescendingAddAll5() {
721 <        try {
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)
746 <                assertEquals(new Integer(i), q.pollFirst());
747 <        }
748 <        finally {}
721 >        Integer[] empty = new Integer[0];
722 >        Integer[] ints = new Integer[SIZE];
723 >        for (int i = 0; i < SIZE; ++i)
724 >            ints[i] = new Integer(SIZE-1- i);
725 >        NavigableSet q = dset0();
726 >        assertFalse(q.addAll(Arrays.asList(empty)));
727 >        assertTrue(q.addAll(Arrays.asList(ints)));
728 >        for (int i = 0; i < SIZE; ++i)
729 >            assertEquals(new Integer(i), q.pollFirst());
730      }
731  
732      /**
# Line 756 | Line 737 | public class ConcurrentSkipListSubSetTes
737          for (int i = 0; i < SIZE; ++i) {
738              assertEquals(i, ((Integer)q.pollFirst()).intValue());
739          }
740 <        assertNull(q.pollFirst());
740 >        assertNull(q.pollFirst());
741      }
742  
743      /**
# Line 932 | Line 913 | public class ConcurrentSkipListSubSetTes
913       */
914      public void testDescendingToArray() {
915          NavigableSet q = populatedSet(SIZE);
916 <        Object[] o = q.toArray();
916 >        Object[] o = q.toArray();
917          Arrays.sort(o);
918 <        for(int i = 0; i < o.length; i++)
919 <            assertEquals(o[i], q.pollFirst());
918 >        for (int i = 0; i < o.length; i++)
919 >            assertEquals(o[i], q.pollFirst());
920      }
921  
922      /**
# Line 943 | Line 924 | public class ConcurrentSkipListSubSetTes
924       */
925      public void testDescendingToArray2() {
926          NavigableSet q = populatedSet(SIZE);
927 <        Integer[] ints = new Integer[SIZE];
928 <        ints = (Integer[])q.toArray(ints);
927 >        Integer[] ints = new Integer[SIZE];
928 >        ints = (Integer[])q.toArray(ints);
929          Arrays.sort(ints);
930 <        for(int i = 0; i < ints.length; i++)
930 >        for (int i = 0; i < ints.length; i++)
931              assertEquals(ints[i], q.pollFirst());
932      }
933  
# Line 956 | Line 937 | public class ConcurrentSkipListSubSetTes
937      public void testDescendingIterator() {
938          NavigableSet q = populatedSet(SIZE);
939          int i = 0;
940 <        Iterator it = q.iterator();
941 <        while(it.hasNext()) {
940 >        Iterator it = q.iterator();
941 >        while (it.hasNext()) {
942              assertTrue(q.contains(it.next()));
943              ++i;
944          }
# Line 970 | Line 951 | public class ConcurrentSkipListSubSetTes
951      public void testDescendingEmptyIterator() {
952          NavigableSet q = dset0();
953          int i = 0;
954 <        Iterator it = q.iterator();
955 <        while(it.hasNext()) {
954 >        Iterator it = q.iterator();
955 >        while (it.hasNext()) {
956              assertTrue(q.contains(it.next()));
957              ++i;
958          }
# Line 1012 | Line 993 | public class ConcurrentSkipListSubSetTes
993      /**
994       * A deserialized serialized set has same elements
995       */
996 <    public void testDescendingSerialization() {
996 >    public void testDescendingSerialization() throws Exception {
997          NavigableSet q = populatedSet(SIZE);
998 <        try {
999 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
1000 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
1001 <            out.writeObject(q);
1002 <            out.close();
1003 <
1004 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1005 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1006 <            NavigableSet r = (NavigableSet)in.readObject();
1007 <            assertEquals(q.size(), r.size());
1008 <            while (!q.isEmpty())
1028 <                assertEquals(q.pollFirst(), r.pollFirst());
1029 <        } catch(Exception e){
1030 <            e.printStackTrace();
1031 <            unexpectedException();
1032 <        }
998 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
999 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
1000 >        out.writeObject(q);
1001 >        out.close();
1002 >
1003 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1004 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1005 >        NavigableSet r = (NavigableSet)in.readObject();
1006 >        assertEquals(q.size(), r.size());
1007 >        while (!q.isEmpty())
1008 >            assertEquals(q.pollFirst(), r.pollFirst());
1009      }
1010  
1011      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines