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.9 by jsr166, Sat Nov 21 10:25:05 2009 UTC vs.
Revision 1.15 by jsr166, Thu Nov 4 01:04:54 2010 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);
# Line 19 | Line 19 | public class ConcurrentSkipListSubSetTes
19  
20      static class MyReverseComparator implements Comparator {
21          public int compare(Object x, Object y) {
22 <            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;
22 >            return ((Comparable)y).compareTo(x);
23          }
24      }
25  
# Line 182 | Line 178 | public class ConcurrentSkipListSubSetTes
178              shouldThrow();
179          } catch (NullPointerException success) {}
180      }
181 +
182      /**
183       * addAll of a collection with null elements throws NPE
184       */
# Line 193 | Line 190 | public class ConcurrentSkipListSubSetTes
190              shouldThrow();
191          } catch (NullPointerException success) {}
192      }
193 +
194      /**
195       * addAll of a collection with any null elements throws NPE after
196       * possibly adding some elements
# Line 212 | Line 210 | public class ConcurrentSkipListSubSetTes
210       * Set contains all elements of successful addAll
211       */
212      public void testAddAll5() {
213 <        try {
214 <            Integer[] empty = new Integer[0];
215 <            Integer[] ints = new Integer[SIZE];
216 <            for (int i = 0; i < SIZE; ++i)
217 <                ints[i] = new Integer(SIZE-1- i);
218 <            NavigableSet q = set0();
219 <            assertFalse(q.addAll(Arrays.asList(empty)));
220 <            assertTrue(q.addAll(Arrays.asList(ints)));
221 <            for (int i = 0; i < SIZE; ++i)
224 <                assertEquals(new Integer(i), q.pollFirst());
225 <        }
226 <        finally {}
213 >        Integer[] empty = new Integer[0];
214 >        Integer[] ints = new Integer[SIZE];
215 >        for (int i = 0; i < SIZE; ++i)
216 >            ints[i] = new Integer(SIZE-1- i);
217 >        NavigableSet q = set0();
218 >        assertFalse(q.addAll(Arrays.asList(empty)));
219 >        assertTrue(q.addAll(Arrays.asList(ints)));
220 >        for (int i = 0; i < SIZE; ++i)
221 >            assertEquals(new Integer(i), q.pollFirst());
222      }
223  
224      /**
# Line 232 | Line 227 | public class ConcurrentSkipListSubSetTes
227      public void testPoll() {
228          NavigableSet q = populatedSet(SIZE);
229          for (int i = 0; i < SIZE; ++i) {
230 <            assertEquals(i, ((Integer)q.pollFirst()).intValue());
230 >            assertEquals(i, q.pollFirst());
231          }
232          assertNull(q.pollFirst());
233      }
# Line 345 | Line 340 | public class ConcurrentSkipListSubSetTes
340  
341          Object e4 = q.lower(zero);
342          assertNull(e4);
348
343      }
344  
345      /**
# Line 364 | Line 358 | public class ConcurrentSkipListSubSetTes
358  
359          Object e4 = q.higher(six);
360          assertNull(e4);
367
361      }
362  
363      /**
# Line 383 | Line 376 | public class ConcurrentSkipListSubSetTes
376  
377          Object e4 = q.floor(zero);
378          assertNull(e4);
386
379      }
380  
381      /**
# Line 402 | Line 394 | public class ConcurrentSkipListSubSetTes
394  
395          Object e4 = q.ceiling(six);
396          assertNull(e4);
405
397      }
398  
399      /**
400 <     * toArray contains all elements
400 >     * toArray contains all elements in sorted order
401       */
402      public void testToArray() {
403          NavigableSet q = populatedSet(SIZE);
404          Object[] o = q.toArray();
414        Arrays.sort(o);
405          for (int i = 0; i < o.length; i++)
406 <            assertEquals(o[i], q.pollFirst());
406 >            assertSame(o[i], q.pollFirst());
407      }
408  
409      /**
410 <     * toArray(a) contains all elements
410 >     * toArray(a) contains all elements in sorted order
411       */
412      public void testToArray2() {
413          NavigableSet q = populatedSet(SIZE);
414          Integer[] ints = new Integer[SIZE];
415 <        ints = (Integer[])q.toArray(ints);
426 <        Arrays.sort(ints);
415 >        assertSame(ints, q.toArray(ints));
416          for (int i = 0; i < ints.length; i++)
417 <            assertEquals(ints[i], q.pollFirst());
417 >            assertSame(ints[i], q.pollFirst());
418      }
419  
420      /**
# Line 459 | Line 448 | public class ConcurrentSkipListSubSetTes
448      /**
449       * iterator.remove removes current element
450       */
451 <    public void testIteratorRemove () {
451 >    public void testIteratorRemove() {
452          final NavigableSet q = set0();
453          q.add(new Integer(2));
454          q.add(new Integer(1));
# Line 691 | Line 680 | public class ConcurrentSkipListSubSetTes
680              shouldThrow();
681          } catch (NullPointerException success) {}
682      }
683 +
684      /**
685       * addAll of a collection with null elements throws NPE
686       */
# Line 702 | Line 692 | public class ConcurrentSkipListSubSetTes
692              shouldThrow();
693          } catch (NullPointerException success) {}
694      }
695 +
696      /**
697       * addAll of a collection with any null elements throws NPE after
698       * possibly adding some elements
# Line 721 | Line 712 | public class ConcurrentSkipListSubSetTes
712       * Set contains all elements of successful addAll
713       */
714      public void testDescendingAddAll5() {
715 <        try {
716 <            Integer[] empty = new Integer[0];
717 <            Integer[] ints = new Integer[SIZE];
718 <            for (int i = 0; i < SIZE; ++i)
719 <                ints[i] = new Integer(SIZE-1- i);
720 <            NavigableSet q = dset0();
721 <            assertFalse(q.addAll(Arrays.asList(empty)));
722 <            assertTrue(q.addAll(Arrays.asList(ints)));
723 <            for (int i = 0; i < SIZE; ++i)
733 <                assertEquals(new Integer(i), q.pollFirst());
734 <        }
735 <        finally {}
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)
723 >            assertEquals(new Integer(i), q.pollFirst());
724      }
725  
726      /**
# Line 741 | Line 729 | public class ConcurrentSkipListSubSetTes
729      public void testDescendingPoll() {
730          NavigableSet q = populatedSet(SIZE);
731          for (int i = 0; i < SIZE; ++i) {
732 <            assertEquals(i, ((Integer)q.pollFirst()).intValue());
732 >            assertEquals(i, q.pollFirst());
733          }
734          assertNull(q.pollFirst());
735      }
# Line 854 | Line 842 | public class ConcurrentSkipListSubSetTes
842  
843          Object e4 = q.lower(zero);
844          assertNull(e4);
857
845      }
846  
847      /**
# Line 873 | Line 860 | public class ConcurrentSkipListSubSetTes
860  
861          Object e4 = q.higher(m6);
862          assertNull(e4);
876
863      }
864  
865      /**
# Line 892 | Line 878 | public class ConcurrentSkipListSubSetTes
878  
879          Object e4 = q.floor(zero);
880          assertNull(e4);
895
881      }
882  
883      /**
# Line 911 | Line 896 | public class ConcurrentSkipListSubSetTes
896  
897          Object e4 = q.ceiling(m6);
898          assertNull(e4);
914
899      }
900  
901      /**
# Line 931 | Line 915 | public class ConcurrentSkipListSubSetTes
915      public void testDescendingToArray2() {
916          NavigableSet q = populatedSet(SIZE);
917          Integer[] ints = new Integer[SIZE];
918 <        ints = (Integer[])q.toArray(ints);
918 >        assertSame(ints, q.toArray(ints));
919          Arrays.sort(ints);
920          for (int i = 0; i < ints.length; i++)
921              assertEquals(ints[i], q.pollFirst());
# Line 968 | Line 952 | public class ConcurrentSkipListSubSetTes
952      /**
953       * iterator.remove removes current element
954       */
955 <    public void testDescendingIteratorRemove () {
955 >    public void testDescendingIteratorRemove() {
956          final NavigableSet q = dset0();
957          q.add(new Integer(2));
958          q.add(new Integer(1));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines