ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/TreeMapTest.java
(Generate patch)

Comparing jsr166/src/test/tck/TreeMapTest.java (file contents):
Revision 1.14 by jsr166, Wed Aug 25 00:07:03 2010 UTC vs.
Revision 1.21 by jsr166, Tue May 31 16:16:24 2011 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7   import junit.framework.*;
8   import java.util.*;
9 import java.util.concurrent.*;
10 import java.io.*;
9  
10   public class TreeMapTest extends JSR166TestCase {
11      public static void main(String[] args) {
# Line 34 | Line 32 | public class TreeMapTest extends JSR166T
32      }
33  
34      /**
35 <     *  clear removes all pairs
35 >     * clear removes all pairs
36       */
37      public void testClear() {
38          TreeMap map = map5();
# Line 52 | Line 50 | public class TreeMapTest extends JSR166T
50      }
51  
52      /**
53 <     *  Maps with same contents are equal
53 >     * Maps with same contents are equal
54       */
55      public void testEquals() {
56          TreeMap map1 = map5();
# Line 65 | Line 63 | public class TreeMapTest extends JSR166T
63      }
64  
65      /**
66 <     *  containsKey returns true for contained key
66 >     * containsKey returns true for contained key
67       */
68      public void testContainsKey() {
69          TreeMap map = map5();
# Line 74 | Line 72 | public class TreeMapTest extends JSR166T
72      }
73  
74      /**
75 <     *  containsValue returns true for held values
75 >     * containsValue returns true for held values
76       */
77      public void testContainsValue() {
78          TreeMap map = map5();
# Line 83 | Line 81 | public class TreeMapTest extends JSR166T
81      }
82  
83      /**
84 <     *  get returns the correct element at the given key,
85 <     *  or null if not present
84 >     * get returns the correct element at the given key,
85 >     * or null if not present
86       */
87      public void testGet() {
88          TreeMap map = map5();
# Line 94 | Line 92 | public class TreeMapTest extends JSR166T
92      }
93  
94      /**
95 <     *  isEmpty is true of empty map and false for non-empty
95 >     * isEmpty is true of empty map and false for non-empty
96       */
97      public void testIsEmpty() {
98          TreeMap empty = new TreeMap();
# Line 104 | Line 102 | public class TreeMapTest extends JSR166T
102      }
103  
104      /**
105 <     *   firstKey returns first key
105 >     * firstKey returns first key
106       */
107      public void testFirstKey() {
108          TreeMap map = map5();
# Line 112 | Line 110 | public class TreeMapTest extends JSR166T
110      }
111  
112      /**
113 <     *   lastKey returns last key
113 >     * lastKey returns last key
114       */
115      public void testLastKey() {
116          TreeMap map = map5();
117          assertEquals(five, map.lastKey());
118      }
119  
122
120      /**
121 <     *  keySet.toArray returns contains all keys
121 >     * keySet.toArray returns contains all keys
122       */
123      public void testKeySetToArray() {
124          TreeMap map = map5();
# Line 134 | Line 131 | public class TreeMapTest extends JSR166T
131      }
132  
133      /**
134 <     *  descendingkeySet.toArray returns contains all keys
134 >     * descendingkeySet.toArray returns contains all keys
135       */
136      public void testDescendingKeySetToArray() {
137          TreeMap map = map5();
# Line 147 | Line 144 | public class TreeMapTest extends JSR166T
144      }
145  
146      /**
147 <     *   keySet returns a Set containing all the keys
147 >     * keySet returns a Set containing all the keys
148       */
149      public void testKeySet() {
150          TreeMap map = map5();
# Line 161 | Line 158 | public class TreeMapTest extends JSR166T
158      }
159  
160      /**
161 <     *   keySet is ordered
161 >     * keySet is ordered
162       */
163      public void testKeySetOrder() {
164          TreeMap map = map5();
# Line 199 | Line 196 | public class TreeMapTest extends JSR166T
196      }
197  
198      /**
199 <     *   descendingKeySet is ordered
199 >     * descendingKeySet is ordered
200       */
201      public void testDescendingKeySetOrder() {
202          TreeMap map = map5();
# Line 218 | Line 215 | public class TreeMapTest extends JSR166T
215      }
216  
217      /**
218 <     *  descending iterator of descendingKeySet is ordered
218 >     * descending iterator of descendingKeySet is ordered
219       */
220      public void testDescendingKeySetDescendingIteratorOrder() {
221          TreeMap map = map5();
# Line 289 | Line 286 | public class TreeMapTest extends JSR166T
286      }
287  
288      /**
289 <     *  entrySet.toArray contains all entries
289 >     * entrySet.toArray contains all entries
290       */
291      public void testEntrySetToArray() {
292          TreeMap map = map5();
# Line 303 | Line 300 | public class TreeMapTest extends JSR166T
300      }
301  
302      /**
303 <     *  descendingEntrySet.toArray contains all entries
303 >     * descendingEntrySet.toArray contains all entries
304       */
305      public void testDescendingEntrySetToArray() {
306          TreeMap map = map5();
# Line 317 | Line 314 | public class TreeMapTest extends JSR166T
314      }
315  
316      /**
317 <     *   putAll  adds all key-value pairs from the given map
317 >     * putAll adds all key-value pairs from the given map
318       */
319      public void testPutAll() {
320          TreeMap empty = new TreeMap();
# Line 332 | Line 329 | public class TreeMapTest extends JSR166T
329      }
330  
331      /**
332 <     *   remove removes the correct key-value pair from the map
332 >     * remove removes the correct key-value pair from the map
333       */
334      public void testRemove() {
335          TreeMap map = map5();
# Line 413 | Line 410 | public class TreeMapTest extends JSR166T
410          assertNull(e4);
411      }
412  
416
413      /**
414       * lowerKey returns preceding element
415       */
# Line 541 | Line 537 | public class TreeMapTest extends JSR166T
537      }
538  
539      /**
540 <     *   size returns the correct values
540 >     * size returns the correct values
541       */
542      public void testSize() {
543          TreeMap map = map5();
# Line 557 | Line 553 | public class TreeMapTest extends JSR166T
553          TreeMap map = map5();
554          String s = map.toString();
555          for (int i = 1; i <= 5; ++i) {
556 <            assertTrue(s.indexOf(String.valueOf(i)) >= 0);
556 >            assertTrue(s.contains(String.valueOf(i)));
557          }
558      }
559  
# Line 601 | Line 597 | public class TreeMapTest extends JSR166T
597       * A deserialized map equals original
598       */
599      public void testSerialization() throws Exception {
600 <        TreeMap q = map5();
600 >        NavigableMap x = map5();
601 >        NavigableMap y = serialClone(x);
602  
603 <        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
604 <        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
605 <        out.writeObject(q);
606 <        out.close();
607 <
611 <        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
612 <        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
613 <        TreeMap r = (TreeMap)in.readObject();
614 <        assertEquals(q.size(), r.size());
615 <        assertTrue(q.equals(r));
616 <        assertTrue(r.equals(q));
603 >        assertTrue(x != y);
604 >        assertEquals(x.size(), y.size());
605 >        assertEquals(x.toString(), y.toString());
606 >        assertEquals(x, y);
607 >        assertEquals(y, x);
608      }
609  
610      /**
# Line 780 | Line 771 | public class TreeMapTest extends JSR166T
771       * Submaps of submaps subdivide correctly
772       */
773      public void testRecursiveSubMaps() throws Exception {
774 <        int mapSize = 1000;
774 >        int mapSize = expensiveTests ? 1000 : 100;
775          Class cl = TreeMap.class;
776          NavigableMap<Integer, Integer> map = newMap(cl);
777          bs = new BitSet(mapSize);
# Line 961 | Line 952 | public class TreeMapTest extends JSR166T
952       */
953      void check(NavigableMap<Integer, Integer> map,
954                        final int min, final int max, final boolean ascending) {
955 <       class ReferenceSet {
955 >        class ReferenceSet {
956              int lower(int key) {
957                  return ascending ? lowerAscending(key) : higherAscending(key);
958              }
# Line 992 | Line 983 | public class TreeMapTest extends JSR166T
983                  // BitSet should support this! Test would run much faster
984                  while (key >= min) {
985                      if (bs.get(key))
986 <                        return(key);
986 >                        return key;
987                      key--;
988                  }
989                  return -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines