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

Comparing jsr166/src/test/tck/ConcurrentSkipListSetTest.java (file contents):
Revision 1.13 by jsr166, Wed Aug 25 00:07:03 2010 UTC vs.
Revision 1.48 by jsr166, Fri Aug 4 04:59:23 2017 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.BitSet;
9 > import java.util.Collection;
10 > import java.util.Comparator;
11 > import java.util.Iterator;
12 > import java.util.NavigableSet;
13 > import java.util.NoSuchElementException;
14 > import java.util.Random;
15 > import java.util.Set;
16 > import java.util.SortedSet;
17 > import java.util.concurrent.ConcurrentSkipListSet;
18 >
19 > import junit.framework.Test;
20 > import junit.framework.TestSuite;
21  
22   public class ConcurrentSkipListSetTest extends JSR166TestCase {
23      public static void main(String[] args) {
24 <        junit.textui.TestRunner.run(suite());
24 >        main(suite(), args);
25      }
26      public static Test suite() {
27          return new TestSuite(ConcurrentSkipListSetTest.class);
# Line 24 | Line 34 | public class ConcurrentSkipListSetTest e
34      }
35  
36      /**
37 <     * Create a set of given size containing consecutive
38 <     * Integers 0 ... n.
37 >     * Returns a new set of given size containing consecutive
38 >     * Integers 0 ... n - 1.
39       */
40 <    private ConcurrentSkipListSet populatedSet(int n) {
41 <        ConcurrentSkipListSet q = new ConcurrentSkipListSet();
40 >    private static ConcurrentSkipListSet<Integer> populatedSet(int n) {
41 >        ConcurrentSkipListSet<Integer> q =
42 >            new ConcurrentSkipListSet<Integer>();
43          assertTrue(q.isEmpty());
44 <        for (int i = n-1; i >= 0; i-=2)
44 >        for (int i = n - 1; i >= 0; i -= 2)
45              assertTrue(q.add(new Integer(i)));
46 <        for (int i = (n & 1); i < n; i+=2)
46 >        for (int i = (n & 1); i < n; i += 2)
47              assertTrue(q.add(new Integer(i)));
48          assertFalse(q.isEmpty());
49          assertEquals(n, q.size());
# Line 40 | Line 51 | public class ConcurrentSkipListSetTest e
51      }
52  
53      /**
54 <     * Create set of first 5 ints
54 >     * Returns a new set of first 5 ints.
55       */
56 <    private ConcurrentSkipListSet set5() {
56 >    private static ConcurrentSkipListSet set5() {
57          ConcurrentSkipListSet q = new ConcurrentSkipListSet();
58          assertTrue(q.isEmpty());
59          q.add(one);
# Line 66 | Line 77 | public class ConcurrentSkipListSetTest e
77       */
78      public void testConstructor3() {
79          try {
80 <            ConcurrentSkipListSet q = new ConcurrentSkipListSet((Collection)null);
80 >            new ConcurrentSkipListSet((Collection)null);
81              shouldThrow();
82          } catch (NullPointerException success) {}
83      }
# Line 76 | Line 87 | public class ConcurrentSkipListSetTest e
87       */
88      public void testConstructor4() {
89          try {
90 <            Integer[] ints = new Integer[SIZE];
80 <            ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints));
90 >            new ConcurrentSkipListSet(Arrays.asList(new Integer[SIZE]));
91              shouldThrow();
92          } catch (NullPointerException success) {}
93      }
# Line 86 | Line 96 | public class ConcurrentSkipListSetTest e
96       * Initializing from Collection with some null elements throws NPE
97       */
98      public void testConstructor5() {
99 +        Integer[] ints = new Integer[SIZE];
100 +        for (int i = 0; i < SIZE - 1; ++i)
101 +            ints[i] = new Integer(i);
102          try {
103 <            Integer[] ints = new Integer[SIZE];
91 <            for (int i = 0; i < SIZE-1; ++i)
92 <                ints[i] = new Integer(i);
93 <            ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints));
103 >            new ConcurrentSkipListSet(Arrays.asList(ints));
104              shouldThrow();
105          } catch (NullPointerException success) {}
106      }
# Line 118 | Line 128 | public class ConcurrentSkipListSetTest e
128          for (int i = 0; i < SIZE; ++i)
129              ints[i] = new Integer(i);
130          q.addAll(Arrays.asList(ints));
131 <        for (int i = SIZE-1; i >= 0; --i)
131 >        for (int i = SIZE - 1; i >= 0; --i)
132              assertEquals(ints[i], q.pollFirst());
133      }
134  
# Line 142 | Line 152 | public class ConcurrentSkipListSetTest e
152      public void testSize() {
153          ConcurrentSkipListSet q = populatedSet(SIZE);
154          for (int i = 0; i < SIZE; ++i) {
155 <            assertEquals(SIZE-i, q.size());
155 >            assertEquals(SIZE - i, q.size());
156              q.pollFirst();
157          }
158          for (int i = 0; i < SIZE; ++i) {
# Line 155 | Line 165 | public class ConcurrentSkipListSetTest e
165       * add(null) throws NPE
166       */
167      public void testAddNull() {
168 +        ConcurrentSkipListSet q = new ConcurrentSkipListSet();
169          try {
159            ConcurrentSkipListSet q = new ConcurrentSkipListSet();
170              q.add(null);
171              shouldThrow();
172          } catch (NullPointerException success) {}
# Line 184 | Line 194 | public class ConcurrentSkipListSetTest e
194       * Add of non-Comparable throws CCE
195       */
196      public void testAddNonComparable() {
197 +        ConcurrentSkipListSet q = new ConcurrentSkipListSet();
198          try {
188            ConcurrentSkipListSet q = new ConcurrentSkipListSet();
189            q.add(new Object());
199              q.add(new Object());
200              q.add(new Object());
201              shouldThrow();
202 <        } catch (ClassCastException success) {}
202 >        } catch (ClassCastException success) {
203 >            assertTrue(q.size() < 2);
204 >            for (int i = 0, size = q.size(); i < size; i++)
205 >                assertSame(Object.class, q.pollFirst().getClass());
206 >            assertNull(q.pollFirst());
207 >            assertTrue(q.isEmpty());
208 >            assertEquals(0, q.size());
209 >        }
210      }
211  
212      /**
213       * addAll(null) throws NPE
214       */
215      public void testAddAll1() {
216 +        ConcurrentSkipListSet q = new ConcurrentSkipListSet();
217          try {
201            ConcurrentSkipListSet q = new ConcurrentSkipListSet();
218              q.addAll(null);
219              shouldThrow();
220          } catch (NullPointerException success) {}
221      }
222 +
223      /**
224       * addAll of a collection with null elements throws NPE
225       */
226      public void testAddAll2() {
227 +        ConcurrentSkipListSet q = new ConcurrentSkipListSet();
228 +        Integer[] ints = new Integer[SIZE];
229          try {
211            ConcurrentSkipListSet q = new ConcurrentSkipListSet();
212            Integer[] ints = new Integer[SIZE];
230              q.addAll(Arrays.asList(ints));
231              shouldThrow();
232          } catch (NullPointerException success) {}
233      }
234 +
235      /**
236       * addAll of a collection with any null elements throws NPE after
237       * possibly adding some elements
238       */
239      public void testAddAll3() {
240 +        ConcurrentSkipListSet q = new ConcurrentSkipListSet();
241 +        Integer[] ints = new Integer[SIZE];
242 +        for (int i = 0; i < SIZE - 1; ++i)
243 +            ints[i] = new Integer(i);
244          try {
223            ConcurrentSkipListSet q = new ConcurrentSkipListSet();
224            Integer[] ints = new Integer[SIZE];
225            for (int i = 0; i < SIZE-1; ++i)
226                ints[i] = new Integer(i);
245              q.addAll(Arrays.asList(ints));
246              shouldThrow();
247          } catch (NullPointerException success) {}
# Line 236 | Line 254 | public class ConcurrentSkipListSetTest e
254          Integer[] empty = new Integer[0];
255          Integer[] ints = new Integer[SIZE];
256          for (int i = 0; i < SIZE; ++i)
257 <            ints[i] = new Integer(SIZE-1-i);
257 >            ints[i] = new Integer(SIZE - 1 - i);
258          ConcurrentSkipListSet q = new ConcurrentSkipListSet();
259          assertFalse(q.addAll(Arrays.asList(empty)));
260          assertTrue(q.addAll(Arrays.asList(ints)));
# Line 260 | Line 278 | public class ConcurrentSkipListSetTest e
278       */
279      public void testPollLast() {
280          ConcurrentSkipListSet q = populatedSet(SIZE);
281 <        for (int i = SIZE-1; i >= 0; --i) {
281 >        for (int i = SIZE - 1; i >= 0; --i) {
282              assertEquals(i, q.pollLast());
283          }
284          assertNull(q.pollFirst());
285      }
286  
269
287      /**
288       * remove(x) removes x and returns true if present
289       */
290      public void testRemoveElement() {
291          ConcurrentSkipListSet q = populatedSet(SIZE);
292 <        for (int i = 1; i < SIZE; i+=2) {
293 <            assertTrue(q.remove(new Integer(i)));
294 <        }
295 <        for (int i = 0; i < SIZE; i+=2) {
296 <            assertTrue(q.remove(new Integer(i)));
297 <            assertFalse(q.remove(new Integer(i+1)));
292 >        for (int i = 1; i < SIZE; i += 2) {
293 >            assertTrue(q.contains(i));
294 >            assertTrue(q.remove(i));
295 >            assertFalse(q.contains(i));
296 >            assertTrue(q.contains(i - 1));
297 >        }
298 >        for (int i = 0; i < SIZE; i += 2) {
299 >            assertTrue(q.contains(i));
300 >            assertTrue(q.remove(i));
301 >            assertFalse(q.contains(i));
302 >            assertFalse(q.remove(i + 1));
303 >            assertFalse(q.contains(i + 1));
304          }
305          assertTrue(q.isEmpty());
306      }
# Line 336 | Line 359 | public class ConcurrentSkipListSetTest e
359                  assertTrue(changed);
360  
361              assertTrue(q.containsAll(p));
362 <            assertEquals(SIZE-i, q.size());
362 >            assertEquals(SIZE - i, q.size());
363              p.pollFirst();
364          }
365      }
# Line 349 | Line 372 | public class ConcurrentSkipListSetTest e
372              ConcurrentSkipListSet q = populatedSet(SIZE);
373              ConcurrentSkipListSet p = populatedSet(i);
374              assertTrue(q.removeAll(p));
375 <            assertEquals(SIZE-i, q.size());
375 >            assertEquals(SIZE - i, q.size());
376              for (int j = 0; j < i; ++j) {
377 <                Integer I = (Integer)(p.pollFirst());
378 <                assertFalse(q.contains(I));
377 >                Integer x = (Integer)(p.pollFirst());
378 >                assertFalse(q.contains(x));
379              }
380          }
381      }
382  
360
361
383      /**
384       * lower returns preceding element
385       */
# Line 432 | Line 453 | public class ConcurrentSkipListSetTest e
453      }
454  
455      /**
456 <     * toArray contains all elements
456 >     * toArray contains all elements in sorted order
457       */
458      public void testToArray() {
459          ConcurrentSkipListSet q = populatedSet(SIZE);
460          Object[] o = q.toArray();
440        Arrays.sort(o);
461          for (int i = 0; i < o.length; i++)
462 <            assertEquals(o[i], q.pollFirst());
462 >            assertSame(o[i], q.pollFirst());
463      }
464  
465      /**
466 <     * toArray(a) contains all elements
466 >     * toArray(a) contains all elements in sorted order
467       */
468      public void testToArray2() {
469 <        ConcurrentSkipListSet q = populatedSet(SIZE);
469 >        ConcurrentSkipListSet<Integer> q = populatedSet(SIZE);
470          Integer[] ints = new Integer[SIZE];
471 <        ints = (Integer[])q.toArray(ints);
452 <        Arrays.sort(ints);
471 >        assertSame(ints, q.toArray(ints));
472          for (int i = 0; i < ints.length; i++)
473 <            assertEquals(ints[i], q.pollFirst());
473 >            assertSame(ints[i], q.pollFirst());
474      }
475  
476      /**
# Line 459 | Line 478 | public class ConcurrentSkipListSetTest e
478       */
479      public void testIterator() {
480          ConcurrentSkipListSet q = populatedSet(SIZE);
462        int i = 0;
481          Iterator it = q.iterator();
482 <        while (it.hasNext()) {
482 >        int i;
483 >        for (i = 0; it.hasNext(); i++)
484              assertTrue(q.contains(it.next()));
466            ++i;
467        }
485          assertEquals(i, SIZE);
486 +        assertIteratorExhausted(it);
487      }
488  
489      /**
490       * iterator of empty set has no elements
491       */
492      public void testEmptyIterator() {
493 <        ConcurrentSkipListSet q = new ConcurrentSkipListSet();
494 <        int i = 0;
495 <        Iterator it = q.iterator();
478 <        while (it.hasNext()) {
479 <            assertTrue(q.contains(it.next()));
480 <            ++i;
481 <        }
482 <        assertEquals(i, 0);
493 >        NavigableSet s = new ConcurrentSkipListSet();
494 >        assertIteratorExhausted(s.iterator());
495 >        assertIteratorExhausted(s.descendingSet().iterator());
496      }
497  
498      /**
# Line 501 | Line 514 | public class ConcurrentSkipListSetTest e
514          assertFalse(it.hasNext());
515      }
516  
504
517      /**
518       * toString contains toStrings of elements
519       */
# Line 509 | Line 521 | public class ConcurrentSkipListSetTest e
521          ConcurrentSkipListSet q = populatedSet(SIZE);
522          String s = q.toString();
523          for (int i = 0; i < SIZE; ++i) {
524 <            assertTrue(s.indexOf(String.valueOf(i)) >= 0);
524 >            assertTrue(s.contains(String.valueOf(i)));
525 >        }
526 >    }
527 >
528 >    /**
529 >     * A cloned set equals original
530 >     */
531 >    public void testClone() {
532 >        ConcurrentSkipListSet x = populatedSet(SIZE);
533 >        ConcurrentSkipListSet y = x.clone();
534 >
535 >        assertNotSame(x, y);
536 >        assertEquals(x.size(), y.size());
537 >        assertEquals(x, y);
538 >        assertEquals(y, x);
539 >        while (!x.isEmpty()) {
540 >            assertFalse(y.isEmpty());
541 >            assertEquals(x.pollFirst(), y.pollFirst());
542          }
543 +        assertTrue(y.isEmpty());
544      }
545  
546      /**
547 <     * A deserialized serialized set has same elements
547 >     * A deserialized/reserialized set equals original
548       */
549      public void testSerialization() throws Exception {
550 <        ConcurrentSkipListSet q = populatedSet(SIZE);
551 <        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
552 <        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
553 <        out.writeObject(q);
554 <        out.close();
555 <
556 <        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
557 <        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
558 <        ConcurrentSkipListSet r = (ConcurrentSkipListSet)in.readObject();
559 <        assertEquals(q.size(), r.size());
560 <        while (!q.isEmpty())
561 <            assertEquals(q.pollFirst(), r.pollFirst());
550 >        NavigableSet x = populatedSet(SIZE);
551 >        NavigableSet y = serialClone(x);
552 >
553 >        assertNotSame(x, y);
554 >        assertEquals(x.size(), y.size());
555 >        assertEquals(x, y);
556 >        assertEquals(y, x);
557 >        while (!x.isEmpty()) {
558 >            assertFalse(y.isEmpty());
559 >            assertEquals(x.pollFirst(), y.pollFirst());
560 >        }
561 >        assertTrue(y.isEmpty());
562      }
563  
564      /**
# Line 651 | Line 681 | public class ConcurrentSkipListSetTest e
681      }
682  
683      Random rnd = new Random(666);
654    BitSet bs;
684  
685      /**
686       * Subsets of subsets subdivide correctly
687       */
688      public void testRecursiveSubSets() throws Exception {
689 <        int setSize = 1000;
689 >        int setSize = expensiveTests ? 1000 : 100;
690          Class cl = ConcurrentSkipListSet.class;
691  
692          NavigableSet<Integer> set = newSet(cl);
693 <        bs = new BitSet(setSize);
693 >        BitSet bs = new BitSet(setSize);
694  
695 <        populate(set, setSize);
696 <        check(set,                 0, setSize - 1, true);
697 <        check(set.descendingSet(), 0, setSize - 1, false);
698 <
699 <        mutateSet(set, 0, setSize - 1);
700 <        check(set,                 0, setSize - 1, true);
701 <        check(set.descendingSet(), 0, setSize - 1, false);
695 >        populate(set, setSize, bs);
696 >        check(set,                 0, setSize - 1, true, bs);
697 >        check(set.descendingSet(), 0, setSize - 1, false, bs);
698 >
699 >        mutateSet(set, 0, setSize - 1, bs);
700 >        check(set,                 0, setSize - 1, true, bs);
701 >        check(set.descendingSet(), 0, setSize - 1, false, bs);
702  
703          bashSubSet(set.subSet(0, true, setSize, false),
704 <                   0, setSize - 1, true);
704 >                   0, setSize - 1, true, bs);
705 >    }
706 >
707 >    /**
708 >     * addAll is idempotent
709 >     */
710 >    public void testAddAll_idempotent() throws Exception {
711 >        Set x = populatedSet(SIZE);
712 >        Set y = new ConcurrentSkipListSet(x);
713 >        y.addAll(x);
714 >        assertEquals(x, y);
715 >        assertEquals(y, x);
716      }
717  
718      static NavigableSet<Integer> newSet(Class cl) throws Exception {
719 <        NavigableSet<Integer> result = (NavigableSet<Integer>) cl.newInstance();
720 <        assertEquals(result.size(), 0);
719 >        NavigableSet<Integer> result =
720 >            (NavigableSet<Integer>) cl.getConstructor().newInstance();
721 >        assertEquals(0, result.size());
722          assertFalse(result.iterator().hasNext());
723          return result;
724      }
725  
726 <    void populate(NavigableSet<Integer> set, int limit) {
726 >    void populate(NavigableSet<Integer> set, int limit, BitSet bs) {
727          for (int i = 0, n = 2 * limit / 3; i < n; i++) {
728              int element = rnd.nextInt(limit);
729 <            put(set, element);
729 >            put(set, element, bs);
730          }
731      }
732  
733 <    void mutateSet(NavigableSet<Integer> set, int min, int max) {
733 >    void mutateSet(NavigableSet<Integer> set, int min, int max, BitSet bs) {
734          int size = set.size();
735          int rangeSize = max - min + 1;
736  
737          // Remove a bunch of entries directly
738          for (int i = 0, n = rangeSize / 2; i < n; i++) {
739 <            remove(set, min - 5 + rnd.nextInt(rangeSize + 10));
739 >            remove(set, min - 5 + rnd.nextInt(rangeSize + 10), bs);
740          }
741  
742          // Remove a bunch of entries with iterator
# Line 709 | Line 750 | public class ConcurrentSkipListSetTest e
750          // Add entries till we're back to original size
751          while (set.size() < size) {
752              int element = min + rnd.nextInt(rangeSize);
753 <            assertTrue(element >= min && element<= max);
754 <            put(set, element);
753 >            assertTrue(element >= min && element <= max);
754 >            put(set, element, bs);
755          }
756      }
757  
758 <    void mutateSubSet(NavigableSet<Integer> set, int min, int max) {
758 >    void mutateSubSet(NavigableSet<Integer> set, int min, int max,
759 >                      BitSet bs) {
760          int size = set.size();
761          int rangeSize = max - min + 1;
762  
763          // Remove a bunch of entries directly
764          for (int i = 0, n = rangeSize / 2; i < n; i++) {
765 <            remove(set, min - 5 + rnd.nextInt(rangeSize + 10));
765 >            remove(set, min - 5 + rnd.nextInt(rangeSize + 10), bs);
766          }
767  
768          // Remove a bunch of entries with iterator
# Line 734 | Line 776 | public class ConcurrentSkipListSetTest e
776          // Add entries till we're back to original size
777          while (set.size() < size) {
778              int element = min - 5 + rnd.nextInt(rangeSize + 10);
779 <            if (element >= min && element<= max) {
780 <                put(set, element);
779 >            if (element >= min && element <= max) {
780 >                put(set, element, bs);
781              } else {
782                  try {
783                      set.add(element);
# Line 745 | Line 787 | public class ConcurrentSkipListSetTest e
787          }
788      }
789  
790 <    void put(NavigableSet<Integer> set, int element) {
790 >    void put(NavigableSet<Integer> set, int element, BitSet bs) {
791          if (set.add(element))
792              bs.set(element);
793      }
794  
795 <    void remove(NavigableSet<Integer> set, int element) {
795 >    void remove(NavigableSet<Integer> set, int element, BitSet bs) {
796          if (set.remove(element))
797              bs.clear(element);
798      }
799  
800      void bashSubSet(NavigableSet<Integer> set,
801 <                    int min, int max, boolean ascending) {
802 <        check(set, min, max, ascending);
803 <        check(set.descendingSet(), min, max, !ascending);
804 <
805 <        mutateSubSet(set, min, max);
806 <        check(set, min, max, ascending);
807 <        check(set.descendingSet(), min, max, !ascending);
801 >                    int min, int max, boolean ascending,
802 >                    BitSet bs) {
803 >        check(set, min, max, ascending, bs);
804 >        check(set.descendingSet(), min, max, !ascending, bs);
805 >
806 >        mutateSubSet(set, min, max, bs);
807 >        check(set, min, max, ascending, bs);
808 >        check(set.descendingSet(), min, max, !ascending, bs);
809  
810          // Recurse
811          if (max - min < 2)
# Line 774 | Line 817 | public class ConcurrentSkipListSetTest e
817          NavigableSet<Integer> hm = set.headSet(midPoint, incl);
818          if (ascending) {
819              if (rnd.nextBoolean())
820 <                bashSubSet(hm, min, midPoint - (incl ? 0 : 1), true);
820 >                bashSubSet(hm, min, midPoint - (incl ? 0 : 1), true, bs);
821              else
822                  bashSubSet(hm.descendingSet(), min, midPoint - (incl ? 0 : 1),
823 <                           false);
823 >                           false, bs);
824          } else {
825              if (rnd.nextBoolean())
826 <                bashSubSet(hm, midPoint + (incl ? 0 : 1), max, false);
826 >                bashSubSet(hm, midPoint + (incl ? 0 : 1), max, false, bs);
827              else
828                  bashSubSet(hm.descendingSet(), midPoint + (incl ? 0 : 1), max,
829 <                           true);
829 >                           true, bs);
830          }
831  
832          // tailSet - pick direction and endpoint inclusion randomly
# Line 791 | Line 834 | public class ConcurrentSkipListSetTest e
834          NavigableSet<Integer> tm = set.tailSet(midPoint,incl);
835          if (ascending) {
836              if (rnd.nextBoolean())
837 <                bashSubSet(tm, midPoint + (incl ? 0 : 1), max, true);
837 >                bashSubSet(tm, midPoint + (incl ? 0 : 1), max, true, bs);
838              else
839                  bashSubSet(tm.descendingSet(), midPoint + (incl ? 0 : 1), max,
840 <                           false);
840 >                           false, bs);
841          } else {
842              if (rnd.nextBoolean()) {
843 <                bashSubSet(tm, min, midPoint - (incl ? 0 : 1), false);
843 >                bashSubSet(tm, min, midPoint - (incl ? 0 : 1), false, bs);
844              } else {
845                  bashSubSet(tm.descendingSet(), min, midPoint - (incl ? 0 : 1),
846 <                           true);
846 >                           true, bs);
847              }
848          }
849  
# Line 817 | Line 860 | public class ConcurrentSkipListSetTest e
860                  endpoints[0], lowIncl, endpoints[1], highIncl);
861              if (rnd.nextBoolean())
862                  bashSubSet(sm, endpoints[0] + (lowIncl ? 0 : 1),
863 <                           endpoints[1] - (highIncl ? 0 : 1), true);
863 >                           endpoints[1] - (highIncl ? 0 : 1), true, bs);
864              else
865                  bashSubSet(sm.descendingSet(), endpoints[0] + (lowIncl ? 0 : 1),
866 <                           endpoints[1] - (highIncl ? 0 : 1), false);
866 >                           endpoints[1] - (highIncl ? 0 : 1), false, bs);
867          } else {
868              NavigableSet<Integer> sm = set.subSet(
869                  endpoints[1], highIncl, endpoints[0], lowIncl);
870              if (rnd.nextBoolean())
871                  bashSubSet(sm, endpoints[0] + (lowIncl ? 0 : 1),
872 <                           endpoints[1] - (highIncl ? 0 : 1), false);
872 >                           endpoints[1] - (highIncl ? 0 : 1), false, bs);
873              else
874                  bashSubSet(sm.descendingSet(), endpoints[0] + (lowIncl ? 0 : 1),
875 <                           endpoints[1] - (highIncl ? 0 : 1), true);
875 >                           endpoints[1] - (highIncl ? 0 : 1), true, bs);
876          }
877      }
878  
# Line 837 | Line 880 | public class ConcurrentSkipListSetTest e
880       * min and max are both inclusive.  If max < min, interval is empty.
881       */
882      void check(NavigableSet<Integer> set,
883 <                      final int min, final int max, final boolean ascending) {
884 <       class ReferenceSet {
883 >               final int min, final int max, final boolean ascending,
884 >               final BitSet bs) {
885 >        class ReferenceSet {
886              int lower(int element) {
887                  return ascending ?
888                      lowerAscending(element) : higherAscending(element);
# Line 873 | Line 917 | public class ConcurrentSkipListSetTest e
917                  // BitSet should support this! Test would run much faster
918                  while (element >= min) {
919                      if (bs.get(element))
920 <                        return(element);
920 >                        return element;
921                      element--;
922                  }
923                  return -1;
# Line 908 | Line 952 | public class ConcurrentSkipListSetTest e
952              if (bsContainsI)
953                  size++;
954          }
955 <        assertEquals(set.size(), size);
955 >        assertEquals(size, set.size());
956  
957          // Test contents using contains elementSet iterator
958          int size2 = 0;
# Line 956 | Line 1000 | public class ConcurrentSkipListSetTest e
1000      }
1001  
1002      static boolean eq(Integer i, int j) {
1003 <        return i == null ? j == -1 : i == j;
1003 >        return (i == null) ? j == -1 : i == j;
1004      }
1005  
1006   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines