--- jsr166/src/test/tck/ConcurrentSkipListMapTest.java 2006/04/20 20:35:00 1.7 +++ jsr166/src/test/tck/ConcurrentSkipListMapTest.java 2009/11/16 05:30:07 1.11 @@ -11,7 +11,7 @@ import java.io.*; public class ConcurrentSkipListMapTest 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(ConcurrentSkipListMapTest.class); @@ -20,7 +20,7 @@ public class ConcurrentSkipListMapTest e /** * Create a map from Integers 1-5 to Strings "A"-"E". */ - private static ConcurrentSkipListMap map5() { + private static ConcurrentSkipListMap map5() { ConcurrentSkipListMap map = new ConcurrentSkipListMap(); assertTrue(map.isEmpty()); map.put(one, "A"); @@ -43,7 +43,7 @@ public class ConcurrentSkipListMapTest e } /** - * + * */ public void testConstructFromSorted() { ConcurrentSkipListMap map = map5(); @@ -169,11 +169,33 @@ public class ConcurrentSkipListMapTest e Iterator i = s.iterator(); Integer last = (Integer)i.next(); assertEquals(last, one); + int count = 1; while (i.hasNext()) { Integer k = (Integer)i.next(); assertTrue(last.compareTo(k) < 0); last = k; + ++count; } + assertEquals(count ,5); + } + + /** + * descending iterator of key set is inverse ordered + */ + public void testKeySetDescendingIteratorOrder() { + ConcurrentSkipListMap map = map5(); + NavigableSet s = map.navigableKeySet(); + Iterator i = s.descendingIterator(); + Integer last = (Integer)i.next(); + assertEquals(last, five); + int count = 1; + while (i.hasNext()) { + Integer k = (Integer)i.next(); + assertTrue(last.compareTo(k) > 0); + last = k; + ++count; + } + assertEquals(count ,5); } /** @@ -185,13 +207,34 @@ public class ConcurrentSkipListMapTest e Iterator i = s.iterator(); Integer last = (Integer)i.next(); assertEquals(last, five); + int count = 1; while (i.hasNext()) { Integer k = (Integer)i.next(); assertTrue(last.compareTo(k) > 0); last = k; + ++count; } + assertEquals(count, 5); } + /** + * descending iterator of descendingKeySet is ordered + */ + public void testDescendingKeySetDescendingIteratorOrder() { + ConcurrentSkipListMap map = map5(); + NavigableSet s = map.descendingKeySet(); + Iterator i = s.descendingIterator(); + Integer last = (Integer)i.next(); + assertEquals(last, one); + int count = 1; + while (i.hasNext()) { + Integer k = (Integer)i.next(); + assertTrue(last.compareTo(k) < 0); + last = k; + ++count; + } + assertEquals(count, 5); + } /** * Values.toArray contains all values @@ -233,7 +276,7 @@ public class ConcurrentSkipListMapTest e Iterator it = s.iterator(); while (it.hasNext()) { Map.Entry e = (Map.Entry) it.next(); - assertTrue( + assertTrue( (e.getKey().equals(one) && e.getValue().equals("A")) || (e.getKey().equals(two) && e.getValue().equals("B")) || (e.getKey().equals(three) && e.getValue().equals("C")) || @@ -252,7 +295,7 @@ public class ConcurrentSkipListMapTest e Iterator it = s.iterator(); while (it.hasNext()) { Map.Entry e = (Map.Entry) it.next(); - assertTrue( + assertTrue( (e.getKey().equals(one) && e.getValue().equals("A")) || (e.getKey().equals(two) && e.getValue().equals("B")) || (e.getKey().equals(three) && e.getValue().equals("C")) || @@ -474,25 +517,25 @@ public class ConcurrentSkipListMapTest e try { e.setValue("X"); fail(); - } catch(UnsupportedOperationException success) {} + } catch (UnsupportedOperationException success) {} e = map.higherEntry(zero); assertEquals(one, e.getKey()); try { e.setValue("X"); fail(); - } catch(UnsupportedOperationException success) {} + } catch (UnsupportedOperationException success) {} e = map.floorEntry(one); assertEquals(one, e.getKey()); try { e.setValue("X"); fail(); - } catch(UnsupportedOperationException success) {} + } catch (UnsupportedOperationException success) {} e = map.ceilingEntry(five); assertEquals(five, e.getKey()); try { e.setValue("X"); fail(); - } catch(UnsupportedOperationException success) {} + } catch (UnsupportedOperationException success) {} } @@ -648,7 +691,7 @@ public class ConcurrentSkipListMapTest e for (int i = 1; i <= 5; ++i) { assertTrue(s.indexOf(String.valueOf(i)) >= 0); } - } + } // Exception tests @@ -660,7 +703,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = map5(); c.get(null); shouldThrow(); - } catch(NullPointerException e){} + } catch (NullPointerException e) {} } /** @@ -671,7 +714,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = map5(); c.containsKey(null); shouldThrow(); - } catch(NullPointerException e){} + } catch (NullPointerException e) {} } /** @@ -682,7 +725,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = new ConcurrentSkipListMap(); c.containsValue(null); shouldThrow(); - } catch(NullPointerException e){} + } catch (NullPointerException e) {} } @@ -694,7 +737,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = map5(); c.put(null, "whatever"); shouldThrow(); - } catch(NullPointerException e){} + } catch (NullPointerException e) {} } /** @@ -705,7 +748,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = map5(); c.putIfAbsent(null, "whatever"); shouldThrow(); - } catch(NullPointerException e){} + } catch (NullPointerException e) {} } /** @@ -716,7 +759,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = map5(); c.replace(null, "whatever"); shouldThrow(); - } catch(NullPointerException e){} + } catch (NullPointerException e) {} } /** @@ -727,7 +770,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = map5(); c.replace(null, one, "whatever"); shouldThrow(); - } catch(NullPointerException e){} + } catch (NullPointerException e) {} } /** @@ -739,7 +782,7 @@ public class ConcurrentSkipListMapTest e c.put("sadsdf", "asdads"); c.remove(null); shouldThrow(); - } catch(NullPointerException e){} + } catch (NullPointerException e) {} } /** @@ -751,7 +794,7 @@ public class ConcurrentSkipListMapTest e c.put("sadsdf", "asdads"); c.remove(null, "whatever"); shouldThrow(); - } catch(NullPointerException e){} + } catch (NullPointerException e) {} } /** @@ -762,7 +805,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = new ConcurrentSkipListMap(); c.put("sadsdf", "asdads"); assertFalse(c.remove("sadsdf", null)); - } catch(NullPointerException e){ + } catch (NullPointerException e) { fail(); } } @@ -785,7 +828,7 @@ public class ConcurrentSkipListMapTest e assertEquals(q.size(), r.size()); assertTrue(q.equals(r)); assertTrue(r.equals(q)); - } catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); unexpectedException(); } @@ -820,7 +863,7 @@ public class ConcurrentSkipListMapTest e k = (Integer)(r.next()); assertEquals(two, k); assertFalse(r.hasNext()); - + Iterator j = sm.keySet().iterator(); j.next(); j.remove(); @@ -854,7 +897,7 @@ public class ConcurrentSkipListMapTest e k = (Integer)(r.next()); assertEquals(two, k); assertFalse(r.hasNext()); - + Iterator j = sm.keySet().iterator(); j.next(); j.remove(); @@ -978,7 +1021,7 @@ public class ConcurrentSkipListMapTest e NavigableMap result = null; try { result = (NavigableMap) cl.newInstance(); - } catch(Exception e) { + } catch (Exception e) { fail(); } assertEquals(result.size(), 0); @@ -1003,7 +1046,7 @@ public class ConcurrentSkipListMapTest e } // Remove a bunch of entries with iterator - for(Iterator it = map.keySet().iterator(); it.hasNext(); ) { + for (Iterator it = map.keySet().iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { bs.clear(it.next()); it.remove(); @@ -1028,7 +1071,7 @@ public class ConcurrentSkipListMapTest e } // Remove a bunch of entries with iterator - for(Iterator it = map.keySet().iterator(); it.hasNext(); ) { + for (Iterator it = map.keySet().iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { bs.clear(it.next()); it.remove(); @@ -1044,7 +1087,7 @@ public class ConcurrentSkipListMapTest e try { map.put(key, 2 * key); fail(); - } catch(IllegalArgumentException e) { + } catch (IllegalArgumentException e) { // expected } } @@ -1242,13 +1285,13 @@ public class ConcurrentSkipListMapTest e try { map.firstKey(); fail(); - } catch(NoSuchElementException e) { + } catch (NoSuchElementException e) { // expected } try { map.lastKey(); fail(); - } catch(NoSuchElementException e) { + } catch (NoSuchElementException e) { // expected } } @@ -1264,5 +1307,5 @@ public class ConcurrentSkipListMapTest e static boolean eq(Integer i, int j) { return i == null ? j == -1 : i == j; } - + }