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.8 by jsr166, Sat Nov 21 10:25:05 2009 UTC vs.
Revision 1.15 by jsr166, Fri May 27 19:10:32 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.*;
# Line 11 | Line 11 | import java.io.*;
11  
12   public class TreeSubMapTest extends JSR166TestCase {
13      public static void main(String[] args) {
14 <        junit.textui.TestRunner.run (suite());
14 >        junit.textui.TestRunner.run(suite());
15      }
16      public static Test suite() {
17          return new TestSuite(TreeSubMapTest.class);
# Line 64 | Line 64 | public class TreeSubMapTest extends JSR1
64      }
65  
66      /**
67 <     *  clear removes all pairs
67 >     * clear removes all pairs
68       */
69      public void testClear() {
70          NavigableMap map = map5();
# Line 74 | Line 74 | public class TreeSubMapTest extends JSR1
74  
75  
76      /**
77 <     *  Maps with same contents are equal
77 >     * Maps with same contents are equal
78       */
79      public void testEquals() {
80          NavigableMap map1 = map5();
# Line 87 | Line 87 | public class TreeSubMapTest extends JSR1
87      }
88  
89      /**
90 <     *  containsKey returns true for contained key
90 >     * containsKey returns true for contained key
91       */
92      public void testContainsKey() {
93          NavigableMap map = map5();
# Line 96 | Line 96 | public class TreeSubMapTest extends JSR1
96      }
97  
98      /**
99 <     *  containsValue returns true for held values
99 >     * containsValue returns true for held values
100       */
101      public void testContainsValue() {
102          NavigableMap map = map5();
# Line 105 | Line 105 | public class TreeSubMapTest extends JSR1
105      }
106  
107      /**
108 <     *  get returns the correct element at the given key,
109 <     *  or null if not present
108 >     * get returns the correct element at the given key,
109 >     * or null if not present
110       */
111      public void testGet() {
112          NavigableMap map = map5();
# Line 116 | Line 116 | public class TreeSubMapTest extends JSR1
116      }
117  
118      /**
119 <     *  isEmpty is true of empty map and false for non-empty
119 >     * isEmpty is true of empty map and false for non-empty
120       */
121      public void testIsEmpty() {
122          NavigableMap empty = map0();
# Line 126 | Line 126 | public class TreeSubMapTest extends JSR1
126      }
127  
128      /**
129 <     *   firstKey returns first key
129 >     * firstKey returns first key
130       */
131      public void testFirstKey() {
132          NavigableMap map = map5();
# Line 134 | Line 134 | public class TreeSubMapTest extends JSR1
134      }
135  
136      /**
137 <     *   lastKey returns last key
137 >     * lastKey returns last key
138       */
139      public void testLastKey() {
140          NavigableMap map = map5();
# Line 143 | Line 143 | public class TreeSubMapTest extends JSR1
143  
144  
145      /**
146 <     *   keySet returns a Set containing all the keys
146 >     * keySet returns a Set containing all the keys
147       */
148      public void testKeySet() {
149          NavigableMap map = map5();
# Line 157 | Line 157 | public class TreeSubMapTest extends JSR1
157      }
158  
159      /**
160 <     *   keySet is ordered
160 >     * keySet is ordered
161       */
162      public void testKeySetOrder() {
163          NavigableMap map = map5();
# Line 206 | Line 206 | public class TreeSubMapTest extends JSR1
206      }
207  
208      /**
209 <     *   putAll  adds all key-value pairs from the given map
209 >     * putAll adds all key-value pairs from the given map
210       */
211      public void testPutAll() {
212          NavigableMap empty = map0();
# Line 221 | Line 221 | public class TreeSubMapTest extends JSR1
221      }
222  
223      /**
224 <     *   remove removes the correct key-value pair from the map
224 >     * remove removes the correct key-value pair from the map
225       */
226      public void testRemove() {
227          NavigableMap map = map5();
# Line 246 | Line 246 | public class TreeSubMapTest extends JSR1
246  
247          Map.Entry e4 = map.lowerEntry(zero);
248          assertNull(e4);
249
249      }
250  
251      /**
# Line 265 | Line 264 | public class TreeSubMapTest extends JSR1
264  
265          Map.Entry e4 = map.higherEntry(six);
266          assertNull(e4);
268
267      }
268  
269      /**
# Line 284 | Line 282 | public class TreeSubMapTest extends JSR1
282  
283          Map.Entry e4 = map.floorEntry(zero);
284          assertNull(e4);
287
285      }
286  
287      /**
# Line 303 | Line 300 | public class TreeSubMapTest extends JSR1
300  
301          Map.Entry e4 = map.ceilingEntry(six);
302          assertNull(e4);
306
303      }
304  
305      /**
# Line 328 | Line 324 | public class TreeSubMapTest extends JSR1
324          try {
325              e.setValue("A");
326              shouldThrow();
327 <        } catch (Exception ok) {
332 <        }
327 >        } catch (UnsupportedOperationException success) {}
328          assertTrue(map.isEmpty());
329          Map.Entry f = map.firstEntry();
330          assertNull(f);
# Line 359 | Line 354 | public class TreeSubMapTest extends JSR1
354          try {
355              e.setValue("E");
356              shouldThrow();
357 <        } catch (Exception ok) {
363 <        }
357 >        } catch (UnsupportedOperationException success) {}
358          e = map.pollLastEntry();
359          assertNull(e);
360      }
361  
362      /**
363 <     *   size returns the correct values
363 >     * size returns the correct values
364       */
365      public void testSize() {
366          NavigableMap map = map5();
# Line 382 | Line 376 | public class TreeSubMapTest extends JSR1
376          NavigableMap map = map5();
377          String s = map.toString();
378          for (int i = 1; i <= 5; ++i) {
379 <            assertTrue(s.indexOf(String.valueOf(i)) >= 0);
379 >            assertTrue(s.contains(String.valueOf(i)));
380          }
381      }
382  
# Line 396 | Line 390 | public class TreeSubMapTest extends JSR1
390              NavigableMap c = map5();
391              c.get(null);
392              shouldThrow();
393 <        } catch (NullPointerException e) {}
393 >        } catch (NullPointerException success) {}
394      }
395  
396      /**
# Line 407 | Line 401 | public class TreeSubMapTest extends JSR1
401              NavigableMap c = map5();
402              c.containsKey(null);
403              shouldThrow();
404 <        } catch (NullPointerException e) {}
404 >        } catch (NullPointerException success) {}
405      }
406  
407      /**
# Line 418 | Line 412 | public class TreeSubMapTest extends JSR1
412              NavigableMap c = map5();
413              c.put(null, "whatever");
414              shouldThrow();
415 <        } catch (NullPointerException e) {}
415 >        } catch (NullPointerException success) {}
416      }
417  
418      /**
# Line 429 | Line 423 | public class TreeSubMapTest extends JSR1
423              NavigableMap c = map5();
424              c.remove(null);
425              shouldThrow();
426 <        } catch (NullPointerException e) {}
426 >        } catch (NullPointerException success) {}
427      }
428  
429      /**
# Line 483 | Line 477 | public class TreeSubMapTest extends JSR1
477          assertEquals(1, sm.size());
478          assertEquals(three, sm.firstKey());
479          assertEquals(three, sm.lastKey());
480 <        assertTrue(sm.remove(three) != null);
480 >        assertEquals("C", sm.remove(three));
481          assertTrue(sm.isEmpty());
482          assertEquals(3, map.size());
483      }
# Line 511 | Line 505 | public class TreeSubMapTest extends JSR1
505          assertEquals(4, map.size());
506          assertEquals(0, sm.size());
507          assertTrue(sm.isEmpty());
508 <        assertTrue(sm.remove(three) == null);
508 >        assertSame(sm.remove(three), null);
509          assertEquals(4, map.size());
510      }
511  
# Line 583 | Line 577 | public class TreeSubMapTest extends JSR1
577          SortedMap ssm = sm.tailMap(four);
578          assertEquals(four, ssm.firstKey());
579          assertEquals(five, ssm.lastKey());
580 <        assertTrue(ssm.remove(four) != null);
580 >        assertEquals("D", ssm.remove(four));
581          assertEquals(1, ssm.size());
582          assertEquals(3, sm.size());
583          assertEquals(4, map.size());
584      }
585  
586      /**
587 <     *  clear removes all pairs
587 >     * clear removes all pairs
588       */
589      public void testDescendingClear() {
590          NavigableMap map = dmap5();
# Line 600 | Line 594 | public class TreeSubMapTest extends JSR1
594  
595  
596      /**
597 <     *  Maps with same contents are equal
597 >     * Maps with same contents are equal
598       */
599      public void testDescendingEquals() {
600          NavigableMap map1 = dmap5();
# Line 613 | Line 607 | public class TreeSubMapTest extends JSR1
607      }
608  
609      /**
610 <     *  containsKey returns true for contained key
610 >     * containsKey returns true for contained key
611       */
612      public void testDescendingContainsKey() {
613          NavigableMap map = dmap5();
# Line 622 | Line 616 | public class TreeSubMapTest extends JSR1
616      }
617  
618      /**
619 <     *  containsValue returns true for held values
619 >     * containsValue returns true for held values
620       */
621      public void testDescendingContainsValue() {
622          NavigableMap map = dmap5();
# Line 631 | Line 625 | public class TreeSubMapTest extends JSR1
625      }
626  
627      /**
628 <     *  get returns the correct element at the given key,
629 <     *  or null if not present
628 >     * get returns the correct element at the given key,
629 >     * or null if not present
630       */
631      public void testDescendingGet() {
632          NavigableMap map = dmap5();
# Line 642 | Line 636 | public class TreeSubMapTest extends JSR1
636      }
637  
638      /**
639 <     *  isEmpty is true of empty map and false for non-empty
639 >     * isEmpty is true of empty map and false for non-empty
640       */
641      public void testDescendingIsEmpty() {
642          NavigableMap empty = dmap0();
# Line 652 | Line 646 | public class TreeSubMapTest extends JSR1
646      }
647  
648      /**
649 <     *   firstKey returns first key
649 >     * firstKey returns first key
650       */
651      public void testDescendingFirstKey() {
652          NavigableMap map = dmap5();
# Line 660 | Line 654 | public class TreeSubMapTest extends JSR1
654      }
655  
656      /**
657 <     *   lastKey returns last key
657 >     * lastKey returns last key
658       */
659      public void testDescendingLastKey() {
660          NavigableMap map = dmap5();
# Line 669 | Line 663 | public class TreeSubMapTest extends JSR1
663  
664  
665      /**
666 <     *   keySet returns a Set containing all the keys
666 >     * keySet returns a Set containing all the keys
667       */
668      public void testDescendingKeySet() {
669          NavigableMap map = dmap5();
# Line 683 | Line 677 | public class TreeSubMapTest extends JSR1
677      }
678  
679      /**
680 <     *   keySet is ordered
680 >     * keySet is ordered
681       */
682      public void testDescendingKeySetOrder() {
683          NavigableMap map = dmap5();
# Line 713 | Line 707 | public class TreeSubMapTest extends JSR1
707      }
708  
709      /**
710 <     *  keySet.toArray returns contains all keys
710 >     * keySet.toArray returns contains all keys
711       */
712      public void testDescendingAscendingKeySetToArray() {
713          NavigableMap map = dmap5();
# Line 726 | Line 720 | public class TreeSubMapTest extends JSR1
720      }
721  
722      /**
723 <     *  descendingkeySet.toArray returns contains all keys
723 >     * descendingkeySet.toArray returns contains all keys
724       */
725      public void testDescendingDescendingKeySetToArray() {
726          NavigableMap map = dmap5();
# Line 739 | Line 733 | public class TreeSubMapTest extends JSR1
733      }
734  
735      /**
736 <     *  Values.toArray contains all values
736 >     * Values.toArray contains all values
737       */
738      public void testDescendingValuesToArray() {
739          NavigableMap map = dmap5();
# Line 775 | Line 769 | public class TreeSubMapTest extends JSR1
769      }
770  
771      /**
772 <     *   putAll  adds all key-value pairs from the given map
772 >     * putAll adds all key-value pairs from the given map
773       */
774      public void testDescendingPutAll() {
775          NavigableMap empty = dmap0();
# Line 791 | Line 785 | public class TreeSubMapTest extends JSR1
785  
786  
787      /**
788 <     *   remove removes the correct key-value pair from the map
788 >     * remove removes the correct key-value pair from the map
789       */
790      public void testDescendingRemove() {
791          NavigableMap map = dmap5();
# Line 816 | Line 810 | public class TreeSubMapTest extends JSR1
810  
811          Map.Entry e4 = map.lowerEntry(zero);
812          assertNull(e4);
819
813      }
814  
815      /**
# Line 835 | Line 828 | public class TreeSubMapTest extends JSR1
828  
829          Map.Entry e4 = map.higherEntry(m6);
830          assertNull(e4);
838
831      }
832  
833      /**
# Line 854 | Line 846 | public class TreeSubMapTest extends JSR1
846  
847          Map.Entry e4 = map.floorEntry(zero);
848          assertNull(e4);
857
849      }
850  
851      /**
# Line 873 | Line 864 | public class TreeSubMapTest extends JSR1
864  
865          Map.Entry e4 = map.ceilingEntry(m6);
866          assertNull(e4);
876
867      }
868  
869      /**
# Line 898 | Line 888 | public class TreeSubMapTest extends JSR1
888          try {
889              e.setValue("A");
890              shouldThrow();
891 <        } catch (Exception ok) {
902 <        }
891 >        } catch (UnsupportedOperationException success) {}
892          e = map.pollFirstEntry();
893          assertNull(e);
894      }
# Line 926 | Line 915 | public class TreeSubMapTest extends JSR1
915          try {
916              e.setValue("E");
917              shouldThrow();
918 <        } catch (Exception ok) {
930 <        }
918 >        } catch (UnsupportedOperationException success) {}
919          e = map.pollLastEntry();
920          assertNull(e);
921      }
922  
923      /**
924 <     *   size returns the correct values
924 >     * size returns the correct values
925       */
926      public void testDescendingSize() {
927          NavigableMap map = dmap5();
# Line 949 | Line 937 | public class TreeSubMapTest extends JSR1
937          NavigableMap map = dmap5();
938          String s = map.toString();
939          for (int i = 1; i <= 5; ++i) {
940 <            assertTrue(s.indexOf(String.valueOf(i)) >= 0);
940 >            assertTrue(s.contains(String.valueOf(i)));
941          }
942      }
943  
# Line 963 | Line 951 | public class TreeSubMapTest extends JSR1
951              NavigableMap c = dmap5();
952              c.get(null);
953              shouldThrow();
954 <        } catch (NullPointerException e) {}
954 >        } catch (NullPointerException success) {}
955      }
956  
957      /**
# Line 974 | Line 962 | public class TreeSubMapTest extends JSR1
962              NavigableMap c = dmap5();
963              c.put(null, "whatever");
964              shouldThrow();
965 <        } catch (NullPointerException e) {}
965 >        } catch (NullPointerException success) {}
966      }
967  
968      /**
# Line 1026 | Line 1014 | public class TreeSubMapTest extends JSR1
1014          assertEquals(1, sm.size());
1015          assertEquals(m3, sm.firstKey());
1016          assertEquals(m3, sm.lastKey());
1017 <        assertTrue(sm.remove(m3) != null);
1017 >        assertEquals("C", sm.remove(m3));
1018          assertTrue(sm.isEmpty());
1019          assertEquals(3, map.size());
1020      }
# Line 1054 | Line 1042 | public class TreeSubMapTest extends JSR1
1042          assertEquals(4, map.size());
1043          assertEquals(0, sm.size());
1044          assertTrue(sm.isEmpty());
1045 <        assertTrue(sm.remove(m3) == null);
1045 >        assertSame(sm.remove(m3), null);
1046          assertEquals(4, map.size());
1047      }
1048  
# Line 1126 | Line 1114 | public class TreeSubMapTest extends JSR1
1114          SortedMap ssm = sm.tailMap(m4);
1115          assertEquals(m4, ssm.firstKey());
1116          assertEquals(m5, ssm.lastKey());
1117 <        assertTrue(ssm.remove(m4) != null);
1117 >        assertEquals("D", ssm.remove(m4));
1118          assertEquals(1, ssm.size());
1119          assertEquals(3, sm.size());
1120          assertEquals(4, map.size());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines