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.28 by jsr166, Wed Dec 31 20:17:39 2014 UTC vs.
Revision 1.39 by jsr166, Mon May 28 21:19:50 2018 UTC

# Line 16 | Line 16 | 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 >        main(suite(), args);
20      }
21      public static Test suite() {
22          return new TestSuite(ConcurrentSkipListSubSetTest.class);
# Line 30 | Line 30 | public class ConcurrentSkipListSubSetTes
30  
31      /**
32       * Returns a new set of given size containing consecutive
33 <     * Integers 0 ... n.
33 >     * Integers 0 ... n - 1.
34       */
35 <    private NavigableSet<Integer> populatedSet(int n) {
36 <        ConcurrentSkipListSet<Integer> q =
37 <            new ConcurrentSkipListSet<Integer>();
35 >    private static NavigableSet<Integer> populatedSet(int n) {
36 >        ConcurrentSkipListSet<Integer> q = new ConcurrentSkipListSet<>();
37          assertTrue(q.isEmpty());
38  
39 <        for (int i = n-1; i >= 0; i -= 2)
39 >        for (int i = n - 1; i >= 0; i -= 2)
40              assertTrue(q.add(new Integer(i)));
41          for (int i = (n & 1); i < n; i += 2)
42              assertTrue(q.add(new Integer(i)));
# Line 52 | Line 51 | public class ConcurrentSkipListSubSetTes
51      /**
52       * Returns a new set of first 5 ints.
53       */
54 <    private NavigableSet set5() {
54 >    private static NavigableSet set5() {
55          ConcurrentSkipListSet q = new ConcurrentSkipListSet();
56          assertTrue(q.isEmpty());
57          q.add(one);
# Line 70 | Line 69 | public class ConcurrentSkipListSubSetTes
69      /**
70       * Returns a new set of first 5 negative ints.
71       */
72 <    private NavigableSet dset5() {
72 >    private static NavigableSet dset5() {
73          ConcurrentSkipListSet q = new ConcurrentSkipListSet();
74          assertTrue(q.isEmpty());
75          q.add(m1);
# Line 122 | Line 121 | public class ConcurrentSkipListSubSetTes
121      public void testSize() {
122          NavigableSet q = populatedSet(SIZE);
123          for (int i = 0; i < SIZE; ++i) {
124 <            assertEquals(SIZE-i, q.size());
124 >            assertEquals(SIZE - i, q.size());
125              q.pollFirst();
126          }
127          for (int i = 0; i < SIZE; ++i) {
# Line 135 | Line 134 | public class ConcurrentSkipListSubSetTes
134       * add(null) throws NPE
135       */
136      public void testAddNull() {
137 +        NavigableSet q = set0();
138          try {
139            NavigableSet q = set0();
139              q.add(null);
140              shouldThrow();
141          } catch (NullPointerException success) {}
# Line 163 | Line 162 | public class ConcurrentSkipListSubSetTes
162       * Add of non-Comparable throws CCE
163       */
164      public void testAddNonComparable() {
165 +        NavigableSet q = set0();
166          try {
167            NavigableSet q = set0();
168            q.add(new Object());
167              q.add(new Object());
168              q.add(new Object());
169              shouldThrow();
# Line 176 | Line 174 | public class ConcurrentSkipListSubSetTes
174       * addAll(null) throws NPE
175       */
176      public void testAddAll1() {
177 +        NavigableSet q = set0();
178          try {
180            NavigableSet q = set0();
179              q.addAll(null);
180              shouldThrow();
181          } catch (NullPointerException success) {}
# Line 187 | Line 185 | public class ConcurrentSkipListSubSetTes
185       * addAll of a collection with null elements throws NPE
186       */
187      public void testAddAll2() {
188 +        NavigableSet q = set0();
189 +        Integer[] ints = new Integer[SIZE];
190          try {
191            NavigableSet q = set0();
192            Integer[] ints = new Integer[SIZE];
191              q.addAll(Arrays.asList(ints));
192              shouldThrow();
193          } catch (NullPointerException success) {}
# Line 200 | Line 198 | public class ConcurrentSkipListSubSetTes
198       * possibly adding some elements
199       */
200      public void testAddAll3() {
201 +        NavigableSet q = set0();
202 +        Integer[] ints = new Integer[SIZE];
203 +        for (int i = 0; i < SIZE - 1; ++i)
204 +            ints[i] = new Integer(i + SIZE);
205          try {
204            NavigableSet q = set0();
205            Integer[] ints = new Integer[SIZE];
206            for (int i = 0; i < SIZE-1; ++i)
207                ints[i] = new Integer(i+SIZE);
206              q.addAll(Arrays.asList(ints));
207              shouldThrow();
208          } catch (NullPointerException success) {}
# Line 217 | Line 215 | public class ConcurrentSkipListSubSetTes
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);
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)));
# Line 245 | Line 243 | public class ConcurrentSkipListSubSetTes
243              assertTrue(q.contains(i));
244              assertTrue(q.remove(i));
245              assertFalse(q.contains(i));
246 <            assertTrue(q.contains(i-1));
246 >            assertTrue(q.contains(i - 1));
247          }
248          for (int i = 0; i < SIZE; i += 2) {
249              assertTrue(q.contains(i));
250              assertTrue(q.remove(i));
251              assertFalse(q.contains(i));
252 <            assertFalse(q.remove(i+1));
253 <            assertFalse(q.contains(i+1));
252 >            assertFalse(q.remove(i + 1));
253 >            assertFalse(q.contains(i + 1));
254          }
255          assertTrue(q.isEmpty());
256      }
# Line 311 | Line 309 | public class ConcurrentSkipListSubSetTes
309                  assertTrue(changed);
310  
311              assertTrue(q.containsAll(p));
312 <            assertEquals(SIZE-i, q.size());
312 >            assertEquals(SIZE - i, q.size());
313              p.pollFirst();
314          }
315      }
# Line 324 | Line 322 | public class ConcurrentSkipListSubSetTes
322              NavigableSet q = populatedSet(SIZE);
323              NavigableSet p = populatedSet(i);
324              assertTrue(q.removeAll(p));
325 <            assertEquals(SIZE-i, q.size());
325 >            assertEquals(SIZE - i, q.size());
326              for (int j = 0; j < i; ++j) {
327                  Integer x = (Integer)(p.pollFirst());
328                  assertFalse(q.contains(x));
# Line 409 | Line 407 | public class ConcurrentSkipListSubSetTes
407       */
408      public void testToArray() {
409          NavigableSet q = populatedSet(SIZE);
410 <        Object[] o = q.toArray();
411 <        for (int i = 0; i < o.length; i++)
412 <            assertSame(o[i], q.pollFirst());
410 >        Object[] a = q.toArray();
411 >        assertSame(Object[].class, a.getClass());
412 >        for (Object o : a)
413 >            assertSame(o, q.pollFirst());
414 >        assertTrue(q.isEmpty());
415      }
416  
417      /**
# Line 422 | Line 422 | public class ConcurrentSkipListSubSetTes
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());
425 >        for (Integer o : ints)
426 >            assertSame(o, q.pollFirst());
427 >        assertTrue(q.isEmpty());
428      }
429  
430      /**
# Line 431 | Line 432 | public class ConcurrentSkipListSubSetTes
432       */
433      public void testIterator() {
434          NavigableSet q = populatedSet(SIZE);
434        int i = 0;
435          Iterator it = q.iterator();
436 <        while (it.hasNext()) {
436 >        int i;
437 >        for (i = 0; it.hasNext(); i++)
438              assertTrue(q.contains(it.next()));
438            ++i;
439        }
439          assertEquals(i, SIZE);
440 +        assertIteratorExhausted(it);
441      }
442  
443      /**
444       * iterator of empty set has no elements
445       */
446      public void testEmptyIterator() {
447 <        NavigableSet q = set0();
448 <        int i = 0;
449 <        Iterator it = q.iterator();
450 <        while (it.hasNext()) {
451 <            assertTrue(q.contains(it.next()));
452 <            ++i;
453 <        }
454 <        assertEquals(0, i);
447 >        assertIteratorExhausted(set0().iterator());
448      }
449  
450      /**
# Line 485 | Line 478 | public class ConcurrentSkipListSubSetTes
478      }
479  
480      /**
481 <     * A deserialized serialized set has same elements
481 >     * A deserialized/reserialized set equals original
482       */
483      public void testSerialization() throws Exception {
484          NavigableSet x = populatedSet(SIZE);
# Line 627 | Line 620 | public class ConcurrentSkipListSubSetTes
620      public void testDescendingSize() {
621          NavigableSet q = populatedSet(SIZE);
622          for (int i = 0; i < SIZE; ++i) {
623 <            assertEquals(SIZE-i, q.size());
623 >            assertEquals(SIZE - i, q.size());
624              q.pollFirst();
625          }
626          for (int i = 0; i < SIZE; ++i) {
# Line 640 | Line 633 | public class ConcurrentSkipListSubSetTes
633       * add(null) throws NPE
634       */
635      public void testDescendingAddNull() {
636 +        NavigableSet q = dset0();
637          try {
644            NavigableSet q = dset0();
638              q.add(null);
639              shouldThrow();
640          } catch (NullPointerException success) {}
# Line 668 | Line 661 | public class ConcurrentSkipListSubSetTes
661       * Add of non-Comparable throws CCE
662       */
663      public void testDescendingAddNonComparable() {
664 +        NavigableSet q = dset0();
665          try {
672            NavigableSet q = dset0();
673            q.add(new Object());
666              q.add(new Object());
667              q.add(new Object());
668              shouldThrow();
# Line 681 | Line 673 | public class ConcurrentSkipListSubSetTes
673       * addAll(null) throws NPE
674       */
675      public void testDescendingAddAll1() {
676 +        NavigableSet q = dset0();
677          try {
685            NavigableSet q = dset0();
678              q.addAll(null);
679              shouldThrow();
680          } catch (NullPointerException success) {}
# Line 692 | Line 684 | public class ConcurrentSkipListSubSetTes
684       * addAll of a collection with null elements throws NPE
685       */
686      public void testDescendingAddAll2() {
687 +        NavigableSet q = dset0();
688 +        Integer[] ints = new Integer[SIZE];
689          try {
696            NavigableSet q = dset0();
697            Integer[] ints = new Integer[SIZE];
690              q.addAll(Arrays.asList(ints));
691              shouldThrow();
692          } catch (NullPointerException success) {}
# Line 705 | Line 697 | public class ConcurrentSkipListSubSetTes
697       * possibly adding some elements
698       */
699      public void testDescendingAddAll3() {
700 +        NavigableSet q = dset0();
701 +        Integer[] ints = new Integer[SIZE];
702 +        for (int i = 0; i < SIZE - 1; ++i)
703 +            ints[i] = new Integer(i + SIZE);
704          try {
709            NavigableSet q = dset0();
710            Integer[] ints = new Integer[SIZE];
711            for (int i = 0; i < SIZE-1; ++i)
712                ints[i] = new Integer(i+SIZE);
705              q.addAll(Arrays.asList(ints));
706              shouldThrow();
707          } catch (NullPointerException success) {}
# Line 722 | Line 714 | public class ConcurrentSkipListSubSetTes
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);
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)));
# Line 751 | Line 743 | public class ConcurrentSkipListSubSetTes
743          }
744          for (int i = 0; i < SIZE; i += 2 ) {
745              assertTrue(q.remove(new Integer(i)));
746 <            assertFalse(q.remove(new Integer(i+1)));
746 >            assertFalse(q.remove(new Integer(i + 1)));
747          }
748          assertTrue(q.isEmpty());
749      }
# Line 810 | Line 802 | public class ConcurrentSkipListSubSetTes
802                  assertTrue(changed);
803  
804              assertTrue(q.containsAll(p));
805 <            assertEquals(SIZE-i, q.size());
805 >            assertEquals(SIZE - i, q.size());
806              p.pollFirst();
807          }
808      }
# Line 823 | Line 815 | public class ConcurrentSkipListSubSetTes
815              NavigableSet q = populatedSet(SIZE);
816              NavigableSet p = populatedSet(i);
817              assertTrue(q.removeAll(p));
818 <            assertEquals(SIZE-i, q.size());
818 >            assertEquals(SIZE - i, q.size());
819              for (int j = 0; j < i; ++j) {
820                  Integer x = (Integer)(p.pollFirst());
821                  assertFalse(q.contains(x));
# Line 985 | Line 977 | public class ConcurrentSkipListSubSetTes
977      }
978  
979      /**
980 <     * A deserialized serialized set has same elements
980 >     * A deserialized/reserialized set equals original
981       */
982      public void testDescendingSerialization() throws Exception {
983          NavigableSet x = dset5();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines