--- jsr166/src/test/tck/TreeSubMapTest.java 2017/08/04 03:30:21 1.24 +++ jsr166/src/test/tck/TreeSubMapTest.java 2021/01/26 13:33:06 1.25 @@ -26,10 +26,10 @@ public class TreeSubMapTest extends JSR1 } /** - * Returns a new map from Integers 1-5 to Strings "A"-"E". + * Returns a new map from Items 1-5 to Strings "A"-"E". */ - private static NavigableMap map5() { - TreeMap map = new TreeMap(); + private static NavigableMap map5() { + TreeMap map = new TreeMap(); assertTrue(map.isEmpty()); map.put(zero, "Z"); map.put(one, "A"); @@ -39,34 +39,34 @@ public class TreeSubMapTest extends JSR1 map.put(four, "D"); map.put(seven, "F"); assertFalse(map.isEmpty()); - assertEquals(7, map.size()); + mustEqual(7, map.size()); return map.subMap(one, true, seven, false); } - private static NavigableMap map0() { - TreeMap map = new TreeMap(); + private static NavigableMap map0() { + TreeMap map = new TreeMap(); assertTrue(map.isEmpty()); return map.tailMap(one, true); } /** - * Returns a new map from Integers -5 to -1 to Strings "A"-"E". + * Returns a new map from Items -5 to -1 to Strings "A"-"E". */ - private static NavigableMap dmap5() { - TreeMap map = new TreeMap(); + private static NavigableMap dmap5() { + TreeMap map = new TreeMap(); assertTrue(map.isEmpty()); - map.put(m1, "A"); - map.put(m5, "E"); - map.put(m3, "C"); - map.put(m2, "B"); - map.put(m4, "D"); + map.put(minusOne, "A"); + map.put(minusFive, "E"); + map.put(minusThree, "C"); + map.put(minusTwo, "B"); + map.put(minusFour, "D"); assertFalse(map.isEmpty()); - assertEquals(5, map.size()); + mustEqual(5, map.size()); return map.descendingMap(); } - private static NavigableMap dmap0() { - TreeMap map = new TreeMap(); + private static NavigableMap dmap0() { + TreeMap map = new TreeMap(); assertTrue(map.isEmpty()); return map; } @@ -75,19 +75,19 @@ public class TreeSubMapTest extends JSR1 * clear removes all pairs */ public void testClear() { - NavigableMap map = map5(); + NavigableMap map = map5(); map.clear(); - assertEquals(0, map.size()); + mustEqual(0, map.size()); } /** * Maps with same contents are equal */ public void testEquals() { - NavigableMap map1 = map5(); - NavigableMap map2 = map5(); - assertEquals(map1, map2); - assertEquals(map2, map1); + NavigableMap map1 = map5(); + NavigableMap map2 = map5(); + mustEqual(map1, map2); + mustEqual(map2, map1); map1.clear(); assertFalse(map1.equals(map2)); assertFalse(map2.equals(map1)); @@ -97,7 +97,7 @@ public class TreeSubMapTest extends JSR1 * containsKey returns true for contained key */ public void testContainsKey() { - NavigableMap map = map5(); + NavigableMap map = map5(); assertTrue(map.containsKey(one)); assertFalse(map.containsKey(zero)); } @@ -106,7 +106,7 @@ public class TreeSubMapTest extends JSR1 * containsValue returns true for held values */ public void testContainsValue() { - NavigableMap map = map5(); + NavigableMap map = map5(); assertTrue(map.containsValue("A")); assertFalse(map.containsValue("Z")); } @@ -116,9 +116,9 @@ public class TreeSubMapTest extends JSR1 * or null if not present */ public void testGet() { - NavigableMap map = map5(); - assertEquals("A", (String)map.get(one)); - NavigableMap empty = map0(); + NavigableMap map = map5(); + mustEqual("A", map.get(one)); + NavigableMap empty = map0(); assertNull(empty.get(one)); } @@ -126,8 +126,8 @@ public class TreeSubMapTest extends JSR1 * isEmpty is true of empty map and false for non-empty */ public void testIsEmpty() { - NavigableMap empty = map0(); - NavigableMap map = map5(); + NavigableMap empty = map0(); + NavigableMap map = map5(); assertTrue(empty.isEmpty()); assertFalse(map.isEmpty()); } @@ -136,43 +136,43 @@ public class TreeSubMapTest extends JSR1 * firstKey returns first key */ public void testFirstKey() { - NavigableMap map = map5(); - assertEquals(one, map.firstKey()); + NavigableMap map = map5(); + mustEqual(one, map.firstKey()); } /** * lastKey returns last key */ public void testLastKey() { - NavigableMap map = map5(); - assertEquals(five, map.lastKey()); + NavigableMap map = map5(); + mustEqual(five, map.lastKey()); } /** * keySet returns a Set containing all the keys */ public void testKeySet() { - NavigableMap map = map5(); - Set s = map.keySet(); - assertEquals(5, s.size()); - assertTrue(s.contains(one)); - assertTrue(s.contains(two)); - assertTrue(s.contains(three)); - assertTrue(s.contains(four)); - assertTrue(s.contains(five)); + NavigableMap map = map5(); + Set s = map.keySet(); + mustEqual(5, s.size()); + mustContain(s, one); + mustContain(s, two); + mustContain(s, three); + mustContain(s, four); + mustContain(s, five); } /** * keySet is ordered */ public void testKeySetOrder() { - NavigableMap map = map5(); - Set s = map.keySet(); - Iterator i = s.iterator(); - Integer last = (Integer)i.next(); - assertEquals(last, one); + NavigableMap map = map5(); + Set s = map.keySet(); + Iterator i = s.iterator(); + Item last = i.next(); + mustEqual(last, one); while (i.hasNext()) { - Integer k = (Integer)i.next(); + Item k = i.next(); assertTrue(last.compareTo(k) < 0); last = k; } @@ -182,9 +182,9 @@ public class TreeSubMapTest extends JSR1 * values collection contains all values */ public void testValues() { - NavigableMap map = map5(); - Collection s = map.values(); - assertEquals(5, s.size()); + NavigableMap map = map5(); + Collection s = map.values(); + mustEqual(5, s.size()); assertTrue(s.contains("A")); assertTrue(s.contains("B")); assertTrue(s.contains("C")); @@ -196,12 +196,12 @@ public class TreeSubMapTest extends JSR1 * entrySet contains all pairs */ public void testEntrySet() { - NavigableMap map = map5(); - Set s = map.entrySet(); - assertEquals(5, s.size()); - Iterator it = s.iterator(); + NavigableMap map = map5(); + Set> s = map.entrySet(); + mustEqual(5, s.size()); + Iterator> it = s.iterator(); while (it.hasNext()) { - Map.Entry e = (Map.Entry) it.next(); + Map.Entry e = it.next(); assertTrue( (e.getKey().equals(one) && e.getValue().equals("A")) || (e.getKey().equals(two) && e.getValue().equals("B")) || @@ -215,10 +215,10 @@ public class TreeSubMapTest extends JSR1 * putAll adds all key-value pairs from the given map */ public void testPutAll() { - NavigableMap empty = map0(); - NavigableMap map = map5(); + NavigableMap empty = map0(); + NavigableMap map = map5(); empty.putAll(map); - assertEquals(5, empty.size()); + mustEqual(5, empty.size()); assertTrue(empty.containsKey(one)); assertTrue(empty.containsKey(two)); assertTrue(empty.containsKey(three)); @@ -230,9 +230,9 @@ public class TreeSubMapTest extends JSR1 * remove removes the correct key-value pair from the map */ public void testRemove() { - NavigableMap map = map5(); + NavigableMap map = map5(); map.remove(five); - assertEquals(4, map.size()); + mustEqual(4, map.size()); assertFalse(map.containsKey(five)); } @@ -240,17 +240,17 @@ public class TreeSubMapTest extends JSR1 * lowerEntry returns preceding entry. */ public void testLowerEntry() { - NavigableMap map = map5(); - Map.Entry e1 = map.lowerEntry(three); - assertEquals(two, e1.getKey()); + NavigableMap map = map5(); + Map.Entry e1 = map.lowerEntry(three); + mustEqual(two, e1.getKey()); - Map.Entry e2 = map.lowerEntry(six); - assertEquals(five, e2.getKey()); + Map.Entry e2 = map.lowerEntry(six); + mustEqual(five, e2.getKey()); - Map.Entry e3 = map.lowerEntry(one); + Map.Entry e3 = map.lowerEntry(one); assertNull(e3); - Map.Entry e4 = map.lowerEntry(zero); + Map.Entry e4 = map.lowerEntry(zero); assertNull(e4); } @@ -258,17 +258,17 @@ public class TreeSubMapTest extends JSR1 * higherEntry returns next entry. */ public void testHigherEntry() { - NavigableMap map = map5(); - Map.Entry e1 = map.higherEntry(three); - assertEquals(four, e1.getKey()); + NavigableMap map = map5(); + Map.Entry e1 = map.higherEntry(three); + mustEqual(four, e1.getKey()); - Map.Entry e2 = map.higherEntry(zero); - assertEquals(one, e2.getKey()); + Map.Entry e2 = map.higherEntry(zero); + mustEqual(one, e2.getKey()); - Map.Entry e3 = map.higherEntry(five); + Map.Entry e3 = map.higherEntry(five); assertNull(e3); - Map.Entry e4 = map.higherEntry(six); + Map.Entry e4 = map.higherEntry(six); assertNull(e4); } @@ -276,17 +276,17 @@ public class TreeSubMapTest extends JSR1 * floorEntry returns preceding entry. */ public void testFloorEntry() { - NavigableMap map = map5(); - Map.Entry e1 = map.floorEntry(three); - assertEquals(three, e1.getKey()); + NavigableMap map = map5(); + Map.Entry e1 = map.floorEntry(three); + mustEqual(three, e1.getKey()); - Map.Entry e2 = map.floorEntry(six); - assertEquals(five, e2.getKey()); + Map.Entry e2 = map.floorEntry(six); + mustEqual(five, e2.getKey()); - Map.Entry e3 = map.floorEntry(one); - assertEquals(one, e3.getKey()); + Map.Entry e3 = map.floorEntry(one); + mustEqual(one, e3.getKey()); - Map.Entry e4 = map.floorEntry(zero); + Map.Entry e4 = map.floorEntry(zero); assertNull(e4); } @@ -294,17 +294,17 @@ public class TreeSubMapTest extends JSR1 * ceilingEntry returns next entry. */ public void testCeilingEntry() { - NavigableMap map = map5(); - Map.Entry e1 = map.ceilingEntry(three); - assertEquals(three, e1.getKey()); + NavigableMap map = map5(); + Map.Entry e1 = map.ceilingEntry(three); + mustEqual(three, e1.getKey()); - Map.Entry e2 = map.ceilingEntry(zero); - assertEquals(one, e2.getKey()); + Map.Entry e2 = map.ceilingEntry(zero); + mustEqual(one, e2.getKey()); - Map.Entry e3 = map.ceilingEntry(five); - assertEquals(five, e3.getKey()); + Map.Entry e3 = map.ceilingEntry(five); + mustEqual(five, e3.getKey()); - Map.Entry e4 = map.ceilingEntry(six); + Map.Entry e4 = map.ceilingEntry(six); assertNull(e4); } @@ -312,27 +312,27 @@ public class TreeSubMapTest extends JSR1 * pollFirstEntry returns entries in order */ public void testPollFirstEntry() { - NavigableMap map = map5(); - Map.Entry e = map.pollFirstEntry(); - assertEquals(one, e.getKey()); - assertEquals("A", e.getValue()); + NavigableMap map = map5(); + Map.Entry e = map.pollFirstEntry(); + mustEqual(one, e.getKey()); + mustEqual("A", e.getValue()); e = map.pollFirstEntry(); - assertEquals(two, e.getKey()); + mustEqual(two, e.getKey()); map.put(one, "A"); e = map.pollFirstEntry(); - assertEquals(one, e.getKey()); - assertEquals("A", e.getValue()); + mustEqual(one, e.getKey()); + mustEqual("A", e.getValue()); e = map.pollFirstEntry(); - assertEquals(three, e.getKey()); + mustEqual(three, e.getKey()); map.remove(four); e = map.pollFirstEntry(); - assertEquals(five, e.getKey()); + mustEqual(five, e.getKey()); try { e.setValue("A"); shouldThrow(); } catch (UnsupportedOperationException success) {} assertTrue(map.isEmpty()); - Map.Entry f = map.firstEntry(); + Map.Entry f = map.firstEntry(); assertNull(f); e = map.pollFirstEntry(); assertNull(e); @@ -342,21 +342,21 @@ public class TreeSubMapTest extends JSR1 * pollLastEntry returns entries in order */ public void testPollLastEntry() { - NavigableMap map = map5(); - Map.Entry e = map.pollLastEntry(); - assertEquals(five, e.getKey()); - assertEquals("E", e.getValue()); + NavigableMap map = map5(); + Map.Entry e = map.pollLastEntry(); + mustEqual(five, e.getKey()); + mustEqual("E", e.getValue()); e = map.pollLastEntry(); - assertEquals(four, e.getKey()); + mustEqual(four, e.getKey()); map.put(five, "E"); e = map.pollLastEntry(); - assertEquals(five, e.getKey()); - assertEquals("E", e.getValue()); + mustEqual(five, e.getKey()); + mustEqual("E", e.getValue()); e = map.pollLastEntry(); - assertEquals(three, e.getKey()); + mustEqual(three, e.getKey()); map.remove(two); e = map.pollLastEntry(); - assertEquals(one, e.getKey()); + mustEqual(one, e.getKey()); try { e.setValue("E"); shouldThrow(); @@ -369,17 +369,17 @@ public class TreeSubMapTest extends JSR1 * size returns the correct values */ public void testSize() { - NavigableMap map = map5(); - NavigableMap empty = map0(); - assertEquals(0, empty.size()); - assertEquals(5, map.size()); + NavigableMap map = map5(); + NavigableMap empty = map0(); + mustEqual(0, empty.size()); + mustEqual(5, map.size()); } /** * toString contains toString of elements */ public void testToString() { - NavigableMap map = map5(); + NavigableMap map = map5(); String s = map.toString(); for (int i = 1; i <= 5; ++i) { assertTrue(s.contains(String.valueOf(i))); @@ -392,7 +392,7 @@ public class TreeSubMapTest extends JSR1 * get(null) of nonempty map throws NPE */ public void testGet_NullPointerException() { - NavigableMap c = map5(); + NavigableMap c = map5(); try { c.get(null); shouldThrow(); @@ -403,7 +403,7 @@ public class TreeSubMapTest extends JSR1 * containsKey(null) of nonempty map throws NPE */ public void testContainsKey_NullPointerException() { - NavigableMap c = map5(); + NavigableMap c = map5(); try { c.containsKey(null); shouldThrow(); @@ -414,7 +414,7 @@ public class TreeSubMapTest extends JSR1 * put(null,x) throws NPE */ public void testPut1_NullPointerException() { - NavigableMap c = map5(); + NavigableMap c = map5(); try { c.put(null, "whatever"); shouldThrow(); @@ -425,7 +425,7 @@ public class TreeSubMapTest extends JSR1 * remove(null) throws NPE */ public void testRemove1_NullPointerException() { - NavigableMap c = map5(); + NavigableMap c = map5(); try { c.remove(null); shouldThrow(); @@ -436,168 +436,168 @@ public class TreeSubMapTest extends JSR1 * A deserialized/reserialized map equals original */ public void testSerialization() throws Exception { - NavigableMap x = map5(); - NavigableMap y = serialClone(x); + NavigableMap x = map5(); + NavigableMap y = serialClone(x); assertNotSame(x, y); - assertEquals(x.size(), y.size()); - assertEquals(x.toString(), y.toString()); - assertEquals(x, y); - assertEquals(y, x); + mustEqual(x.size(), y.size()); + mustEqual(x.toString(), y.toString()); + mustEqual(x, y); + mustEqual(y, x); } /** * subMap returns map with keys in requested range */ public void testSubMapContents() { - NavigableMap map = map5(); - SortedMap sm = map.subMap(two, four); - assertEquals(two, sm.firstKey()); - assertEquals(three, sm.lastKey()); - assertEquals(2, sm.size()); + NavigableMap map = map5(); + SortedMap sm = map.subMap(two, four); + mustEqual(two, sm.firstKey()); + mustEqual(three, sm.lastKey()); + mustEqual(2, sm.size()); assertFalse(sm.containsKey(one)); assertTrue(sm.containsKey(two)); assertTrue(sm.containsKey(three)); assertFalse(sm.containsKey(four)); assertFalse(sm.containsKey(five)); - Iterator i = sm.keySet().iterator(); - Object k; - k = (Integer)(i.next()); - assertEquals(two, k); - k = (Integer)(i.next()); - assertEquals(three, k); + Iterator i = sm.keySet().iterator(); + Item k; + k = (Item)(i.next()); + mustEqual(two, k); + k = (Item)(i.next()); + mustEqual(three, k); assertFalse(i.hasNext()); - Iterator j = sm.keySet().iterator(); + Iterator j = sm.keySet().iterator(); j.next(); j.remove(); assertFalse(map.containsKey(two)); - assertEquals(4, map.size()); - assertEquals(1, sm.size()); - assertEquals(three, sm.firstKey()); - assertEquals(three, sm.lastKey()); - assertEquals("C", sm.remove(three)); + mustEqual(4, map.size()); + mustEqual(1, sm.size()); + mustEqual(three, sm.firstKey()); + mustEqual(three, sm.lastKey()); + mustEqual("C", sm.remove(three)); assertTrue(sm.isEmpty()); - assertEquals(3, map.size()); + mustEqual(3, map.size()); } public void testSubMapContents2() { - NavigableMap map = map5(); - SortedMap sm = map.subMap(two, three); - assertEquals(1, sm.size()); - assertEquals(two, sm.firstKey()); - assertEquals(two, sm.lastKey()); + NavigableMap map = map5(); + SortedMap sm = map.subMap(two, three); + mustEqual(1, sm.size()); + mustEqual(two, sm.firstKey()); + mustEqual(two, sm.lastKey()); assertFalse(sm.containsKey(one)); assertTrue(sm.containsKey(two)); assertFalse(sm.containsKey(three)); assertFalse(sm.containsKey(four)); assertFalse(sm.containsKey(five)); - Iterator i = sm.keySet().iterator(); + Iterator i = sm.keySet().iterator(); Object k; - k = (Integer)(i.next()); - assertEquals(two, k); + k = (Item)(i.next()); + mustEqual(two, k); assertFalse(i.hasNext()); - Iterator j = sm.keySet().iterator(); + Iterator j = sm.keySet().iterator(); j.next(); j.remove(); assertFalse(map.containsKey(two)); - assertEquals(4, map.size()); - assertEquals(0, sm.size()); + mustEqual(4, map.size()); + mustEqual(0, sm.size()); assertTrue(sm.isEmpty()); - assertSame(sm.remove(three), null); - assertEquals(4, map.size()); + assertNull(sm.remove(three)); + mustEqual(4, map.size()); } /** * headMap returns map with keys in requested range */ public void testHeadMapContents() { - NavigableMap map = map5(); - SortedMap sm = map.headMap(four); + NavigableMap map = map5(); + SortedMap sm = map.headMap(four); assertTrue(sm.containsKey(one)); assertTrue(sm.containsKey(two)); assertTrue(sm.containsKey(three)); assertFalse(sm.containsKey(four)); assertFalse(sm.containsKey(five)); - Iterator i = sm.keySet().iterator(); - Object k; - k = (Integer)(i.next()); - assertEquals(one, k); - k = (Integer)(i.next()); - assertEquals(two, k); - k = (Integer)(i.next()); - assertEquals(three, k); + Iterator i = sm.keySet().iterator(); + Item k; + k = (Item)(i.next()); + mustEqual(one, k); + k = (Item)(i.next()); + mustEqual(two, k); + k = (Item)(i.next()); + mustEqual(three, k); assertFalse(i.hasNext()); sm.clear(); assertTrue(sm.isEmpty()); - assertEquals(2, map.size()); - assertEquals(four, map.firstKey()); + mustEqual(2, map.size()); + mustEqual(four, map.firstKey()); } /** * headMap returns map with keys in requested range */ public void testTailMapContents() { - NavigableMap map = map5(); - SortedMap sm = map.tailMap(two); + NavigableMap map = map5(); + SortedMap sm = map.tailMap(two); assertFalse(sm.containsKey(one)); assertTrue(sm.containsKey(two)); assertTrue(sm.containsKey(three)); assertTrue(sm.containsKey(four)); assertTrue(sm.containsKey(five)); - Iterator i = sm.keySet().iterator(); + Iterator i = sm.keySet().iterator(); Object k; - k = (Integer)(i.next()); - assertEquals(two, k); - k = (Integer)(i.next()); - assertEquals(three, k); - k = (Integer)(i.next()); - assertEquals(four, k); - k = (Integer)(i.next()); - assertEquals(five, k); + k = (Item)(i.next()); + mustEqual(two, k); + k = (Item)(i.next()); + mustEqual(three, k); + k = (Item)(i.next()); + mustEqual(four, k); + k = (Item)(i.next()); + mustEqual(five, k); assertFalse(i.hasNext()); - Iterator ei = sm.entrySet().iterator(); - Map.Entry e; - e = (Map.Entry)(ei.next()); - assertEquals(two, e.getKey()); - assertEquals("B", e.getValue()); - e = (Map.Entry)(ei.next()); - assertEquals(three, e.getKey()); - assertEquals("C", e.getValue()); - e = (Map.Entry)(ei.next()); - assertEquals(four, e.getKey()); - assertEquals("D", e.getValue()); - e = (Map.Entry)(ei.next()); - assertEquals(five, e.getKey()); - assertEquals("E", e.getValue()); + Iterator> ei = sm.entrySet().iterator(); + Map.Entry e; + e = ei.next(); + mustEqual(two, e.getKey()); + mustEqual("B", e.getValue()); + e = (ei.next()); + mustEqual(three, e.getKey()); + mustEqual("C", e.getValue()); + e = (ei.next()); + mustEqual(four, e.getKey()); + mustEqual("D", e.getValue()); + e = (ei.next()); + mustEqual(five, e.getKey()); + mustEqual("E", e.getValue()); assertFalse(i.hasNext()); - SortedMap ssm = sm.tailMap(four); - assertEquals(four, ssm.firstKey()); - assertEquals(five, ssm.lastKey()); - assertEquals("D", ssm.remove(four)); - assertEquals(1, ssm.size()); - assertEquals(3, sm.size()); - assertEquals(4, map.size()); + SortedMap ssm = sm.tailMap(four); + mustEqual(four, ssm.firstKey()); + mustEqual(five, ssm.lastKey()); + mustEqual("D", ssm.remove(four)); + mustEqual(1, ssm.size()); + mustEqual(3, sm.size()); + mustEqual(4, map.size()); } /** * clear removes all pairs */ public void testDescendingClear() { - NavigableMap map = dmap5(); + NavigableMap map = dmap5(); map.clear(); - assertEquals(0, map.size()); + mustEqual(0, map.size()); } /** * Maps with same contents are equal */ public void testDescendingEquals() { - NavigableMap map1 = dmap5(); - NavigableMap map2 = dmap5(); - assertEquals(map1, map2); - assertEquals(map2, map1); + NavigableMap map1 = dmap5(); + NavigableMap map2 = dmap5(); + mustEqual(map1, map2); + mustEqual(map2, map1); map1.clear(); assertFalse(map1.equals(map2)); assertFalse(map2.equals(map1)); @@ -607,8 +607,8 @@ public class TreeSubMapTest extends JSR1 * containsKey returns true for contained key */ public void testDescendingContainsKey() { - NavigableMap map = dmap5(); - assertTrue(map.containsKey(m1)); + NavigableMap map = dmap5(); + assertTrue(map.containsKey(minusOne)); assertFalse(map.containsKey(zero)); } @@ -616,7 +616,7 @@ public class TreeSubMapTest extends JSR1 * containsValue returns true for held values */ public void testDescendingContainsValue() { - NavigableMap map = dmap5(); + NavigableMap map = dmap5(); assertTrue(map.containsValue("A")); assertFalse(map.containsValue("Z")); } @@ -626,18 +626,18 @@ public class TreeSubMapTest extends JSR1 * or null if not present */ public void testDescendingGet() { - NavigableMap map = dmap5(); - assertEquals("A", (String)map.get(m1)); - NavigableMap empty = dmap0(); - assertNull(empty.get(m1)); + NavigableMap map = dmap5(); + mustEqual("A", map.get(minusOne)); + NavigableMap empty = dmap0(); + assertNull(empty.get(minusOne)); } /** * isEmpty is true of empty map and false for non-empty */ public void testDescendingIsEmpty() { - NavigableMap empty = dmap0(); - NavigableMap map = dmap5(); + NavigableMap empty = dmap0(); + NavigableMap map = dmap5(); assertTrue(empty.isEmpty()); assertFalse(map.isEmpty()); } @@ -646,43 +646,43 @@ public class TreeSubMapTest extends JSR1 * firstKey returns first key */ public void testDescendingFirstKey() { - NavigableMap map = dmap5(); - assertEquals(m1, map.firstKey()); + NavigableMap map = dmap5(); + mustEqual(minusOne, map.firstKey()); } /** * lastKey returns last key */ public void testDescendingLastKey() { - NavigableMap map = dmap5(); - assertEquals(m5, map.lastKey()); + NavigableMap map = dmap5(); + mustEqual(minusFive, map.lastKey()); } /** * keySet returns a Set containing all the keys */ public void testDescendingKeySet() { - NavigableMap map = dmap5(); - Set s = map.keySet(); - assertEquals(5, s.size()); - assertTrue(s.contains(m1)); - assertTrue(s.contains(m2)); - assertTrue(s.contains(m3)); - assertTrue(s.contains(m4)); - assertTrue(s.contains(m5)); + NavigableMap map = dmap5(); + Set s = map.keySet(); + mustEqual(5, s.size()); + mustContain(s, minusOne); + mustContain(s, minusTwo); + mustContain(s, minusThree); + mustContain(s, minusFour); + mustContain(s, minusFive); } /** * keySet is ordered */ public void testDescendingKeySetOrder() { - NavigableMap map = dmap5(); - Set s = map.keySet(); - Iterator i = s.iterator(); - Integer last = (Integer)i.next(); - assertEquals(last, m1); + NavigableMap map = dmap5(); + Set s = map.keySet(); + Iterator i = s.iterator(); + Item last = (Item)i.next(); + mustEqual(last, minusOne); while (i.hasNext()) { - Integer k = (Integer)i.next(); + Item k = (Item)i.next(); assertTrue(last.compareTo(k) > 0); last = k; } @@ -692,9 +692,9 @@ public class TreeSubMapTest extends JSR1 * values collection contains all values */ public void testDescendingValues() { - NavigableMap map = dmap5(); - Collection s = map.values(); - assertEquals(5, s.size()); + NavigableMap map = dmap5(); + Collection s = map.values(); + mustEqual(5, s.size()); assertTrue(s.contains("A")); assertTrue(s.contains("B")); assertTrue(s.contains("C")); @@ -706,12 +706,12 @@ public class TreeSubMapTest extends JSR1 * keySet.toArray returns contains all keys */ public void testDescendingAscendingKeySetToArray() { - NavigableMap map = dmap5(); - Set s = map.keySet(); - Object[] ar = s.toArray(); + NavigableMap map = dmap5(); + Set s = map.keySet(); + Item[] ar = s.toArray(new Item[0]); assertTrue(s.containsAll(Arrays.asList(ar))); - assertEquals(5, ar.length); - ar[0] = m10; + mustEqual(5, ar.length); + ar[0] = minusTen; assertFalse(s.containsAll(Arrays.asList(ar))); } @@ -719,12 +719,12 @@ public class TreeSubMapTest extends JSR1 * descendingkeySet.toArray returns contains all keys */ public void testDescendingDescendingKeySetToArray() { - NavigableMap map = dmap5(); - Set s = map.descendingKeySet(); - Object[] ar = s.toArray(); - assertEquals(5, ar.length); + NavigableMap map = dmap5(); + Set s = map.descendingKeySet(); + Item[] ar = s.toArray(new Item[0]); + mustEqual(5, ar.length); assertTrue(s.containsAll(Arrays.asList(ar))); - ar[0] = m10; + ar[0] = minusTen; assertFalse(s.containsAll(Arrays.asList(ar))); } @@ -732,11 +732,11 @@ public class TreeSubMapTest extends JSR1 * Values.toArray contains all values */ public void testDescendingValuesToArray() { - NavigableMap map = dmap5(); - Collection v = map.values(); - Object[] ar = v.toArray(); - ArrayList s = new ArrayList(Arrays.asList(ar)); - assertEquals(5, ar.length); + NavigableMap map = dmap5(); + Collection v = map.values(); + String[] ar = v.toArray(new String[0]); + ArrayList s = new ArrayList(Arrays.asList(ar)); + mustEqual(5, ar.length); assertTrue(s.contains("A")); assertTrue(s.contains("B")); assertTrue(s.contains("C")); @@ -748,18 +748,18 @@ public class TreeSubMapTest extends JSR1 * entrySet contains all pairs */ public void testDescendingEntrySet() { - NavigableMap map = dmap5(); - Set s = map.entrySet(); - assertEquals(5, s.size()); - Iterator it = s.iterator(); + NavigableMap map = dmap5(); + Set> s = map.entrySet(); + mustEqual(5, s.size()); + Iterator> it = s.iterator(); while (it.hasNext()) { - Map.Entry e = (Map.Entry) it.next(); + Map.Entry e = it.next(); assertTrue( - (e.getKey().equals(m1) && e.getValue().equals("A")) || - (e.getKey().equals(m2) && e.getValue().equals("B")) || - (e.getKey().equals(m3) && e.getValue().equals("C")) || - (e.getKey().equals(m4) && e.getValue().equals("D")) || - (e.getKey().equals(m5) && e.getValue().equals("E"))); + (e.getKey().equals(minusOne) && e.getValue().equals("A")) || + (e.getKey().equals(minusTwo) && e.getValue().equals("B")) || + (e.getKey().equals(minusThree) && e.getValue().equals("C")) || + (e.getKey().equals(minusFour) && e.getValue().equals("D")) || + (e.getKey().equals(minusFive) && e.getValue().equals("E"))); } } @@ -767,42 +767,42 @@ public class TreeSubMapTest extends JSR1 * putAll adds all key-value pairs from the given map */ public void testDescendingPutAll() { - NavigableMap empty = dmap0(); - NavigableMap map = dmap5(); + NavigableMap empty = dmap0(); + NavigableMap map = dmap5(); empty.putAll(map); - assertEquals(5, empty.size()); - assertTrue(empty.containsKey(m1)); - assertTrue(empty.containsKey(m2)); - assertTrue(empty.containsKey(m3)); - assertTrue(empty.containsKey(m4)); - assertTrue(empty.containsKey(m5)); + mustEqual(5, empty.size()); + assertTrue(empty.containsKey(minusOne)); + assertTrue(empty.containsKey(minusTwo)); + assertTrue(empty.containsKey(minusThree)); + assertTrue(empty.containsKey(minusFour)); + assertTrue(empty.containsKey(minusFive)); } /** * remove removes the correct key-value pair from the map */ public void testDescendingRemove() { - NavigableMap map = dmap5(); - map.remove(m5); - assertEquals(4, map.size()); - assertFalse(map.containsKey(m5)); + NavigableMap map = dmap5(); + map.remove(minusFive); + mustEqual(4, map.size()); + assertFalse(map.containsKey(minusFive)); } /** * lowerEntry returns preceding entry. */ public void testDescendingLowerEntry() { - NavigableMap map = dmap5(); - Map.Entry e1 = map.lowerEntry(m3); - assertEquals(m2, e1.getKey()); + NavigableMap map = dmap5(); + Map.Entry e1 = map.lowerEntry(minusThree); + mustEqual(minusTwo, e1.getKey()); - Map.Entry e2 = map.lowerEntry(m6); - assertEquals(m5, e2.getKey()); + Map.Entry e2 = map.lowerEntry(minusSix); + mustEqual(minusFive, e2.getKey()); - Map.Entry e3 = map.lowerEntry(m1); + Map.Entry e3 = map.lowerEntry(minusOne); assertNull(e3); - Map.Entry e4 = map.lowerEntry(zero); + Map.Entry e4 = map.lowerEntry(zero); assertNull(e4); } @@ -810,17 +810,17 @@ public class TreeSubMapTest extends JSR1 * higherEntry returns next entry. */ public void testDescendingHigherEntry() { - NavigableMap map = dmap5(); - Map.Entry e1 = map.higherEntry(m3); - assertEquals(m4, e1.getKey()); + NavigableMap map = dmap5(); + Map.Entry e1 = map.higherEntry(minusThree); + mustEqual(minusFour, e1.getKey()); - Map.Entry e2 = map.higherEntry(zero); - assertEquals(m1, e2.getKey()); + Map.Entry e2 = map.higherEntry(zero); + mustEqual(minusOne, e2.getKey()); - Map.Entry e3 = map.higherEntry(m5); + Map.Entry e3 = map.higherEntry(minusFive); assertNull(e3); - Map.Entry e4 = map.higherEntry(m6); + Map.Entry e4 = map.higherEntry(minusSix); assertNull(e4); } @@ -828,17 +828,17 @@ public class TreeSubMapTest extends JSR1 * floorEntry returns preceding entry. */ public void testDescendingFloorEntry() { - NavigableMap map = dmap5(); - Map.Entry e1 = map.floorEntry(m3); - assertEquals(m3, e1.getKey()); + NavigableMap map = dmap5(); + Map.Entry e1 = map.floorEntry(minusThree); + mustEqual(minusThree, e1.getKey()); - Map.Entry e2 = map.floorEntry(m6); - assertEquals(m5, e2.getKey()); + Map.Entry e2 = map.floorEntry(minusSix); + mustEqual(minusFive, e2.getKey()); - Map.Entry e3 = map.floorEntry(m1); - assertEquals(m1, e3.getKey()); + Map.Entry e3 = map.floorEntry(minusOne); + mustEqual(minusOne, e3.getKey()); - Map.Entry e4 = map.floorEntry(zero); + Map.Entry e4 = map.floorEntry(zero); assertNull(e4); } @@ -846,17 +846,17 @@ public class TreeSubMapTest extends JSR1 * ceilingEntry returns next entry. */ public void testDescendingCeilingEntry() { - NavigableMap map = dmap5(); - Map.Entry e1 = map.ceilingEntry(m3); - assertEquals(m3, e1.getKey()); + NavigableMap map = dmap5(); + Map.Entry e1 = map.ceilingEntry(minusThree); + mustEqual(minusThree, e1.getKey()); - Map.Entry e2 = map.ceilingEntry(zero); - assertEquals(m1, e2.getKey()); + Map.Entry e2 = map.ceilingEntry(zero); + mustEqual(minusOne, e2.getKey()); - Map.Entry e3 = map.ceilingEntry(m5); - assertEquals(m5, e3.getKey()); + Map.Entry e3 = map.ceilingEntry(minusFive); + mustEqual(minusFive, e3.getKey()); - Map.Entry e4 = map.ceilingEntry(m6); + Map.Entry e4 = map.ceilingEntry(minusSix); assertNull(e4); } @@ -864,21 +864,21 @@ public class TreeSubMapTest extends JSR1 * pollFirstEntry returns entries in order */ public void testDescendingPollFirstEntry() { - NavigableMap map = dmap5(); - Map.Entry e = map.pollFirstEntry(); - assertEquals(m1, e.getKey()); - assertEquals("A", e.getValue()); + NavigableMap map = dmap5(); + Map.Entry e = map.pollFirstEntry(); + mustEqual(minusOne, e.getKey()); + mustEqual("A", e.getValue()); e = map.pollFirstEntry(); - assertEquals(m2, e.getKey()); - map.put(m1, "A"); + mustEqual(minusTwo, e.getKey()); + map.put(minusOne, "A"); e = map.pollFirstEntry(); - assertEquals(m1, e.getKey()); - assertEquals("A", e.getValue()); + mustEqual(minusOne, e.getKey()); + mustEqual("A", e.getValue()); e = map.pollFirstEntry(); - assertEquals(m3, e.getKey()); - map.remove(m4); + mustEqual(minusThree, e.getKey()); + map.remove(minusFour); e = map.pollFirstEntry(); - assertEquals(m5, e.getKey()); + mustEqual(minusFive, e.getKey()); try { e.setValue("A"); shouldThrow(); @@ -891,21 +891,21 @@ public class TreeSubMapTest extends JSR1 * pollLastEntry returns entries in order */ public void testDescendingPollLastEntry() { - NavigableMap map = dmap5(); - Map.Entry e = map.pollLastEntry(); - assertEquals(m5, e.getKey()); - assertEquals("E", e.getValue()); + NavigableMap map = dmap5(); + Map.Entry e = map.pollLastEntry(); + mustEqual(minusFive, e.getKey()); + mustEqual("E", e.getValue()); e = map.pollLastEntry(); - assertEquals(m4, e.getKey()); - map.put(m5, "E"); + mustEqual(minusFour, e.getKey()); + map.put(minusFive, "E"); e = map.pollLastEntry(); - assertEquals(m5, e.getKey()); - assertEquals("E", e.getValue()); + mustEqual(minusFive, e.getKey()); + mustEqual("E", e.getValue()); e = map.pollLastEntry(); - assertEquals(m3, e.getKey()); - map.remove(m2); + mustEqual(minusThree, e.getKey()); + map.remove(minusTwo); e = map.pollLastEntry(); - assertEquals(m1, e.getKey()); + mustEqual(minusOne, e.getKey()); try { e.setValue("E"); shouldThrow(); @@ -918,17 +918,17 @@ public class TreeSubMapTest extends JSR1 * size returns the correct values */ public void testDescendingSize() { - NavigableMap map = dmap5(); - NavigableMap empty = dmap0(); - assertEquals(0, empty.size()); - assertEquals(5, map.size()); + NavigableMap map = dmap5(); + NavigableMap empty = dmap0(); + mustEqual(0, empty.size()); + mustEqual(5, map.size()); } /** * toString contains toString of elements */ public void testDescendingToString() { - NavigableMap map = dmap5(); + NavigableMap map = dmap5(); String s = map.toString(); for (int i = 1; i <= 5; ++i) { assertTrue(s.contains(String.valueOf(i))); @@ -941,7 +941,7 @@ public class TreeSubMapTest extends JSR1 * get(null) of nonempty map throws NPE */ public void testDescendingGet_NullPointerException() { - NavigableMap c = dmap5(); + NavigableMap c = dmap5(); try { c.get(null); shouldThrow(); @@ -952,7 +952,7 @@ public class TreeSubMapTest extends JSR1 * put(null,x) throws NPE */ public void testDescendingPut1_NullPointerException() { - NavigableMap c = dmap5(); + NavigableMap c = dmap5(); try { c.put(null, "whatever"); shouldThrow(); @@ -963,149 +963,149 @@ public class TreeSubMapTest extends JSR1 * A deserialized/reserialized map equals original */ public void testDescendingSerialization() throws Exception { - NavigableMap x = dmap5(); - NavigableMap y = serialClone(x); + NavigableMap x = dmap5(); + NavigableMap y = serialClone(x); assertNotSame(x, y); - assertEquals(x.size(), y.size()); - assertEquals(x.toString(), y.toString()); - assertEquals(x, y); - assertEquals(y, x); + mustEqual(x.size(), y.size()); + mustEqual(x.toString(), y.toString()); + mustEqual(x, y); + mustEqual(y, x); } /** * subMap returns map with keys in requested range */ public void testDescendingSubMapContents() { - NavigableMap map = dmap5(); - SortedMap sm = map.subMap(m2, m4); - assertEquals(m2, sm.firstKey()); - assertEquals(m3, sm.lastKey()); - assertEquals(2, sm.size()); - assertFalse(sm.containsKey(m1)); - assertTrue(sm.containsKey(m2)); - assertTrue(sm.containsKey(m3)); - assertFalse(sm.containsKey(m4)); - assertFalse(sm.containsKey(m5)); - Iterator i = sm.keySet().iterator(); - Object k; - k = (Integer)(i.next()); - assertEquals(m2, k); - k = (Integer)(i.next()); - assertEquals(m3, k); + NavigableMap map = dmap5(); + SortedMap sm = map.subMap(minusTwo, minusFour); + mustEqual(minusTwo, sm.firstKey()); + mustEqual(minusThree, sm.lastKey()); + mustEqual(2, sm.size()); + assertFalse(sm.containsKey(minusOne)); + assertTrue(sm.containsKey(minusTwo)); + assertTrue(sm.containsKey(minusThree)); + assertFalse(sm.containsKey(minusFour)); + assertFalse(sm.containsKey(minusFive)); + Iterator i = sm.keySet().iterator(); + Item k; + k = (Item)(i.next()); + mustEqual(minusTwo, k); + k = (Item)(i.next()); + mustEqual(minusThree, k); assertFalse(i.hasNext()); - Iterator j = sm.keySet().iterator(); + Iterator j = sm.keySet().iterator(); j.next(); j.remove(); - assertFalse(map.containsKey(m2)); - assertEquals(4, map.size()); - assertEquals(1, sm.size()); - assertEquals(m3, sm.firstKey()); - assertEquals(m3, sm.lastKey()); - assertEquals("C", sm.remove(m3)); + assertFalse(map.containsKey(minusTwo)); + mustEqual(4, map.size()); + mustEqual(1, sm.size()); + mustEqual(minusThree, sm.firstKey()); + mustEqual(minusThree, sm.lastKey()); + mustEqual("C", sm.remove(minusThree)); assertTrue(sm.isEmpty()); - assertEquals(3, map.size()); + mustEqual(3, map.size()); } public void testDescendingSubMapContents2() { - NavigableMap map = dmap5(); - SortedMap sm = map.subMap(m2, m3); - assertEquals(1, sm.size()); - assertEquals(m2, sm.firstKey()); - assertEquals(m2, sm.lastKey()); - assertFalse(sm.containsKey(m1)); - assertTrue(sm.containsKey(m2)); - assertFalse(sm.containsKey(m3)); - assertFalse(sm.containsKey(m4)); - assertFalse(sm.containsKey(m5)); - Iterator i = sm.keySet().iterator(); - Object k; - k = (Integer)(i.next()); - assertEquals(m2, k); + NavigableMap map = dmap5(); + SortedMap sm = map.subMap(minusTwo, minusThree); + mustEqual(1, sm.size()); + mustEqual(minusTwo, sm.firstKey()); + mustEqual(minusTwo, sm.lastKey()); + assertFalse(sm.containsKey(minusOne)); + assertTrue(sm.containsKey(minusTwo)); + assertFalse(sm.containsKey(minusThree)); + assertFalse(sm.containsKey(minusFour)); + assertFalse(sm.containsKey(minusFive)); + Iterator i = sm.keySet().iterator(); + Item k; + k = (Item)(i.next()); + mustEqual(minusTwo, k); assertFalse(i.hasNext()); - Iterator j = sm.keySet().iterator(); + Iterator j = sm.keySet().iterator(); j.next(); j.remove(); - assertFalse(map.containsKey(m2)); - assertEquals(4, map.size()); - assertEquals(0, sm.size()); + assertFalse(map.containsKey(minusTwo)); + mustEqual(4, map.size()); + mustEqual(0, sm.size()); assertTrue(sm.isEmpty()); - assertSame(sm.remove(m3), null); - assertEquals(4, map.size()); + assertNull(sm.remove(minusThree)); + mustEqual(4, map.size()); } /** * headMap returns map with keys in requested range */ public void testDescendingHeadMapContents() { - NavigableMap map = dmap5(); - SortedMap sm = map.headMap(m4); - assertTrue(sm.containsKey(m1)); - assertTrue(sm.containsKey(m2)); - assertTrue(sm.containsKey(m3)); - assertFalse(sm.containsKey(m4)); - assertFalse(sm.containsKey(m5)); - Iterator i = sm.keySet().iterator(); - Object k; - k = (Integer)(i.next()); - assertEquals(m1, k); - k = (Integer)(i.next()); - assertEquals(m2, k); - k = (Integer)(i.next()); - assertEquals(m3, k); + NavigableMap map = dmap5(); + SortedMap sm = map.headMap(minusFour); + assertTrue(sm.containsKey(minusOne)); + assertTrue(sm.containsKey(minusTwo)); + assertTrue(sm.containsKey(minusThree)); + assertFalse(sm.containsKey(minusFour)); + assertFalse(sm.containsKey(minusFive)); + Iterator i = sm.keySet().iterator(); + Item k; + k = (Item)(i.next()); + mustEqual(minusOne, k); + k = (Item)(i.next()); + mustEqual(minusTwo, k); + k = (Item)(i.next()); + mustEqual(minusThree, k); assertFalse(i.hasNext()); sm.clear(); assertTrue(sm.isEmpty()); - assertEquals(2, map.size()); - assertEquals(m4, map.firstKey()); + mustEqual(2, map.size()); + mustEqual(minusFour, map.firstKey()); } /** * headMap returns map with keys in requested range */ public void testDescendingTailMapContents() { - NavigableMap map = dmap5(); - SortedMap sm = map.tailMap(m2); - assertFalse(sm.containsKey(m1)); - assertTrue(sm.containsKey(m2)); - assertTrue(sm.containsKey(m3)); - assertTrue(sm.containsKey(m4)); - assertTrue(sm.containsKey(m5)); - Iterator i = sm.keySet().iterator(); - Object k; - k = (Integer)(i.next()); - assertEquals(m2, k); - k = (Integer)(i.next()); - assertEquals(m3, k); - k = (Integer)(i.next()); - assertEquals(m4, k); - k = (Integer)(i.next()); - assertEquals(m5, k); + NavigableMap map = dmap5(); + SortedMap sm = map.tailMap(minusTwo); + assertFalse(sm.containsKey(minusOne)); + assertTrue(sm.containsKey(minusTwo)); + assertTrue(sm.containsKey(minusThree)); + assertTrue(sm.containsKey(minusFour)); + assertTrue(sm.containsKey(minusFive)); + Iterator i = sm.keySet().iterator(); + Item k; + k = (Item)(i.next()); + mustEqual(minusTwo, k); + k = (Item)(i.next()); + mustEqual(minusThree, k); + k = (Item)(i.next()); + mustEqual(minusFour, k); + k = (Item)(i.next()); + mustEqual(minusFive, k); assertFalse(i.hasNext()); - Iterator ei = sm.entrySet().iterator(); - Map.Entry e; - e = (Map.Entry)(ei.next()); - assertEquals(m2, e.getKey()); - assertEquals("B", e.getValue()); - e = (Map.Entry)(ei.next()); - assertEquals(m3, e.getKey()); - assertEquals("C", e.getValue()); - e = (Map.Entry)(ei.next()); - assertEquals(m4, e.getKey()); - assertEquals("D", e.getValue()); - e = (Map.Entry)(ei.next()); - assertEquals(m5, e.getKey()); - assertEquals("E", e.getValue()); + Iterator> ei = sm.entrySet().iterator(); + Map.Entry e; + e = (ei.next()); + mustEqual(minusTwo, e.getKey()); + mustEqual("B", e.getValue()); + e = (ei.next()); + mustEqual(minusThree, e.getKey()); + mustEqual("C", e.getValue()); + e = (ei.next()); + mustEqual(minusFour, e.getKey()); + mustEqual("D", e.getValue()); + e = (ei.next()); + mustEqual(minusFive, e.getKey()); + mustEqual("E", e.getValue()); assertFalse(i.hasNext()); - SortedMap ssm = sm.tailMap(m4); - assertEquals(m4, ssm.firstKey()); - assertEquals(m5, ssm.lastKey()); - assertEquals("D", ssm.remove(m4)); - assertEquals(1, ssm.size()); - assertEquals(3, sm.size()); - assertEquals(4, map.size()); + SortedMap ssm = sm.tailMap(minusFour); + mustEqual(minusFour, ssm.firstKey()); + mustEqual(minusFive, ssm.lastKey()); + mustEqual("D", ssm.remove(minusFour)); + mustEqual(1, ssm.size()); + mustEqual(3, sm.size()); + mustEqual(4, map.size()); } }