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

Comparing jsr166/src/test/tck/TreeSubMapTest.java (file contents):
Revision 1.11 by jsr166, Tue Dec 1 09:44:58 2009 UTC vs.
Revision 1.20 by jsr166, Thu May 30 03:28:55 2013 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 TreeSubMapTest extends JSR166TestCase {
11      public static void main(String[] args) {
12 <        junit.textui.TestRunner.run (suite());
12 >        junit.textui.TestRunner.run(suite());
13      }
14      public static Test suite() {
15          return new TestSuite(TreeSubMapTest.class);
16      }
17  
18      /**
19 <     * Create a map from Integers 1-5 to Strings "A"-"E".
19 >     * Returns a new map from Integers 1-5 to Strings "A"-"E".
20       */
21      private static NavigableMap map5() {
22          TreeMap map = new TreeMap();
# Line 42 | Line 40 | public class TreeSubMapTest extends JSR1
40      }
41  
42      /**
43 <     * Create a map from Integers -5 to -1 to Strings "A"-"E".
43 >     * Returns a new map from Integers -5 to -1 to Strings "A"-"E".
44       */
45      private static NavigableMap dmap5() {
46          TreeMap map = new TreeMap();
# Line 64 | Line 62 | public class TreeSubMapTest extends JSR1
62      }
63  
64      /**
65 <     *  clear removes all pairs
65 >     * clear removes all pairs
66       */
67      public void testClear() {
68          NavigableMap map = map5();
69          map.clear();
70 <        assertEquals(map.size(), 0);
70 >        assertEquals(0, map.size());
71      }
72  
75
73      /**
74 <     *  Maps with same contents are equal
74 >     * Maps with same contents are equal
75       */
76      public void testEquals() {
77          NavigableMap map1 = map5();
# Line 87 | Line 84 | public class TreeSubMapTest extends JSR1
84      }
85  
86      /**
87 <     *  containsKey returns true for contained key
87 >     * containsKey returns true for contained key
88       */
89      public void testContainsKey() {
90          NavigableMap map = map5();
# Line 96 | Line 93 | public class TreeSubMapTest extends JSR1
93      }
94  
95      /**
96 <     *  containsValue returns true for held values
96 >     * containsValue returns true for held values
97       */
98      public void testContainsValue() {
99          NavigableMap map = map5();
# Line 105 | Line 102 | public class TreeSubMapTest extends JSR1
102      }
103  
104      /**
105 <     *  get returns the correct element at the given key,
106 <     *  or null if not present
105 >     * get returns the correct element at the given key,
106 >     * or null if not present
107       */
108      public void testGet() {
109          NavigableMap map = map5();
# Line 116 | Line 113 | public class TreeSubMapTest extends JSR1
113      }
114  
115      /**
116 <     *  isEmpty is true of empty map and false for non-empty
116 >     * isEmpty is true of empty map and false for non-empty
117       */
118      public void testIsEmpty() {
119          NavigableMap empty = map0();
# Line 126 | Line 123 | public class TreeSubMapTest extends JSR1
123      }
124  
125      /**
126 <     *   firstKey returns first key
126 >     * firstKey returns first key
127       */
128      public void testFirstKey() {
129          NavigableMap map = map5();
# Line 134 | Line 131 | public class TreeSubMapTest extends JSR1
131      }
132  
133      /**
134 <     *   lastKey returns last key
134 >     * lastKey returns last key
135       */
136      public void testLastKey() {
137          NavigableMap map = map5();
138          assertEquals(five, map.lastKey());
139      }
140  
144
141      /**
142 <     *   keySet returns a Set containing all the keys
142 >     * keySet returns a Set containing all the keys
143       */
144      public void testKeySet() {
145          NavigableMap map = map5();
# Line 157 | Line 153 | public class TreeSubMapTest extends JSR1
153      }
154  
155      /**
156 <     *   keySet is ordered
156 >     * keySet is ordered
157       */
158      public void testKeySetOrder() {
159          NavigableMap map = map5();
# Line 206 | Line 202 | public class TreeSubMapTest extends JSR1
202      }
203  
204      /**
205 <     *   putAll  adds all key-value pairs from the given map
205 >     * putAll adds all key-value pairs from the given map
206       */
207      public void testPutAll() {
208          NavigableMap empty = map0();
# Line 221 | Line 217 | public class TreeSubMapTest extends JSR1
217      }
218  
219      /**
220 <     *   remove removes the correct key-value pair from the map
220 >     * remove removes the correct key-value pair from the map
221       */
222      public void testRemove() {
223          NavigableMap map = map5();
# Line 360 | Line 356 | public class TreeSubMapTest extends JSR1
356      }
357  
358      /**
359 <     *   size returns the correct values
359 >     * size returns the correct values
360       */
361      public void testSize() {
362          NavigableMap map = map5();
# Line 376 | Line 372 | public class TreeSubMapTest extends JSR1
372          NavigableMap map = map5();
373          String s = map.toString();
374          for (int i = 1; i <= 5; ++i) {
375 <            assertTrue(s.indexOf(String.valueOf(i)) >= 0);
375 >            assertTrue(s.contains(String.valueOf(i)));
376          }
377      }
378  
# Line 430 | Line 426 | public class TreeSubMapTest extends JSR1
426       * A deserialized map equals original
427       */
428      public void testSerialization() throws Exception {
429 <        NavigableMap q = map5();
429 >        NavigableMap x = map5();
430 >        NavigableMap y = serialClone(x);
431  
432 <        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
433 <        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
434 <        out.writeObject(q);
435 <        out.close();
436 <
440 <        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
441 <        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
442 <        NavigableMap r = (NavigableMap)in.readObject();
443 <        assertFalse(r.isEmpty());
444 <        assertEquals(q.size(), r.size());
445 <        assertTrue(q.equals(r));
446 <        assertTrue(r.equals(q));
432 >        assertNotSame(x, y);
433 >        assertEquals(x.size(), y.size());
434 >        assertEquals(x.toString(), y.toString());
435 >        assertEquals(x, y);
436 >        assertEquals(y, x);
437      }
438  
449
450
439      /**
440       * subMap returns map with keys in requested range
441       */
# Line 584 | Line 572 | public class TreeSubMapTest extends JSR1
572      }
573  
574      /**
575 <     *  clear removes all pairs
575 >     * clear removes all pairs
576       */
577      public void testDescendingClear() {
578          NavigableMap map = dmap5();
579          map.clear();
580 <        assertEquals(map.size(), 0);
580 >        assertEquals(0, map.size());
581      }
582  
595
583      /**
584 <     *  Maps with same contents are equal
584 >     * Maps with same contents are equal
585       */
586      public void testDescendingEquals() {
587          NavigableMap map1 = dmap5();
# Line 607 | Line 594 | public class TreeSubMapTest extends JSR1
594      }
595  
596      /**
597 <     *  containsKey returns true for contained key
597 >     * containsKey returns true for contained key
598       */
599      public void testDescendingContainsKey() {
600          NavigableMap map = dmap5();
# Line 616 | Line 603 | public class TreeSubMapTest extends JSR1
603      }
604  
605      /**
606 <     *  containsValue returns true for held values
606 >     * containsValue returns true for held values
607       */
608      public void testDescendingContainsValue() {
609          NavigableMap map = dmap5();
# Line 625 | Line 612 | public class TreeSubMapTest extends JSR1
612      }
613  
614      /**
615 <     *  get returns the correct element at the given key,
616 <     *  or null if not present
615 >     * get returns the correct element at the given key,
616 >     * or null if not present
617       */
618      public void testDescendingGet() {
619          NavigableMap map = dmap5();
# Line 636 | Line 623 | public class TreeSubMapTest extends JSR1
623      }
624  
625      /**
626 <     *  isEmpty is true of empty map and false for non-empty
626 >     * isEmpty is true of empty map and false for non-empty
627       */
628      public void testDescendingIsEmpty() {
629          NavigableMap empty = dmap0();
# Line 646 | Line 633 | public class TreeSubMapTest extends JSR1
633      }
634  
635      /**
636 <     *   firstKey returns first key
636 >     * firstKey returns first key
637       */
638      public void testDescendingFirstKey() {
639          NavigableMap map = dmap5();
# Line 654 | Line 641 | public class TreeSubMapTest extends JSR1
641      }
642  
643      /**
644 <     *   lastKey returns last key
644 >     * lastKey returns last key
645       */
646      public void testDescendingLastKey() {
647          NavigableMap map = dmap5();
648          assertEquals(m5, map.lastKey());
649      }
650  
664
651      /**
652 <     *   keySet returns a Set containing all the keys
652 >     * keySet returns a Set containing all the keys
653       */
654      public void testDescendingKeySet() {
655          NavigableMap map = dmap5();
# Line 677 | Line 663 | public class TreeSubMapTest extends JSR1
663      }
664  
665      /**
666 <     *   keySet is ordered
666 >     * keySet is ordered
667       */
668      public void testDescendingKeySetOrder() {
669          NavigableMap map = dmap5();
# Line 707 | Line 693 | public class TreeSubMapTest extends JSR1
693      }
694  
695      /**
696 <     *  keySet.toArray returns contains all keys
696 >     * keySet.toArray returns contains all keys
697       */
698      public void testDescendingAscendingKeySetToArray() {
699          NavigableMap map = dmap5();
# Line 720 | Line 706 | public class TreeSubMapTest extends JSR1
706      }
707  
708      /**
709 <     *  descendingkeySet.toArray returns contains all keys
709 >     * descendingkeySet.toArray returns contains all keys
710       */
711      public void testDescendingDescendingKeySetToArray() {
712          NavigableMap map = dmap5();
# Line 733 | Line 719 | public class TreeSubMapTest extends JSR1
719      }
720  
721      /**
722 <     *  Values.toArray contains all values
722 >     * Values.toArray contains all values
723       */
724      public void testDescendingValuesToArray() {
725          NavigableMap map = dmap5();
# Line 748 | Line 734 | public class TreeSubMapTest extends JSR1
734          assertTrue(s.contains("E"));
735      }
736  
751
737      /**
738       * entrySet contains all pairs
739       */
# Line 769 | Line 754 | public class TreeSubMapTest extends JSR1
754      }
755  
756      /**
757 <     *   putAll  adds all key-value pairs from the given map
757 >     * putAll adds all key-value pairs from the given map
758       */
759      public void testDescendingPutAll() {
760          NavigableMap empty = dmap0();
# Line 783 | Line 768 | public class TreeSubMapTest extends JSR1
768          assertTrue(empty.containsKey(m5));
769      }
770  
786
771      /**
772 <     *   remove removes the correct key-value pair from the map
772 >     * remove removes the correct key-value pair from the map
773       */
774      public void testDescendingRemove() {
775          NavigableMap map = dmap5();
# Line 921 | Line 905 | public class TreeSubMapTest extends JSR1
905      }
906  
907      /**
908 <     *   size returns the correct values
908 >     * size returns the correct values
909       */
910      public void testDescendingSize() {
911          NavigableMap map = dmap5();
# Line 937 | Line 921 | public class TreeSubMapTest extends JSR1
921          NavigableMap map = dmap5();
922          String s = map.toString();
923          for (int i = 1; i <= 5; ++i) {
924 <            assertTrue(s.indexOf(String.valueOf(i)) >= 0);
924 >            assertTrue(s.contains(String.valueOf(i)));
925          }
926      }
927  
# Line 969 | Line 953 | public class TreeSubMapTest extends JSR1
953       * A deserialized map equals original
954       */
955      public void testDescendingSerialization() throws Exception {
956 <        NavigableMap q = dmap5();
956 >        NavigableMap x = dmap5();
957 >        NavigableMap y = serialClone(x);
958  
959 <        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
960 <        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
961 <        out.writeObject(q);
962 <        out.close();
963 <
979 <        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
980 <        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
981 <        NavigableMap r = (NavigableMap)in.readObject();
982 <        assertEquals(q.size(), r.size());
983 <        assertTrue(q.equals(r));
984 <        assertTrue(r.equals(q));
959 >        assertNotSame(x, y);
960 >        assertEquals(x.size(), y.size());
961 >        assertEquals(x.toString(), y.toString());
962 >        assertEquals(x, y);
963 >        assertEquals(y, x);
964      }
965  
987
966      /**
967       * subMap returns map with keys in requested range
968       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines