--- jsr166/src/test/tck/ConcurrentSkipListSubSetTest.java 2009/11/21 10:29:50 1.10 +++ jsr166/src/test/tck/ConcurrentSkipListSubSetTest.java 2011/03/15 19:47:06 1.18 @@ -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.*; @@ -11,7 +11,7 @@ import java.io.*; public class ConcurrentSkipListSubSetTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run (suite()); + junit.textui.TestRunner.run(suite()); } public static Test suite() { return new TestSuite(ConcurrentSkipListSubSetTest.class); @@ -19,11 +19,7 @@ public class ConcurrentSkipListSubSetTes 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); } } @@ -31,8 +27,9 @@ public class ConcurrentSkipListSubSetTes * Create a set of given size containing consecutive * Integers 0 ... n. */ - private NavigableSet populatedSet(int n) { - ConcurrentSkipListSet q = new ConcurrentSkipListSet(); + private NavigableSet populatedSet(int n) { + ConcurrentSkipListSet q = + new ConcurrentSkipListSet(); assertTrue(q.isEmpty()); for (int i = n-1; i >= 0; i-=2) @@ -182,6 +179,7 @@ public class ConcurrentSkipListSubSetTes shouldThrow(); } catch (NullPointerException success) {} } + /** * addAll of a collection with null elements throws NPE */ @@ -193,6 +191,7 @@ public class ConcurrentSkipListSubSetTes shouldThrow(); } catch (NullPointerException success) {} } + /** * addAll of a collection with any null elements throws NPE after * possibly adding some elements @@ -229,7 +228,7 @@ public class ConcurrentSkipListSubSetTes public void testPoll() { NavigableSet q = populatedSet(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.pollFirst()).intValue()); + assertEquals(i, q.pollFirst()); } assertNull(q.pollFirst()); } @@ -240,11 +239,17 @@ public class ConcurrentSkipListSubSetTes public void testRemoveElement() { NavigableSet 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()); } @@ -342,7 +347,6 @@ public class ConcurrentSkipListSubSetTes Object e4 = q.lower(zero); assertNull(e4); - } /** @@ -361,7 +365,6 @@ public class ConcurrentSkipListSubSetTes Object e4 = q.higher(six); assertNull(e4); - } /** @@ -380,7 +383,6 @@ public class ConcurrentSkipListSubSetTes Object e4 = q.floor(zero); assertNull(e4); - } /** @@ -399,30 +401,28 @@ public class ConcurrentSkipListSubSetTes Object e4 = q.ceiling(six); assertNull(e4); - } /** - * toArray contains all elements + * toArray contains all elements in sorted order */ public void testToArray() { NavigableSet 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() { - NavigableSet q = populatedSet(SIZE); + NavigableSet 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()); } /** @@ -456,7 +456,7 @@ public class ConcurrentSkipListSubSetTes /** * iterator.remove removes current element */ - public void testIteratorRemove () { + public void testIteratorRemove() { final NavigableSet q = set0(); q.add(new Integer(2)); q.add(new Integer(1)); @@ -688,6 +688,7 @@ public class ConcurrentSkipListSubSetTes shouldThrow(); } catch (NullPointerException success) {} } + /** * addAll of a collection with null elements throws NPE */ @@ -699,6 +700,7 @@ public class ConcurrentSkipListSubSetTes shouldThrow(); } catch (NullPointerException success) {} } + /** * addAll of a collection with any null elements throws NPE after * possibly adding some elements @@ -735,7 +737,7 @@ public class ConcurrentSkipListSubSetTes public void testDescendingPoll() { NavigableSet q = populatedSet(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.pollFirst()).intValue()); + assertEquals(i, q.pollFirst()); } assertNull(q.pollFirst()); } @@ -848,7 +850,6 @@ public class ConcurrentSkipListSubSetTes Object e4 = q.lower(zero); assertNull(e4); - } /** @@ -867,7 +868,6 @@ public class ConcurrentSkipListSubSetTes Object e4 = q.higher(m6); assertNull(e4); - } /** @@ -886,7 +886,6 @@ public class ConcurrentSkipListSubSetTes Object e4 = q.floor(zero); assertNull(e4); - } /** @@ -905,7 +904,6 @@ public class ConcurrentSkipListSubSetTes Object e4 = q.ceiling(m6); assertNull(e4); - } /** @@ -925,7 +923,7 @@ public class ConcurrentSkipListSubSetTes public void testDescendingToArray2() { NavigableSet q = populatedSet(SIZE); Integer[] ints = new Integer[SIZE]; - ints = (Integer[])q.toArray(ints); + assertSame(ints, q.toArray(ints)); Arrays.sort(ints); for (int i = 0; i < ints.length; i++) assertEquals(ints[i], q.pollFirst()); @@ -962,7 +960,7 @@ public class ConcurrentSkipListSubSetTes /** * iterator.remove removes current element */ - public void testDescendingIteratorRemove () { + public void testDescendingIteratorRemove() { final NavigableSet q = dset0(); q.add(new Integer(2)); q.add(new Integer(1));