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.9 by jsr166, Sat Nov 21 02:07:27 2009 UTC vs.
Revision 1.16 by jsr166, Sat Oct 9 19:30:35 2010 UTC

# Line 11 | Line 11 | import java.io.*;
11  
12   public class TreeMapTest 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(TreeMapTest.class);
# Line 34 | Line 34 | public class TreeMapTest extends JSR166T
34      }
35  
36      /**
37 <     *  clear removes all pairs
37 >     * clear removes all pairs
38       */
39      public void testClear() {
40          TreeMap map = map5();
# Line 52 | Line 52 | public class TreeMapTest extends JSR166T
52      }
53  
54      /**
55 <     *  Maps with same contents are equal
55 >     * Maps with same contents are equal
56       */
57      public void testEquals() {
58          TreeMap map1 = map5();
# Line 65 | Line 65 | public class TreeMapTest extends JSR166T
65      }
66  
67      /**
68 <     *  containsKey returns true for contained key
68 >     * containsKey returns true for contained key
69       */
70      public void testContainsKey() {
71          TreeMap map = map5();
# Line 74 | Line 74 | public class TreeMapTest extends JSR166T
74      }
75  
76      /**
77 <     *  containsValue returns true for held values
77 >     * containsValue returns true for held values
78       */
79      public void testContainsValue() {
80          TreeMap map = map5();
# Line 83 | Line 83 | public class TreeMapTest extends JSR166T
83      }
84  
85      /**
86 <     *  get returns the correct element at the given key,
87 <     *  or null if not present
86 >     * get returns the correct element at the given key,
87 >     * or null if not present
88       */
89      public void testGet() {
90          TreeMap map = map5();
# Line 94 | Line 94 | public class TreeMapTest extends JSR166T
94      }
95  
96      /**
97 <     *  isEmpty is true of empty map and false for non-empty
97 >     * isEmpty is true of empty map and false for non-empty
98       */
99      public void testIsEmpty() {
100          TreeMap empty = new TreeMap();
# Line 104 | Line 104 | public class TreeMapTest extends JSR166T
104      }
105  
106      /**
107 <     *   firstKey returns first key
107 >     * firstKey returns first key
108       */
109      public void testFirstKey() {
110          TreeMap map = map5();
# Line 112 | Line 112 | public class TreeMapTest extends JSR166T
112      }
113  
114      /**
115 <     *   lastKey returns last key
115 >     * lastKey returns last key
116       */
117      public void testLastKey() {
118          TreeMap map = map5();
# Line 121 | Line 121 | public class TreeMapTest extends JSR166T
121  
122  
123      /**
124 <     *  keySet.toArray returns contains all keys
124 >     * keySet.toArray returns contains all keys
125       */
126      public void testKeySetToArray() {
127          TreeMap map = map5();
# Line 134 | Line 134 | public class TreeMapTest extends JSR166T
134      }
135  
136      /**
137 <     *  descendingkeySet.toArray returns contains all keys
137 >     * descendingkeySet.toArray returns contains all keys
138       */
139      public void testDescendingKeySetToArray() {
140          TreeMap map = map5();
# Line 147 | Line 147 | public class TreeMapTest extends JSR166T
147      }
148  
149      /**
150 <     *   keySet returns a Set containing all the keys
150 >     * keySet returns a Set containing all the keys
151       */
152      public void testKeySet() {
153          TreeMap map = map5();
# Line 161 | Line 161 | public class TreeMapTest extends JSR166T
161      }
162  
163      /**
164 <     *   keySet is ordered
164 >     * keySet is ordered
165       */
166      public void testKeySetOrder() {
167          TreeMap map = map5();
# Line 199 | Line 199 | public class TreeMapTest extends JSR166T
199      }
200  
201      /**
202 <     *   descendingKeySet is ordered
202 >     * descendingKeySet is ordered
203       */
204      public void testDescendingKeySetOrder() {
205          TreeMap map = map5();
# Line 218 | Line 218 | public class TreeMapTest extends JSR166T
218      }
219  
220      /**
221 <     *  descending iterator of descendingKeySet is ordered
221 >     * descending iterator of descendingKeySet is ordered
222       */
223      public void testDescendingKeySetDescendingIteratorOrder() {
224          TreeMap map = map5();
# Line 289 | Line 289 | public class TreeMapTest extends JSR166T
289      }
290  
291      /**
292 <     *  entrySet.toArray contains all entries
292 >     * entrySet.toArray contains all entries
293       */
294      public void testEntrySetToArray() {
295          TreeMap map = map5();
# Line 303 | Line 303 | public class TreeMapTest extends JSR166T
303      }
304  
305      /**
306 <     *  descendingEntrySet.toArray contains all entries
306 >     * descendingEntrySet.toArray contains all entries
307       */
308      public void testDescendingEntrySetToArray() {
309          TreeMap map = map5();
# Line 317 | Line 317 | public class TreeMapTest extends JSR166T
317      }
318  
319      /**
320 <     *   putAll  adds all key-value pairs from the given map
320 >     * putAll adds all key-value pairs from the given map
321       */
322      public void testPutAll() {
323          TreeMap empty = new TreeMap();
# Line 332 | Line 332 | public class TreeMapTest extends JSR166T
332      }
333  
334      /**
335 <     *   remove removes the correct key-value pair from the map
335 >     * remove removes the correct key-value pair from the map
336       */
337      public void testRemove() {
338          TreeMap map = map5();
# Line 357 | Line 357 | public class TreeMapTest extends JSR166T
357  
358          Map.Entry e4 = map.lowerEntry(zero);
359          assertNull(e4);
360
360      }
361  
362      /**
# Line 376 | Line 375 | public class TreeMapTest extends JSR166T
375  
376          Map.Entry e4 = map.higherEntry(six);
377          assertNull(e4);
379
378      }
379  
380      /**
# Line 395 | Line 393 | public class TreeMapTest extends JSR166T
393  
394          Map.Entry e4 = map.floorEntry(zero);
395          assertNull(e4);
398
396      }
397  
398      /**
# Line 414 | Line 411 | public class TreeMapTest extends JSR166T
411  
412          Map.Entry e4 = map.ceilingEntry(six);
413          assertNull(e4);
417
414      }
415  
416  
# Line 434 | Line 430 | public class TreeMapTest extends JSR166T
430  
431          Object e4 = q.lowerKey(zero);
432          assertNull(e4);
437
433      }
434  
435      /**
# Line 453 | Line 448 | public class TreeMapTest extends JSR166T
448  
449          Object e4 = q.higherKey(six);
450          assertNull(e4);
456
451      }
452  
453      /**
# Line 472 | Line 466 | public class TreeMapTest extends JSR166T
466  
467          Object e4 = q.floorKey(zero);
468          assertNull(e4);
475
469      }
470  
471      /**
# Line 491 | Line 484 | public class TreeMapTest extends JSR166T
484  
485          Object e4 = q.ceilingKey(six);
486          assertNull(e4);
494
487      }
488  
489      /**
# Line 516 | Line 508 | public class TreeMapTest extends JSR166T
508          try {
509              e.setValue("A");
510              shouldThrow();
511 <        } catch (Exception ok) {
520 <        }
511 >        } catch (UnsupportedOperationException success) {}
512          e = map.pollFirstEntry();
513          assertNull(e);
514      }
# Line 544 | Line 535 | public class TreeMapTest extends JSR166T
535          try {
536              e.setValue("E");
537              shouldThrow();
538 <        } catch (Exception ok) {
548 <        }
538 >        } catch (UnsupportedOperationException success) {}
539          e = map.pollLastEntry();
540          assertNull(e);
541      }
542  
543      /**
544 <     *   size returns the correct values
544 >     * size returns the correct values
545       */
546      public void testSize() {
547          TreeMap map = map5();
# Line 581 | Line 571 | public class TreeMapTest extends JSR166T
571              TreeMap c = map5();
572              c.get(null);
573              shouldThrow();
574 <        } catch (NullPointerException e) {}
574 >        } catch (NullPointerException success) {}
575      }
576  
577      /**
# Line 592 | Line 582 | public class TreeMapTest extends JSR166T
582              TreeMap c = map5();
583              c.containsKey(null);
584              shouldThrow();
585 <        } catch (NullPointerException e) {}
585 >        } catch (NullPointerException success) {}
586      }
587  
588      /**
# Line 604 | Line 594 | public class TreeMapTest extends JSR166T
594              c.put("sadsdf", "asdads");
595              c.remove(null);
596              shouldThrow();
597 <        } catch (NullPointerException e) {}
597 >        } catch (NullPointerException success) {}
598      }
599  
600      /**
601       * A deserialized map equals original
602       */
603 <    public void testSerialization() {
603 >    public void testSerialization() throws Exception {
604          TreeMap q = map5();
605  
606 <        try {
607 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
608 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
609 <            out.writeObject(q);
610 <            out.close();
611 <
612 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
613 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
614 <            TreeMap r = (TreeMap)in.readObject();
615 <            assertEquals(q.size(), r.size());
616 <            assertTrue(q.equals(r));
627 <            assertTrue(r.equals(q));
628 <        } catch (Exception e) {
629 <            e.printStackTrace();
630 <            unexpectedException();
631 <        }
606 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
607 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
608 >        out.writeObject(q);
609 >        out.close();
610 >
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));
617      }
618  
619      /**
# Line 667 | Line 652 | public class TreeMapTest extends JSR166T
652          assertEquals(1, sm.size());
653          assertEquals(three, sm.firstKey());
654          assertEquals(three, sm.lastKey());
655 <        assertTrue(sm.remove(three) != null);
655 >        assertEquals("C", sm.remove(three));
656          assertTrue(sm.isEmpty());
657          assertEquals(3, map.size());
658      }
# Line 700 | Line 685 | public class TreeMapTest extends JSR166T
685          assertEquals(4, map.size());
686          assertEquals(0, sm.size());
687          assertTrue(sm.isEmpty());
688 <        assertTrue(sm.remove(three) == null);
688 >        assertSame(sm.remove(three), null);
689          assertEquals(4, map.size());
690      }
691  
# Line 782 | Line 767 | public class TreeMapTest extends JSR166T
767          NavigableMap ssm = sm.tailMap(four, true);
768          assertEquals(four, ssm.firstKey());
769          assertEquals(five, ssm.lastKey());
770 <        assertTrue(ssm.remove(four) != null);
770 >        assertEquals("D", ssm.remove(four));
771          assertEquals(1, ssm.size());
772          assertEquals(3, sm.size());
773          assertEquals(4, map.size());
# Line 794 | Line 779 | public class TreeMapTest extends JSR166T
779      /**
780       * Submaps of submaps subdivide correctly
781       */
782 <    public void testRecursiveSubMaps() {
782 >    public void testRecursiveSubMaps() throws Exception {
783          int mapSize = 1000;
784          Class cl = TreeMap.class;
785          NavigableMap<Integer, Integer> map = newMap(cl);
# Line 812 | Line 797 | public class TreeMapTest extends JSR166T
797                     0, mapSize - 1, true);
798      }
799  
800 <    static NavigableMap<Integer, Integer> newMap(Class cl) {
801 <        NavigableMap<Integer, Integer> result = null;
802 <        try {
818 <            result = (NavigableMap<Integer, Integer>) cl.newInstance();
819 <        } catch (Exception e) {
820 <            fail();
821 <        }
800 >    static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception {
801 >        NavigableMap<Integer, Integer> result
802 >            = (NavigableMap<Integer, Integer>) cl.newInstance();
803          assertEquals(result.size(), 0);
804          assertFalse(result.keySet().iterator().hasNext());
805          return result;
# Line 881 | Line 862 | public class TreeMapTest extends JSR166T
862              } else {
863                  try {
864                      map.put(key, 2 * key);
865 <                    fail();
866 <                } catch (IllegalArgumentException e) {
886 <                    // expected
887 <                }
865 >                    shouldThrow();
866 >                } catch (IllegalArgumentException success) {}
867              }
868          }
869      }
# Line 1013 | Line 992 | public class TreeMapTest extends JSR166T
992                  // BitSet should support this! Test would run much faster
993                  while (key >= min) {
994                      if (bs.get(key))
995 <                        return(key);
995 >                        return key;
996                      key--;
997                  }
998                  return -1;
# Line 1079 | Line 1058 | public class TreeMapTest extends JSR166T
1058              assertEq(rs.last(),  -1);
1059              try {
1060                  map.firstKey();
1061 <                fail();
1062 <            } catch (NoSuchElementException e) {
1084 <                // expected
1085 <            }
1061 >                shouldThrow();
1062 >            } catch (NoSuchElementException success) {}
1063              try {
1064                  map.lastKey();
1065 <                fail();
1066 <            } catch (NoSuchElementException e) {
1090 <                // expected
1091 <            }
1065 >                shouldThrow();
1066 >            } catch (NoSuchElementException success) {}
1067          }
1068      }
1069  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines