--- jsr166/src/test/tck/ConcurrentSkipListSetTest.java 2009/11/02 20:28:31 1.4 +++ jsr166/src/test/tck/ConcurrentSkipListSetTest.java 2015/05/24 01:42:14 1.42 @@ -1,50 +1,57 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain + * http://creativecommons.org/publicdomain/zero/1.0/ */ -import junit.framework.*; -import java.util.*; -import java.util.concurrent.*; -import java.io.*; +import java.util.Arrays; +import java.util.BitSet; +import java.util.Collection; +import java.util.Comparator; +import java.util.Iterator; +import java.util.NavigableSet; +import java.util.NoSuchElementException; +import java.util.Random; +import java.util.Set; +import java.util.SortedSet; +import java.util.concurrent.ConcurrentSkipListSet; + +import junit.framework.Test; +import junit.framework.TestSuite; public class ConcurrentSkipListSetTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run (suite()); + main(suite(), args); } public static Test suite() { - return new TestSuite(ConcurrentSkipListSetTest.class); + return new TestSuite(ConcurrentSkipListSetTest.class); } static class MyReverseComparator implements Comparator { public int compare(Object x, Object y) { - int i = ((Integer)x).intValue(); - int j = ((Integer)y).intValue(); - if (i < j) return 1; - if (i > j) return -1; - return 0; + return ((Comparable)y).compareTo(x); } } /** - * Create a set of given size containing consecutive + * Returns a new set of given size containing consecutive * Integers 0 ... n. */ - private ConcurrentSkipListSet populatedSet(int n) { - ConcurrentSkipListSet q = new ConcurrentSkipListSet(); + private ConcurrentSkipListSet populatedSet(int n) { + ConcurrentSkipListSet q = + new ConcurrentSkipListSet(); assertTrue(q.isEmpty()); - for(int i = n-1; i >= 0; i-=2) - assertTrue(q.add(new Integer(i))); - for(int i = (n & 1); i < n; i+=2) - assertTrue(q.add(new Integer(i))); + for (int i = n - 1; i >= 0; i -= 2) + assertTrue(q.add(new Integer(i))); + for (int i = (n & 1); i < n; i += 2) + assertTrue(q.add(new Integer(i))); assertFalse(q.isEmpty()); - assertEquals(n, q.size()); + assertEquals(n, q.size()); return q; } /** - * Create set of first 5 ints + * Returns a new set of first 5 ints. */ private ConcurrentSkipListSet set5() { ConcurrentSkipListSet q = new ConcurrentSkipListSet(); @@ -54,7 +61,7 @@ public class ConcurrentSkipListSetTest e q.add(three); q.add(four); q.add(five); - assertEquals(5, q.size()); + assertEquals(5, q.size()); return q; } @@ -70,10 +77,9 @@ public class ConcurrentSkipListSetTest e */ public void testConstructor3() { try { - ConcurrentSkipListSet q = new ConcurrentSkipListSet((Collection)null); + new ConcurrentSkipListSet((Collection)null); shouldThrow(); - } - catch (NullPointerException success) {} + } catch (NullPointerException success) {} } /** @@ -81,58 +87,49 @@ public class ConcurrentSkipListSetTest e */ public void testConstructor4() { try { - Integer[] ints = new Integer[SIZE]; - ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints)); + new ConcurrentSkipListSet(Arrays.asList(new Integer[SIZE])); shouldThrow(); - } - catch (NullPointerException success) {} + } catch (NullPointerException success) {} } /** * Initializing from Collection with some null elements throws NPE */ public void testConstructor5() { + Integer[] ints = new Integer[SIZE]; + for (int i = 0; i < SIZE - 1; ++i) + ints[i] = new Integer(i); try { - Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE-1; ++i) - ints[i] = new Integer(i); - ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints)); + new ConcurrentSkipListSet(Arrays.asList(ints)); shouldThrow(); - } - catch (NullPointerException success) {} + } catch (NullPointerException success) {} } /** * Set contains all elements of collection used to initialize */ public void testConstructor6() { - try { - Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE; ++i) - ints[i] = new Integer(i); - ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints)); - for (int i = 0; i < SIZE; ++i) - assertEquals(ints[i], q.pollFirst()); - } - finally {} + Integer[] ints = new Integer[SIZE]; + for (int i = 0; i < SIZE; ++i) + ints[i] = new Integer(i); + ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints)); + for (int i = 0; i < SIZE; ++i) + assertEquals(ints[i], q.pollFirst()); } /** * The comparator used in constructor is used */ public void testConstructor7() { - try { - MyReverseComparator cmp = new MyReverseComparator(); - ConcurrentSkipListSet q = new ConcurrentSkipListSet(cmp); - assertEquals(cmp, q.comparator()); - Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE; ++i) - ints[i] = new Integer(i); - q.addAll(Arrays.asList(ints)); - for (int i = SIZE-1; i >= 0; --i) - assertEquals(ints[i], q.pollFirst()); - } - finally {} + MyReverseComparator cmp = new MyReverseComparator(); + ConcurrentSkipListSet q = new ConcurrentSkipListSet(cmp); + assertEquals(cmp, q.comparator()); + Integer[] ints = new Integer[SIZE]; + for (int i = 0; i < SIZE; ++i) + ints[i] = new Integer(i); + q.addAll(Arrays.asList(ints)); + for (int i = SIZE - 1; i >= 0; --i) + assertEquals(ints[i], q.pollFirst()); } /** @@ -155,7 +152,7 @@ public class ConcurrentSkipListSetTest e public void testSize() { ConcurrentSkipListSet q = populatedSet(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(SIZE-i, q.size()); + assertEquals(SIZE - i, q.size()); q.pollFirst(); } for (int i = 0; i < SIZE; ++i) { @@ -168,11 +165,11 @@ public class ConcurrentSkipListSetTest e * add(null) throws NPE */ public void testAddNull() { - try { - ConcurrentSkipListSet q = new ConcurrentSkipListSet(); + ConcurrentSkipListSet q = new ConcurrentSkipListSet(); + try { q.add(null); shouldThrow(); - } catch (NullPointerException success) { } + } catch (NullPointerException success) {} } /** @@ -197,71 +194,65 @@ public class ConcurrentSkipListSetTest e * Add of non-Comparable throws CCE */ public void testAddNonComparable() { + ConcurrentSkipListSet q = new ConcurrentSkipListSet(); try { - ConcurrentSkipListSet q = new ConcurrentSkipListSet(); - q.add(new Object()); q.add(new Object()); q.add(new Object()); shouldThrow(); - } - catch(ClassCastException success) {} + } catch (ClassCastException success) {} } /** * addAll(null) throws NPE */ public void testAddAll1() { + ConcurrentSkipListSet q = new ConcurrentSkipListSet(); try { - ConcurrentSkipListSet q = new ConcurrentSkipListSet(); q.addAll(null); shouldThrow(); - } - catch (NullPointerException success) {} + } catch (NullPointerException success) {} } + /** * addAll of a collection with null elements throws NPE */ public void testAddAll2() { + ConcurrentSkipListSet q = new ConcurrentSkipListSet(); + Integer[] ints = new Integer[SIZE]; try { - ConcurrentSkipListSet q = new ConcurrentSkipListSet(); - Integer[] ints = new Integer[SIZE]; q.addAll(Arrays.asList(ints)); shouldThrow(); - } - catch (NullPointerException success) {} + } catch (NullPointerException success) {} } + /** * addAll of a collection with any null elements throws NPE after * possibly adding some elements */ public void testAddAll3() { + ConcurrentSkipListSet q = new ConcurrentSkipListSet(); + Integer[] ints = new Integer[SIZE]; + for (int i = 0; i < SIZE - 1; ++i) + ints[i] = new Integer(i); try { - ConcurrentSkipListSet q = new ConcurrentSkipListSet(); - Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE-1; ++i) - ints[i] = new Integer(i); q.addAll(Arrays.asList(ints)); shouldThrow(); - } - catch (NullPointerException success) {} + } catch (NullPointerException success) {} } /** * Set contains all elements of successful addAll */ public void testAddAll5() { - try { - Integer[] empty = new Integer[0]; - Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE; ++i) - ints[i] = new Integer(SIZE-1-i); - ConcurrentSkipListSet q = new ConcurrentSkipListSet(); - assertFalse(q.addAll(Arrays.asList(empty))); - assertTrue(q.addAll(Arrays.asList(ints))); - for (int i = 0; i < SIZE; ++i) - assertEquals(new Integer(i), q.pollFirst()); - } - finally {} + Integer[] empty = new Integer[0]; + Integer[] ints = new Integer[SIZE]; + for (int i = 0; i < SIZE; ++i) + ints[i] = new Integer(SIZE - 1 - i); + ConcurrentSkipListSet q = new ConcurrentSkipListSet(); + assertFalse(q.addAll(Arrays.asList(empty))); + assertTrue(q.addAll(Arrays.asList(ints))); + for (int i = 0; i < SIZE; ++i) + assertEquals(i, q.pollFirst()); } /** @@ -270,9 +261,9 @@ public class ConcurrentSkipListSetTest e public void testPollFirst() { ConcurrentSkipListSet q = populatedSet(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.pollFirst()).intValue()); + assertEquals(i, q.pollFirst()); } - assertNull(q.pollFirst()); + assertNull(q.pollFirst()); } /** @@ -280,24 +271,29 @@ public class ConcurrentSkipListSetTest e */ public void testPollLast() { ConcurrentSkipListSet q = populatedSet(SIZE); - for (int i = SIZE-1; i >= 0; --i) { - assertEquals(i, ((Integer)q.pollLast()).intValue()); + for (int i = SIZE - 1; i >= 0; --i) { + assertEquals(i, q.pollLast()); } - assertNull(q.pollFirst()); + assertNull(q.pollFirst()); } - /** * remove(x) removes x and returns true if present */ public void testRemoveElement() { ConcurrentSkipListSet q = populatedSet(SIZE); - for (int i = 1; i < SIZE; i+=2) { - assertTrue(q.remove(new Integer(i))); - } - for (int i = 0; i < SIZE; i+=2) { - assertTrue(q.remove(new Integer(i))); - assertFalse(q.remove(new Integer(i+1))); + for (int i = 1; i < SIZE; i += 2) { + assertTrue(q.contains(i)); + assertTrue(q.remove(i)); + assertFalse(q.contains(i)); + assertTrue(q.contains(i - 1)); + } + for (int i = 0; i < SIZE; i += 2) { + assertTrue(q.contains(i)); + assertTrue(q.remove(i)); + assertFalse(q.contains(i)); + assertFalse(q.remove(i + 1)); + assertFalse(q.contains(i + 1)); } assertTrue(q.isEmpty()); } @@ -356,7 +352,7 @@ public class ConcurrentSkipListSetTest e assertTrue(changed); assertTrue(q.containsAll(p)); - assertEquals(SIZE-i, q.size()); + assertEquals(SIZE - i, q.size()); p.pollFirst(); } } @@ -369,16 +365,14 @@ public class ConcurrentSkipListSetTest e ConcurrentSkipListSet q = populatedSet(SIZE); ConcurrentSkipListSet p = populatedSet(i); assertTrue(q.removeAll(p)); - assertEquals(SIZE-i, q.size()); + assertEquals(SIZE - i, q.size()); for (int j = 0; j < i; ++j) { - Integer I = (Integer)(p.pollFirst()); - assertFalse(q.contains(I)); + Integer x = (Integer)(p.pollFirst()); + assertFalse(q.contains(x)); } } } - - /** * lower returns preceding element */ @@ -395,7 +389,6 @@ public class ConcurrentSkipListSetTest e Object e4 = q.lower(zero); assertNull(e4); - } /** @@ -414,7 +407,6 @@ public class ConcurrentSkipListSetTest e Object e4 = q.higher(six); assertNull(e4); - } /** @@ -433,7 +425,6 @@ public class ConcurrentSkipListSetTest e Object e4 = q.floor(zero); assertNull(e4); - } /** @@ -452,30 +443,27 @@ public class ConcurrentSkipListSetTest e Object e4 = q.ceiling(six); assertNull(e4); - } /** - * toArray contains all elements + * toArray contains all elements in sorted order */ public void testToArray() { ConcurrentSkipListSet q = populatedSet(SIZE); - Object[] o = q.toArray(); - Arrays.sort(o); - for(int i = 0; i < o.length; i++) - assertEquals(o[i], q.pollFirst()); + Object[] o = q.toArray(); + for (int i = 0; i < o.length; i++) + assertSame(o[i], q.pollFirst()); } /** - * toArray(a) contains all elements + * toArray(a) contains all elements in sorted order */ public void testToArray2() { - ConcurrentSkipListSet q = populatedSet(SIZE); - Integer[] ints = new Integer[SIZE]; - ints = (Integer[])q.toArray(ints); - Arrays.sort(ints); - for(int i = 0; i < ints.length; i++) - assertEquals(ints[i], q.pollFirst()); + ConcurrentSkipListSet q = populatedSet(SIZE); + Integer[] ints = new Integer[SIZE]; + assertSame(ints, q.toArray(ints)); + for (int i = 0; i < ints.length; i++) + assertSame(ints[i], q.pollFirst()); } /** @@ -483,33 +471,27 @@ public class ConcurrentSkipListSetTest e */ public void testIterator() { ConcurrentSkipListSet q = populatedSet(SIZE); - int i = 0; - Iterator it = q.iterator(); - while(it.hasNext()) { + Iterator it = q.iterator(); + int i; + for (i = 0; it.hasNext(); i++) assertTrue(q.contains(it.next())); - ++i; - } assertEquals(i, SIZE); + assertIteratorExhausted(it); } /** * iterator of empty set has no elements */ public void testEmptyIterator() { - ConcurrentSkipListSet q = new ConcurrentSkipListSet(); - int i = 0; - Iterator it = q.iterator(); - while(it.hasNext()) { - assertTrue(q.contains(it.next())); - ++i; - } - assertEquals(i, 0); + NavigableSet s = new ConcurrentSkipListSet(); + assertIteratorExhausted(s.iterator()); + assertIteratorExhausted(s.descendingSet().iterator()); } /** * iterator.remove removes current element */ - public void testIteratorRemove () { + public void testIteratorRemove() { final ConcurrentSkipListSet q = new ConcurrentSkipListSet(); q.add(new Integer(2)); q.add(new Integer(1)); @@ -525,7 +507,6 @@ public class ConcurrentSkipListSetTest e assertFalse(it.hasNext()); } - /** * toString contains toStrings of elements */ @@ -533,31 +514,26 @@ public class ConcurrentSkipListSetTest e ConcurrentSkipListSet q = populatedSet(SIZE); String s = q.toString(); for (int i = 0; i < SIZE; ++i) { - assertTrue(s.indexOf(String.valueOf(i)) >= 0); + assertTrue(s.contains(String.valueOf(i))); } } /** * A deserialized serialized set has same elements */ - public void testSerialization() { - ConcurrentSkipListSet q = populatedSet(SIZE); - try { - ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); - ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); - out.writeObject(q); - out.close(); - - ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); - ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); - ConcurrentSkipListSet r = (ConcurrentSkipListSet)in.readObject(); - assertEquals(q.size(), r.size()); - while (!q.isEmpty()) - assertEquals(q.pollFirst(), r.pollFirst()); - } catch(Exception e){ - e.printStackTrace(); - unexpectedException(); + public void testSerialization() throws Exception { + NavigableSet x = populatedSet(SIZE); + NavigableSet y = serialClone(x); + + assertNotSame(x, y); + assertEquals(x.size(), y.size()); + assertEquals(x, y); + assertEquals(y, x); + while (!x.isEmpty()) { + assertFalse(y.isEmpty()); + assertEquals(x.pollFirst(), y.pollFirst()); } + assertTrue(y.isEmpty()); } /** @@ -680,60 +656,65 @@ public class ConcurrentSkipListSetTest e } Random rnd = new Random(666); - BitSet bs; /** * Subsets of subsets subdivide correctly */ - public void testRecursiveSubSets() { - int setSize = 1000; - Class cl = ConcurrentSkipListSet.class; + public void testRecursiveSubSets() throws Exception { + int setSize = expensiveTests ? 1000 : 100; + Class cl = ConcurrentSkipListSet.class; NavigableSet set = newSet(cl); - bs = new BitSet(setSize); + BitSet bs = new BitSet(setSize); - populate(set, setSize); - check(set, 0, setSize - 1, true); - check(set.descendingSet(), 0, setSize - 1, false); - - mutateSet(set, 0, setSize - 1); - check(set, 0, setSize - 1, true); - check(set.descendingSet(), 0, setSize - 1, false); + populate(set, setSize, bs); + check(set, 0, setSize - 1, true, bs); + check(set.descendingSet(), 0, setSize - 1, false, bs); + + mutateSet(set, 0, setSize - 1, bs); + check(set, 0, setSize - 1, true, bs); + check(set.descendingSet(), 0, setSize - 1, false, bs); bashSubSet(set.subSet(0, true, setSize, false), - 0, setSize - 1, true); + 0, setSize - 1, true, bs); } - static NavigableSet newSet(Class cl) { - NavigableSet result = null; - try { - result = (NavigableSet) cl.newInstance(); - } catch(Exception e) { - fail(); - } - assertEquals(result.size(), 0); + /** + * addAll is idempotent + */ + public void testAddAll_idempotent() throws Exception { + Set x = populatedSet(SIZE); + Set y = new ConcurrentSkipListSet(x); + y.addAll(x); + assertEquals(x, y); + assertEquals(y, x); + } + + static NavigableSet newSet(Class cl) throws Exception { + NavigableSet result = (NavigableSet) cl.newInstance(); + assertEquals(0, result.size()); assertFalse(result.iterator().hasNext()); return result; } - void populate(NavigableSet set, int limit) { + void populate(NavigableSet set, int limit, BitSet bs) { for (int i = 0, n = 2 * limit / 3; i < n; i++) { int element = rnd.nextInt(limit); - put(set, element); + put(set, element, bs); } } - void mutateSet(NavigableSet set, int min, int max) { + void mutateSet(NavigableSet set, int min, int max, BitSet bs) { int size = set.size(); int rangeSize = max - min + 1; // Remove a bunch of entries directly for (int i = 0, n = rangeSize / 2; i < n; i++) { - remove(set, min - 5 + rnd.nextInt(rangeSize + 10)); + remove(set, min - 5 + rnd.nextInt(rangeSize + 10), bs); } // Remove a bunch of entries with iterator - for(Iterator it = set.iterator(); it.hasNext(); ) { + for (Iterator it = set.iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { bs.clear(it.next()); it.remove(); @@ -743,22 +724,23 @@ public class ConcurrentSkipListSetTest e // Add entries till we're back to original size while (set.size() < size) { int element = min + rnd.nextInt(rangeSize); - assertTrue(element >= min && element<= max); - put(set, element); + assertTrue(element >= min && element <= max); + put(set, element, bs); } } - void mutateSubSet(NavigableSet set, int min, int max) { + void mutateSubSet(NavigableSet set, int min, int max, + BitSet bs) { int size = set.size(); int rangeSize = max - min + 1; // Remove a bunch of entries directly for (int i = 0, n = rangeSize / 2; i < n; i++) { - remove(set, min - 5 + rnd.nextInt(rangeSize + 10)); + remove(set, min - 5 + rnd.nextInt(rangeSize + 10), bs); } // Remove a bunch of entries with iterator - for(Iterator it = set.iterator(); it.hasNext(); ) { + for (Iterator it = set.iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { bs.clear(it.next()); it.remove(); @@ -768,37 +750,36 @@ public class ConcurrentSkipListSetTest e // Add entries till we're back to original size while (set.size() < size) { int element = min - 5 + rnd.nextInt(rangeSize + 10); - if (element >= min && element<= max) { - put(set, element); + if (element >= min && element <= max) { + put(set, element, bs); } else { try { set.add(element); - fail(); - } catch(IllegalArgumentException e) { - // expected - } + shouldThrow(); + } catch (IllegalArgumentException success) {} } } } - void put(NavigableSet set, int element) { + void put(NavigableSet set, int element, BitSet bs) { if (set.add(element)) bs.set(element); } - void remove(NavigableSet set, int element) { + void remove(NavigableSet set, int element, BitSet bs) { if (set.remove(element)) bs.clear(element); } void bashSubSet(NavigableSet set, - int min, int max, boolean ascending) { - check(set, min, max, ascending); - check(set.descendingSet(), min, max, !ascending); - - mutateSubSet(set, min, max); - check(set, min, max, ascending); - check(set.descendingSet(), min, max, !ascending); + int min, int max, boolean ascending, + BitSet bs) { + check(set, min, max, ascending, bs); + check(set.descendingSet(), min, max, !ascending, bs); + + mutateSubSet(set, min, max, bs); + check(set, min, max, ascending, bs); + check(set.descendingSet(), min, max, !ascending, bs); // Recurse if (max - min < 2) @@ -810,16 +791,16 @@ public class ConcurrentSkipListSetTest e NavigableSet hm = set.headSet(midPoint, incl); if (ascending) { if (rnd.nextBoolean()) - bashSubSet(hm, min, midPoint - (incl ? 0 : 1), true); + bashSubSet(hm, min, midPoint - (incl ? 0 : 1), true, bs); else bashSubSet(hm.descendingSet(), min, midPoint - (incl ? 0 : 1), - false); + false, bs); } else { if (rnd.nextBoolean()) - bashSubSet(hm, midPoint + (incl ? 0 : 1), max, false); + bashSubSet(hm, midPoint + (incl ? 0 : 1), max, false, bs); else bashSubSet(hm.descendingSet(), midPoint + (incl ? 0 : 1), max, - true); + true, bs); } // tailSet - pick direction and endpoint inclusion randomly @@ -827,16 +808,16 @@ public class ConcurrentSkipListSetTest e NavigableSet tm = set.tailSet(midPoint,incl); if (ascending) { if (rnd.nextBoolean()) - bashSubSet(tm, midPoint + (incl ? 0 : 1), max, true); + bashSubSet(tm, midPoint + (incl ? 0 : 1), max, true, bs); else bashSubSet(tm.descendingSet(), midPoint + (incl ? 0 : 1), max, - false); + false, bs); } else { if (rnd.nextBoolean()) { - bashSubSet(tm, min, midPoint - (incl ? 0 : 1), false); + bashSubSet(tm, min, midPoint - (incl ? 0 : 1), false, bs); } else { bashSubSet(tm.descendingSet(), min, midPoint - (incl ? 0 : 1), - true); + true, bs); } } @@ -853,19 +834,19 @@ public class ConcurrentSkipListSetTest e endpoints[0], lowIncl, endpoints[1], highIncl); if (rnd.nextBoolean()) bashSubSet(sm, endpoints[0] + (lowIncl ? 0 : 1), - endpoints[1] - (highIncl ? 0 : 1), true); + endpoints[1] - (highIncl ? 0 : 1), true, bs); else bashSubSet(sm.descendingSet(), endpoints[0] + (lowIncl ? 0 : 1), - endpoints[1] - (highIncl ? 0 : 1), false); + endpoints[1] - (highIncl ? 0 : 1), false, bs); } else { NavigableSet sm = set.subSet( endpoints[1], highIncl, endpoints[0], lowIncl); if (rnd.nextBoolean()) bashSubSet(sm, endpoints[0] + (lowIncl ? 0 : 1), - endpoints[1] - (highIncl ? 0 : 1), false); + endpoints[1] - (highIncl ? 0 : 1), false, bs); else bashSubSet(sm.descendingSet(), endpoints[0] + (lowIncl ? 0 : 1), - endpoints[1] - (highIncl ? 0 : 1), true); + endpoints[1] - (highIncl ? 0 : 1), true, bs); } } @@ -873,8 +854,9 @@ public class ConcurrentSkipListSetTest e * min and max are both inclusive. If max < min, interval is empty. */ void check(NavigableSet set, - final int min, final int max, final boolean ascending) { - class ReferenceSet { + final int min, final int max, final boolean ascending, + final BitSet bs) { + class ReferenceSet { int lower(int element) { return ascending ? lowerAscending(element) : higherAscending(element); @@ -909,7 +891,7 @@ public class ConcurrentSkipListSetTest e // BitSet should support this! Test would run much faster while (element >= min) { if (bs.get(element)) - return(element); + return element; element--; } return -1; @@ -944,7 +926,7 @@ public class ConcurrentSkipListSetTest e if (bsContainsI) size++; } - assertEquals(set.size(), size); + assertEquals(size, set.size()); // Test contents using contains elementSet iterator int size2 = 0; @@ -975,16 +957,12 @@ public class ConcurrentSkipListSetTest e assertEq(rs.last(), -1); try { set.first(); - fail(); - } catch(NoSuchElementException e) { - // expected - } + shouldThrow(); + } catch (NoSuchElementException success) {} try { set.last(); - fail(); - } catch(NoSuchElementException e) { - // expected - } + shouldThrow(); + } catch (NoSuchElementException success) {} } } @@ -996,7 +974,7 @@ public class ConcurrentSkipListSetTest e } static boolean eq(Integer i, int j) { - return i == null ? j == -1 : i == j; + return (i == null) ? j == -1 : i == j; } }