--- jsr166/src/test/tck/ConcurrentSkipListSetTest.java 2006/04/20 20:35:00 1.3 +++ jsr166/src/test/tck/ConcurrentSkipListSetTest.java 2009/11/21 02:07:26 1.7 @@ -11,13 +11,13 @@ import java.io.*; public class ConcurrentSkipListSetTest 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(ConcurrentSkipListSetTest.class); + return new TestSuite(ConcurrentSkipListSetTest.class); } - static class MyReverseComparator implements Comparator { + static class MyReverseComparator implements Comparator { public int compare(Object x, Object y) { int i = ((Integer)x).intValue(); int j = ((Integer)y).intValue(); @@ -34,12 +34,12 @@ public class ConcurrentSkipListSetTest e 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; } @@ -54,10 +54,10 @@ public class ConcurrentSkipListSetTest e q.add(three); q.add(four); q.add(five); - assertEquals(5, q.size()); + assertEquals(5, q.size()); return q; } - + /** * A new set has unbounded capacity */ @@ -168,11 +168,11 @@ public class ConcurrentSkipListSetTest e * add(null) throws NPE */ public void testAddNull() { - try { + try { ConcurrentSkipListSet q = new ConcurrentSkipListSet(); q.add(null); shouldThrow(); - } catch (NullPointerException success) { } + } catch (NullPointerException success) { } } /** @@ -204,7 +204,7 @@ public class ConcurrentSkipListSetTest e q.add(new Object()); shouldThrow(); } - catch(ClassCastException success) {} + catch (ClassCastException success) {} } /** @@ -272,7 +272,7 @@ public class ConcurrentSkipListSetTest e for (int i = 0; i < SIZE; ++i) { assertEquals(i, ((Integer)q.pollFirst()).intValue()); } - assertNull(q.pollFirst()); + assertNull(q.pollFirst()); } /** @@ -283,7 +283,7 @@ public class ConcurrentSkipListSetTest e for (int i = SIZE-1; i >= 0; --i) { assertEquals(i, ((Integer)q.pollLast()).intValue()); } - assertNull(q.pollFirst()); + assertNull(q.pollFirst()); } @@ -301,7 +301,7 @@ public class ConcurrentSkipListSetTest e } assertTrue(q.isEmpty()); } - + /** * contains(x) reports true when elements added but not yet removed */ @@ -377,7 +377,7 @@ public class ConcurrentSkipListSetTest e } } - + /** * lower returns preceding element @@ -460,10 +460,10 @@ public class ConcurrentSkipListSetTest e */ public void testToArray() { ConcurrentSkipListSet q = populatedSet(SIZE); - Object[] o = q.toArray(); + Object[] o = q.toArray(); Arrays.sort(o); - for(int i = 0; i < o.length; i++) - assertEquals(o[i], q.pollFirst()); + for (int i = 0; i < o.length; i++) + assertEquals(o[i], q.pollFirst()); } /** @@ -471,21 +471,21 @@ public class ConcurrentSkipListSetTest e */ public void testToArray2() { ConcurrentSkipListSet q = populatedSet(SIZE); - Integer[] ints = new Integer[SIZE]; - ints = (Integer[])q.toArray(ints); + Integer[] ints = new Integer[SIZE]; + ints = (Integer[])q.toArray(ints); Arrays.sort(ints); - for(int i = 0; i < ints.length; i++) + for (int i = 0; i < ints.length; i++) assertEquals(ints[i], q.pollFirst()); } - + /** * iterator iterates through all elements */ public void testIterator() { ConcurrentSkipListSet q = populatedSet(SIZE); int i = 0; - Iterator it = q.iterator(); - while(it.hasNext()) { + Iterator it = q.iterator(); + while (it.hasNext()) { assertTrue(q.contains(it.next())); ++i; } @@ -498,8 +498,8 @@ public class ConcurrentSkipListSetTest e public void testEmptyIterator() { ConcurrentSkipListSet q = new ConcurrentSkipListSet(); int i = 0; - Iterator it = q.iterator(); - while(it.hasNext()) { + Iterator it = q.iterator(); + while (it.hasNext()) { assertTrue(q.contains(it.next())); ++i; } @@ -535,10 +535,10 @@ public class ConcurrentSkipListSetTest e for (int i = 0; i < SIZE; ++i) { assertTrue(s.indexOf(String.valueOf(i)) >= 0); } - } + } /** - * A deserialized serialized set has same elements + * A deserialized serialized set has same elements */ public void testSerialization() { ConcurrentSkipListSet q = populatedSet(SIZE); @@ -552,9 +552,9 @@ public class ConcurrentSkipListSetTest e ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); ConcurrentSkipListSet r = (ConcurrentSkipListSet)in.readObject(); assertEquals(q.size(), r.size()); - while (!q.isEmpty()) + while (!q.isEmpty()) assertEquals(q.pollFirst(), r.pollFirst()); - } catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); unexpectedException(); } @@ -686,8 +686,8 @@ public class ConcurrentSkipListSetTest e * Subsets of subsets subdivide correctly */ public void testRecursiveSubSets() { - int setSize = 1000; - Class cl = ConcurrentSkipListSet.class; + int setSize = 1000; + Class cl = ConcurrentSkipListSet.class; NavigableSet set = newSet(cl); bs = new BitSet(setSize); @@ -706,11 +706,11 @@ public class ConcurrentSkipListSetTest e static NavigableSet newSet(Class cl) { NavigableSet result = null; - try { + try { result = (NavigableSet) cl.newInstance(); - } catch(Exception e) { + } catch (Exception e) { fail(); - } + } assertEquals(result.size(), 0); assertFalse(result.iterator().hasNext()); return result; @@ -733,7 +733,7 @@ public class ConcurrentSkipListSetTest e } // 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(); @@ -758,7 +758,7 @@ public class ConcurrentSkipListSetTest e } // 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(); @@ -774,7 +774,7 @@ public class ConcurrentSkipListSetTest e try { set.add(element); fail(); - } catch(IllegalArgumentException e) { + } catch (IllegalArgumentException e) { // expected } } @@ -976,13 +976,13 @@ public class ConcurrentSkipListSetTest e try { set.first(); fail(); - } catch(NoSuchElementException e) { + } catch (NoSuchElementException e) { // expected } try { set.last(); fail(); - } catch(NoSuchElementException e) { + } catch (NoSuchElementException e) { // expected } }