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.24 by jsr166, Thu May 30 03:28:55 2013 UTC vs.
Revision 1.32 by jsr166, Sat Apr 25 04:55:30 2015 UTC

# Line 4 | Line 4
4   * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7 import junit.framework.*;
7   import java.util.Arrays;
9 import java.util.BitSet;
10 import java.util.Collection;
8   import java.util.Comparator;
9   import java.util.Iterator;
10   import java.util.NavigableSet;
14 import java.util.NoSuchElementException;
15 import java.util.Random;
16 import java.util.Set;
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 >        main(suite(), args);
20      }
21      public static Test suite() {
22          return new TestSuite(ConcurrentSkipListSubSetTest.class);
# Line 40 | Line 37 | public class ConcurrentSkipListSubSetTes
37              new ConcurrentSkipListSet<Integer>();
38          assertTrue(q.isEmpty());
39  
40 <        for (int i = n-1; i >= 0; i-=2)
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)
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)));
# Line 138 | Line 135 | public class ConcurrentSkipListSubSetTes
135       * add(null) throws NPE
136       */
137      public void testAddNull() {
138 +        NavigableSet q = set0();
139          try {
142            NavigableSet q = set0();
140              q.add(null);
141              shouldThrow();
142          } catch (NullPointerException success) {}
# Line 166 | Line 163 | public class ConcurrentSkipListSubSetTes
163       * Add of non-Comparable throws CCE
164       */
165      public void testAddNonComparable() {
166 +        NavigableSet q = set0();
167          try {
170            NavigableSet q = set0();
171            q.add(new Object());
168              q.add(new Object());
169              q.add(new Object());
170              shouldThrow();
# Line 179 | Line 175 | public class ConcurrentSkipListSubSetTes
175       * addAll(null) throws NPE
176       */
177      public void testAddAll1() {
178 +        NavigableSet q = set0();
179          try {
183            NavigableSet q = set0();
180              q.addAll(null);
181              shouldThrow();
182          } catch (NullPointerException success) {}
# Line 190 | Line 186 | public class ConcurrentSkipListSubSetTes
186       * addAll of a collection with null elements throws NPE
187       */
188      public void testAddAll2() {
189 +        NavigableSet q = set0();
190 +        Integer[] ints = new Integer[SIZE];
191          try {
194            NavigableSet q = set0();
195            Integer[] ints = new Integer[SIZE];
192              q.addAll(Arrays.asList(ints));
193              shouldThrow();
194          } catch (NullPointerException success) {}
# Line 203 | Line 199 | public class ConcurrentSkipListSubSetTes
199       * possibly adding some elements
200       */
201      public void testAddAll3() {
202 +        NavigableSet q = set0();
203 +        Integer[] ints = new Integer[SIZE];
204 +        for (int i = 0; i < SIZE-1; ++i)
205 +            ints[i] = new Integer(i+SIZE);
206          try {
207            NavigableSet q = set0();
208            Integer[] ints = new Integer[SIZE];
209            for (int i = 0; i < SIZE-1; ++i)
210                ints[i] = new Integer(i+SIZE);
207              q.addAll(Arrays.asList(ints));
208              shouldThrow();
209          } catch (NullPointerException success) {}
# Line 244 | Line 240 | public class ConcurrentSkipListSubSetTes
240       */
241      public void testRemoveElement() {
242          NavigableSet q = populatedSet(SIZE);
243 <        for (int i = 1; i < SIZE; i+=2) {
243 >        for (int i = 1; i < SIZE; i += 2) {
244              assertTrue(q.contains(i));
245              assertTrue(q.remove(i));
246              assertFalse(q.contains(i));
247              assertTrue(q.contains(i-1));
248          }
249 <        for (int i = 0; i < SIZE; i+=2) {
249 >        for (int i = 0; i < SIZE; i += 2) {
250              assertTrue(q.contains(i));
251              assertTrue(q.remove(i));
252              assertFalse(q.contains(i));
# Line 329 | Line 325 | public class ConcurrentSkipListSubSetTes
325              assertTrue(q.removeAll(p));
326              assertEquals(SIZE-i, q.size());
327              for (int j = 0; j < i; ++j) {
328 <                Integer I = (Integer)(p.pollFirst());
329 <                assertFalse(q.contains(I));
328 >                Integer x = (Integer)(p.pollFirst());
329 >                assertFalse(q.contains(x));
330              }
331          }
332      }
# Line 434 | Line 430 | public class ConcurrentSkipListSubSetTes
430       */
431      public void testIterator() {
432          NavigableSet q = populatedSet(SIZE);
437        int i = 0;
433          Iterator it = q.iterator();
434 <        while (it.hasNext()) {
434 >        int i;
435 >        for (i = 0; it.hasNext(); i++)
436              assertTrue(q.contains(it.next()));
441            ++i;
442        }
437          assertEquals(i, SIZE);
438 +        assertIteratorExhausted(it);
439      }
440  
441      /**
442       * iterator of empty set has no elements
443       */
444      public void testEmptyIterator() {
445 <        NavigableSet q = set0();
451 <        int i = 0;
452 <        Iterator it = q.iterator();
453 <        while (it.hasNext()) {
454 <            assertTrue(q.contains(it.next()));
455 <            ++i;
456 <        }
457 <        assertEquals(0, i);
445 >        assertIteratorExhausted(set0().iterator());
446      }
447  
448      /**
# Line 643 | Line 631 | public class ConcurrentSkipListSubSetTes
631       * add(null) throws NPE
632       */
633      public void testDescendingAddNull() {
634 +        NavigableSet q = dset0();
635          try {
647            NavigableSet q = dset0();
636              q.add(null);
637              shouldThrow();
638          } catch (NullPointerException success) {}
# Line 671 | Line 659 | public class ConcurrentSkipListSubSetTes
659       * Add of non-Comparable throws CCE
660       */
661      public void testDescendingAddNonComparable() {
662 +        NavigableSet q = dset0();
663          try {
675            NavigableSet q = dset0();
676            q.add(new Object());
664              q.add(new Object());
665              q.add(new Object());
666              shouldThrow();
# Line 684 | Line 671 | public class ConcurrentSkipListSubSetTes
671       * addAll(null) throws NPE
672       */
673      public void testDescendingAddAll1() {
674 +        NavigableSet q = dset0();
675          try {
688            NavigableSet q = dset0();
676              q.addAll(null);
677              shouldThrow();
678          } catch (NullPointerException success) {}
# Line 695 | Line 682 | public class ConcurrentSkipListSubSetTes
682       * addAll of a collection with null elements throws NPE
683       */
684      public void testDescendingAddAll2() {
685 +        NavigableSet q = dset0();
686 +        Integer[] ints = new Integer[SIZE];
687          try {
699            NavigableSet q = dset0();
700            Integer[] ints = new Integer[SIZE];
688              q.addAll(Arrays.asList(ints));
689              shouldThrow();
690          } catch (NullPointerException success) {}
# Line 708 | Line 695 | public class ConcurrentSkipListSubSetTes
695       * possibly adding some elements
696       */
697      public void testDescendingAddAll3() {
698 +        NavigableSet q = dset0();
699 +        Integer[] ints = new Integer[SIZE];
700 +        for (int i = 0; i < SIZE-1; ++i)
701 +            ints[i] = new Integer(i+SIZE);
702          try {
712            NavigableSet q = dset0();
713            Integer[] ints = new Integer[SIZE];
714            for (int i = 0; i < SIZE-1; ++i)
715                ints[i] = new Integer(i+SIZE);
703              q.addAll(Arrays.asList(ints));
704              shouldThrow();
705          } catch (NullPointerException success) {}
# Line 749 | Line 736 | public class ConcurrentSkipListSubSetTes
736       */
737      public void testDescendingRemoveElement() {
738          NavigableSet q = populatedSet(SIZE);
739 <        for (int i = 1; i < SIZE; i+=2) {
739 >        for (int i = 1; i < SIZE; i += 2) {
740              assertTrue(q.remove(new Integer(i)));
741          }
742 <        for (int i = 0; i < SIZE; i+=2) {
742 >        for (int i = 0; i < SIZE; i += 2 ) {
743              assertTrue(q.remove(new Integer(i)));
744              assertFalse(q.remove(new Integer(i+1)));
745          }
# Line 828 | Line 815 | public class ConcurrentSkipListSubSetTes
815              assertTrue(q.removeAll(p));
816              assertEquals(SIZE-i, q.size());
817              for (int j = 0; j < i; ++j) {
818 <                Integer I = (Integer)(p.pollFirst());
819 <                assertFalse(q.contains(I));
818 >                Integer x = (Integer)(p.pollFirst());
819 >                assertFalse(q.contains(x));
820              }
821          }
822      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines