--- jsr166/src/test/tck/ConcurrentSkipListSetTest.java 2010/08/25 00:07:03 1.13 +++ jsr166/src/test/tck/ConcurrentSkipListSetTest.java 2011/05/27 19:21:27 1.22 @@ -1,7 +1,7 @@ /* * 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.*; @@ -27,8 +27,9 @@ public class ConcurrentSkipListSetTest e * Create a 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))); @@ -203,6 +204,7 @@ public class ConcurrentSkipListSetTest e shouldThrow(); } catch (NullPointerException success) {} } + /** * addAll of a collection with null elements throws NPE */ @@ -214,6 +216,7 @@ public class ConcurrentSkipListSetTest e shouldThrow(); } catch (NullPointerException success) {} } + /** * addAll of a collection with any null elements throws NPE after * possibly adding some elements @@ -266,18 +269,23 @@ public class ConcurrentSkipListSetTest e 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))); + 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.remove(new Integer(i))); - assertFalse(q.remove(new Integer(i+1))); + 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()); } @@ -357,8 +365,6 @@ public class ConcurrentSkipListSetTest e } } - - /** * lower returns preceding element */ @@ -432,26 +438,25 @@ public class ConcurrentSkipListSetTest e } /** - * 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()); + 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); + ConcurrentSkipListSet q = populatedSet(SIZE); Integer[] ints = new Integer[SIZE]; - ints = (Integer[])q.toArray(ints); - Arrays.sort(ints); + Integer[] array = q.toArray(ints); + assertSame(ints, array); for (int i = 0; i < ints.length; i++) - assertEquals(ints[i], q.pollFirst()); + assertSame(ints[i], q.pollFirst()); } /** @@ -501,7 +506,6 @@ public class ConcurrentSkipListSetTest e assertFalse(it.hasNext()); } - /** * toString contains toStrings of elements */ @@ -509,7 +513,7 @@ 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))); } } @@ -657,7 +661,7 @@ public class ConcurrentSkipListSetTest e * Subsets of subsets subdivide correctly */ public void testRecursiveSubSets() throws Exception { - int setSize = 1000; + int setSize = expensiveTests ? 1000 : 100; Class cl = ConcurrentSkipListSet.class; NavigableSet set = newSet(cl); @@ -838,7 +842,7 @@ public class ConcurrentSkipListSetTest e */ void check(NavigableSet set, final int min, final int max, final boolean ascending) { - class ReferenceSet { + class ReferenceSet { int lower(int element) { return ascending ? lowerAscending(element) : higherAscending(element); @@ -873,7 +877,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;