--- jsr166/src/test/tck/ConcurrentSkipListMapTest.java 2006/04/20 20:35:00 1.7 +++ jsr166/src/test/tck/ConcurrentSkipListMapTest.java 2009/11/02 20:28:31 1.9 @@ -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")) || @@ -648,7 +691,7 @@ public class ConcurrentSkipListMapTest e for (int i = 1; i <= 5; ++i) { assertTrue(s.indexOf(String.valueOf(i)) >= 0); } - } + } // Exception tests @@ -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(); @@ -1264,5 +1307,5 @@ public class ConcurrentSkipListMapTest e static boolean eq(Integer i, int j) { return i == null ? j == -1 : i == j; } - + }