--- jsr166/src/test/tck/TreeMapTest.java 2010/10/11 05:40:41 1.17 +++ jsr166/src/test/tck/TreeMapTest.java 2014/12/31 21:45:16 1.29 @@ -1,13 +1,23 @@ /* * 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.*; -import java.util.*; -import java.util.concurrent.*; -import java.io.*; +import java.util.Arrays; +import java.util.BitSet; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; +import java.util.NavigableMap; +import java.util.NavigableSet; +import java.util.NoSuchElementException; +import java.util.Random; +import java.util.Set; +import java.util.TreeMap; + +import junit.framework.Test; +import junit.framework.TestSuite; public class TreeMapTest extends JSR166TestCase { public static void main(String[] args) { @@ -18,7 +28,7 @@ public class TreeMapTest extends JSR166T } /** - * Create a map from Integers 1-5 to Strings "A"-"E". + * Returns a new map from Integers 1-5 to Strings "A"-"E". */ private static TreeMap map5() { TreeMap map = new TreeMap(); @@ -39,11 +49,11 @@ public class TreeMapTest extends JSR166T public void testClear() { TreeMap map = map5(); map.clear(); - assertEquals(map.size(), 0); + assertEquals(0, map.size()); } /** - * + * copy constructor creates map equal to source map */ public void testConstructFromSorted() { TreeMap map = map5(); @@ -119,7 +129,6 @@ public class TreeMapTest extends JSR166T assertEquals(five, map.lastKey()); } - /** * keySet.toArray returns contains all keys */ @@ -176,7 +185,7 @@ public class TreeMapTest extends JSR166T last = k; ++count; } - assertEquals(count ,5); + assertEquals(5, count); } /** @@ -195,7 +204,7 @@ public class TreeMapTest extends JSR166T last = k; ++count; } - assertEquals(count ,5); + assertEquals(5, count); } /** @@ -214,7 +223,7 @@ public class TreeMapTest extends JSR166T last = k; ++count; } - assertEquals(count, 5); + assertEquals(5, count); } /** @@ -233,7 +242,7 @@ public class TreeMapTest extends JSR166T last = k; ++count; } - assertEquals(count, 5); + assertEquals(5, count); } /** @@ -413,7 +422,6 @@ public class TreeMapTest extends JSR166T assertNull(e4); } - /** * lowerKey returns preceding element */ @@ -557,7 +565,7 @@ public class TreeMapTest extends JSR166T TreeMap map = map5(); String s = map.toString(); for (int i = 1; i <= 5; ++i) { - assertTrue(s.indexOf(String.valueOf(i)) >= 0); + assertTrue(s.contains(String.valueOf(i))); } } @@ -601,19 +609,14 @@ public class TreeMapTest extends JSR166T * A deserialized map equals original */ public void testSerialization() throws Exception { - TreeMap q = map5(); + NavigableMap x = map5(); + NavigableMap y = serialClone(x); - ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); - ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); - out.writeObject(q); - out.close(); - - ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); - ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); - TreeMap r = (TreeMap)in.readObject(); - assertEquals(q.size(), r.size()); - assertTrue(q.equals(r)); - assertTrue(r.equals(q)); + assertNotSame(x, y); + assertEquals(x.size(), y.size()); + assertEquals(x.toString(), y.toString()); + assertEquals(x, y); + assertEquals(y, x); } /** @@ -800,7 +803,7 @@ public class TreeMapTest extends JSR166T static NavigableMap newMap(Class cl) throws Exception { NavigableMap result = (NavigableMap) cl.newInstance(); - assertEquals(result.size(), 0); + assertEquals(0, result.size()); assertFalse(result.keySet().iterator().hasNext()); return result; } @@ -832,7 +835,7 @@ public class TreeMapTest extends JSR166T // Add entries till we're back to original size while (map.size() < size) { int key = min + rnd.nextInt(rangeSize); - assertTrue(key >= min && key<= max); + assertTrue(key >= min && key <= max); put(map, key); } } @@ -857,7 +860,7 @@ public class TreeMapTest extends JSR166T // Add entries till we're back to original size while (map.size() < size) { int key = min - 5 + rnd.nextInt(rangeSize + 10); - if (key >= min && key<= max) { + if (key >= min && key <= max) { put(map, key); } else { try { @@ -961,7 +964,7 @@ public class TreeMapTest extends JSR166T */ void check(NavigableMap map, final int min, final int max, final boolean ascending) { - class ReferenceSet { + class ReferenceSet { int lower(int key) { return ascending ? lowerAscending(key) : higherAscending(key); } @@ -1027,7 +1030,7 @@ public class TreeMapTest extends JSR166T if (bsContainsI) size++; } - assertEquals(map.size(), size); + assertEquals(size, map.size()); // Test contents using contains keySet iterator int size2 = 0;