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.4 by dl, Thu Apr 20 20:35:00 2006 UTC vs.
Revision 1.6 by jsr166, Mon Nov 2 20:28:32 2009 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 20 | Line 20 | public class TreeMapTest extends JSR166T
20      /**
21       * Create a map from Integers 1-5 to Strings "A"-"E".
22       */
23 <    private static TreeMap map5() {  
23 >    private static TreeMap map5() {
24          TreeMap map = new TreeMap();
25          assertTrue(map.isEmpty());
26          map.put(one, "A");
# Line 43 | Line 43 | public class TreeMapTest extends JSR166T
43      }
44  
45      /**
46 <     *  
46 >     *
47       */
48      public void testConstructFromSorted() {
49          TreeMap map = map5();
# Line 169 | Line 169 | public class TreeMapTest extends JSR166T
169          Iterator i = s.iterator();
170          Integer last = (Integer)i.next();
171          assertEquals(last, one);
172 +        int count = 1;
173          while (i.hasNext()) {
174              Integer k = (Integer)i.next();
175              assertTrue(last.compareTo(k) < 0);
176              last = k;
177 +            ++count;
178          }
179 +        assertEquals(count ,5);
180 +    }
181 +
182 +    /**
183 +     * descending iterator of key set is inverse ordered
184 +     */
185 +    public void testKeySetDescendingIteratorOrder() {
186 +        TreeMap map = map5();
187 +        NavigableSet s = map.navigableKeySet();
188 +        Iterator i = s.descendingIterator();
189 +        Integer last = (Integer)i.next();
190 +        assertEquals(last, five);
191 +        int count = 1;
192 +        while (i.hasNext()) {
193 +            Integer k = (Integer)i.next();
194 +            assertTrue(last.compareTo(k) > 0);
195 +            last = k;
196 +            ++count;
197 +        }
198 +        assertEquals(count ,5);
199      }
200  
201      /**
# Line 185 | Line 207 | public class TreeMapTest extends JSR166T
207          Iterator i = s.iterator();
208          Integer last = (Integer)i.next();
209          assertEquals(last, five);
210 +        int count = 1;
211          while (i.hasNext()) {
212              Integer k = (Integer)i.next();
213              assertTrue(last.compareTo(k) > 0);
214              last = k;
215 +            ++count;
216 +        }
217 +        assertEquals(count, 5);
218 +    }
219 +
220 +    /**
221 +     *  descending iterator of descendingKeySet is ordered
222 +     */
223 +    public void testDescendingKeySetDescendingIteratorOrder() {
224 +        TreeMap map = map5();
225 +        NavigableSet s = map.descendingKeySet();
226 +        Iterator i = s.descendingIterator();
227 +        Integer last = (Integer)i.next();
228 +        assertEquals(last, one);
229 +        int count = 1;
230 +        while (i.hasNext()) {
231 +            Integer k = (Integer)i.next();
232 +            assertTrue(last.compareTo(k) < 0);
233 +            last = k;
234 +            ++count;
235          }
236 +        assertEquals(count, 5);
237      }
238  
239      /**
# Line 216 | Line 260 | public class TreeMapTest extends JSR166T
260          Iterator it = s.iterator();
261          while (it.hasNext()) {
262              Map.Entry e = (Map.Entry) it.next();
263 <            assertTrue(
263 >            assertTrue(
264                         (e.getKey().equals(one) && e.getValue().equals("A")) ||
265                         (e.getKey().equals(two) && e.getValue().equals("B")) ||
266                         (e.getKey().equals(three) && e.getValue().equals("C")) ||
# Line 235 | Line 279 | public class TreeMapTest extends JSR166T
279          Iterator it = s.iterator();
280          while (it.hasNext()) {
281              Map.Entry e = (Map.Entry) it.next();
282 <            assertTrue(
282 >            assertTrue(
283                         (e.getKey().equals(one) && e.getValue().equals("A")) ||
284                         (e.getKey().equals(two) && e.getValue().equals("B")) ||
285                         (e.getKey().equals(three) && e.getValue().equals("C")) ||
# Line 525 | Line 569 | public class TreeMapTest extends JSR166T
569          for (int i = 1; i <= 5; ++i) {
570              assertTrue(s.indexOf(String.valueOf(i)) >= 0);
571          }
572 <    }        
572 >    }
573  
574      // Exception tests
575  
# Line 614 | Line 658 | public class TreeMapTest extends JSR166T
658          k = (Integer)(r.next());
659          assertEquals(two, k);
660          assertFalse(r.hasNext());
661 <        
661 >
662          Iterator j = sm.keySet().iterator();
663          j.next();
664          j.remove();
# Line 648 | Line 692 | public class TreeMapTest extends JSR166T
692          k = (Integer)(r.next());
693          assertEquals(two, k);
694          assertFalse(r.hasNext());
695 <        
695 >
696          Iterator j = sm.keySet().iterator();
697          j.next();
698          j.remove();
# Line 1058 | Line 1102 | public class TreeMapTest extends JSR166T
1102      static boolean eq(Integer i, int j) {
1103          return i == null ? j == -1 : i == j;
1104      }
1105 <    
1105 >
1106   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines