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.35 by jsr166, Sun Sep 29 20:40:48 2019 UTC vs.
Revision 1.36 by dl, Tue Jan 26 13:33:06 2021 UTC

# Line 37 | Line 37 | public class TreeMapTest extends JSR166T
37      }
38  
39      /**
40 <     * Returns a new map from Integers 1-5 to Strings "A"-"E".
40 >     * Returns a new map from Items 1-5 to Strings "A"-"E".
41       */
42 <    private static TreeMap map5() {
43 <        TreeMap map = new TreeMap();
42 >    private static TreeMap<Item,String> map5() {
43 >        TreeMap<Item,String> map = new TreeMap<Item,String>();
44          assertTrue(map.isEmpty());
45          map.put(one, "A");
46          map.put(five, "E");
# Line 48 | Line 48 | public class TreeMapTest extends JSR166T
48          map.put(two, "B");
49          map.put(four, "D");
50          assertFalse(map.isEmpty());
51 <        assertEquals(5, map.size());
51 >        mustEqual(5, map.size());
52          return map;
53      }
54  
# Line 56 | Line 56 | public class TreeMapTest extends JSR166T
56       * clear removes all pairs
57       */
58      public void testClear() {
59 <        TreeMap map = map5();
59 >        TreeMap<Item,String> map = map5();
60          map.clear();
61 <        assertEquals(0, map.size());
61 >        mustEqual(0, map.size());
62      }
63  
64      /**
65       * copy constructor creates map equal to source map
66       */
67      public void testConstructFromSorted() {
68 <        TreeMap map = map5();
69 <        TreeMap map2 = new TreeMap(map);
70 <        assertEquals(map, map2);
68 >        TreeMap<Item,String> map = map5();
69 >        TreeMap<Item,String> map2 = new TreeMap<Item,String>(map);
70 >        mustEqual(map, map2);
71      }
72  
73      /**
74       * Maps with same contents are equal
75       */
76      public void testEquals() {
77 <        TreeMap map1 = map5();
78 <        TreeMap map2 = map5();
79 <        assertEquals(map1, map2);
80 <        assertEquals(map2, map1);
77 >        TreeMap<Item,String> map1 = map5();
78 >        TreeMap<Item,String> map2 = map5();
79 >        mustEqual(map1, map2);
80 >        mustEqual(map2, map1);
81          map1.clear();
82          assertFalse(map1.equals(map2));
83          assertFalse(map2.equals(map1));
# Line 87 | Line 87 | public class TreeMapTest extends JSR166T
87       * containsKey returns true for contained key
88       */
89      public void testContainsKey() {
90 <        TreeMap map = map5();
90 >        TreeMap<Item,String> map = map5();
91          assertTrue(map.containsKey(one));
92          assertFalse(map.containsKey(zero));
93      }
# Line 96 | Line 96 | public class TreeMapTest extends JSR166T
96       * containsValue returns true for held values
97       */
98      public void testContainsValue() {
99 <        TreeMap map = map5();
99 >        TreeMap<Item,String> map = map5();
100          assertTrue(map.containsValue("A"));
101          assertFalse(map.containsValue("Z"));
102      }
# Line 106 | Line 106 | public class TreeMapTest extends JSR166T
106       * or null if not present
107       */
108      public void testGet() {
109 <        TreeMap map = map5();
110 <        assertEquals("A", (String)map.get(one));
111 <        TreeMap empty = new TreeMap();
109 >        TreeMap<Item,String> map = map5();
110 >        mustEqual("A", map.get(one));
111 >        TreeMap<Item,String> empty = new TreeMap<Item,String>();
112          assertNull(empty.get(one));
113      }
114  
# Line 116 | Line 116 | public class TreeMapTest extends JSR166T
116       * isEmpty is true of empty map and false for non-empty
117       */
118      public void testIsEmpty() {
119 <        TreeMap empty = new TreeMap();
120 <        TreeMap map = map5();
119 >        TreeMap<Item,String> empty = new TreeMap<Item,String>();
120 >        TreeMap<Item,String> map = map5();
121          assertTrue(empty.isEmpty());
122          assertFalse(map.isEmpty());
123      }
# Line 126 | Line 126 | public class TreeMapTest extends JSR166T
126       * firstKey returns first key
127       */
128      public void testFirstKey() {
129 <        TreeMap map = map5();
130 <        assertEquals(one, map.firstKey());
129 >        TreeMap<Item,String> map = map5();
130 >        mustEqual(one, map.firstKey());
131      }
132  
133      /**
134       * lastKey returns last key
135       */
136      public void testLastKey() {
137 <        TreeMap map = map5();
138 <        assertEquals(five, map.lastKey());
137 >        TreeMap<Item,String> map = map5();
138 >        mustEqual(five, map.lastKey());
139      }
140  
141      /**
142       * keySet.toArray returns contains all keys
143       */
144      public void testKeySetToArray() {
145 <        TreeMap map = map5();
146 <        Set s = map.keySet();
145 >        TreeMap<Item,String> map = map5();
146 >        Set<Item> s = map.keySet();
147          Object[] ar = s.toArray();
148          assertTrue(s.containsAll(Arrays.asList(ar)));
149 <        assertEquals(5, ar.length);
150 <        ar[0] = m10;
149 >        mustEqual(5, ar.length);
150 >        ar[0] = minusTen;
151          assertFalse(s.containsAll(Arrays.asList(ar)));
152      }
153  
# Line 155 | Line 155 | public class TreeMapTest extends JSR166T
155       * descendingkeySet.toArray returns contains all keys
156       */
157      public void testDescendingKeySetToArray() {
158 <        TreeMap map = map5();
159 <        Set s = map.descendingKeySet();
158 >        TreeMap<Item,String> map = map5();
159 >        Set<Item> s = map.descendingKeySet();
160          Object[] ar = s.toArray();
161 <        assertEquals(5, ar.length);
161 >        mustEqual(5, ar.length);
162          assertTrue(s.containsAll(Arrays.asList(ar)));
163 <        ar[0] = m10;
163 >        ar[0] = minusTen;
164          assertFalse(s.containsAll(Arrays.asList(ar)));
165      }
166  
# Line 168 | Line 168 | public class TreeMapTest extends JSR166T
168       * keySet returns a Set containing all the keys
169       */
170      public void testKeySet() {
171 <        TreeMap map = map5();
172 <        Set s = map.keySet();
173 <        assertEquals(5, s.size());
174 <        assertTrue(s.contains(one));
175 <        assertTrue(s.contains(two));
176 <        assertTrue(s.contains(three));
177 <        assertTrue(s.contains(four));
178 <        assertTrue(s.contains(five));
171 >        TreeMap<Item,String> map = map5();
172 >        Set<Item> s = map.keySet();
173 >        mustEqual(5, s.size());
174 >        mustContain(s, one);
175 >        mustContain(s, two);
176 >        mustContain(s, three);
177 >        mustContain(s, four);
178 >        mustContain(s, five);
179      }
180  
181      /**
182       * keySet is ordered
183       */
184      public void testKeySetOrder() {
185 <        TreeMap map = map5();
186 <        Set s = map.keySet();
187 <        Iterator i = s.iterator();
188 <        Integer last = (Integer)i.next();
189 <        assertEquals(last, one);
185 >        TreeMap<Item,String> map = map5();
186 >        Set<Item> s = map.keySet();
187 >        Iterator<? extends Item> i = s.iterator();
188 >        Item last = i.next();
189 >        mustEqual(last, one);
190          int count = 1;
191          while (i.hasNext()) {
192 <            Integer k = (Integer)i.next();
192 >            Item k = i.next();
193              assertTrue(last.compareTo(k) < 0);
194              last = k;
195              ++count;
196          }
197 <        assertEquals(5, count);
197 >        mustEqual(5, count);
198      }
199  
200      /**
201       * descending iterator of key set is inverse ordered
202       */
203      public void testKeySetDescendingIteratorOrder() {
204 <        TreeMap map = map5();
205 <        NavigableSet s = map.navigableKeySet();
206 <        Iterator i = s.descendingIterator();
207 <        Integer last = (Integer)i.next();
208 <        assertEquals(last, five);
204 >        TreeMap<Item,String> map = map5();
205 >        NavigableSet<Item> s = map.navigableKeySet();
206 >        Iterator<? extends Item> i = s.descendingIterator();
207 >        Item last = (Item)i.next();
208 >        mustEqual(last, five);
209          int count = 1;
210          while (i.hasNext()) {
211 <            Integer k = (Integer)i.next();
211 >            Item k = (Item)i.next();
212              assertTrue(last.compareTo(k) > 0);
213              last = k;
214              ++count;
215          }
216 <        assertEquals(5, count);
216 >        mustEqual(5, count);
217      }
218  
219      /**
220       * descendingKeySet is ordered
221       */
222      public void testDescendingKeySetOrder() {
223 <        TreeMap map = map5();
224 <        Set s = map.descendingKeySet();
225 <        Iterator i = s.iterator();
226 <        Integer last = (Integer)i.next();
227 <        assertEquals(last, five);
223 >        TreeMap<Item,String> map = map5();
224 >        Set<Item> s = map.descendingKeySet();
225 >        Iterator<? extends Item> i = s.iterator();
226 >        Item last = (Item)i.next();
227 >        mustEqual(last, five);
228          int count = 1;
229          while (i.hasNext()) {
230 <            Integer k = (Integer)i.next();
230 >            Item k = (Item)i.next();
231              assertTrue(last.compareTo(k) > 0);
232              last = k;
233              ++count;
234          }
235 <        assertEquals(5, count);
235 >        mustEqual(5, count);
236      }
237  
238      /**
239       * descending iterator of descendingKeySet is ordered
240       */
241      public void testDescendingKeySetDescendingIteratorOrder() {
242 <        TreeMap map = map5();
243 <        NavigableSet s = map.descendingKeySet();
244 <        Iterator i = s.descendingIterator();
245 <        Integer last = (Integer)i.next();
246 <        assertEquals(last, one);
242 >        TreeMap<Item,String> map = map5();
243 >        NavigableSet<Item> s = map.descendingKeySet();
244 >        Iterator<? extends Item> i = s.descendingIterator();
245 >        Item last = (Item)i.next();
246 >        mustEqual(last, one);
247          int count = 1;
248          while (i.hasNext()) {
249 <            Integer k = (Integer)i.next();
249 >            Item k = (Item)i.next();
250              assertTrue(last.compareTo(k) < 0);
251              last = k;
252              ++count;
253          }
254 <        assertEquals(5, count);
254 >        mustEqual(5, count);
255      }
256  
257      /**
258       * values collection contains all values
259       */
260      public void testValues() {
261 <        TreeMap map = map5();
262 <        Collection s = map.values();
263 <        assertEquals(5, s.size());
261 >        TreeMap<Item,String> map = map5();
262 >        Collection<String> s = map.values();
263 >        mustEqual(5, s.size());
264          assertTrue(s.contains("A"));
265          assertTrue(s.contains("B"));
266          assertTrue(s.contains("C"));
# Line 272 | Line 272 | public class TreeMapTest extends JSR166T
272       * entrySet contains all pairs
273       */
274      public void testEntrySet() {
275 <        TreeMap map = map5();
276 <        Set s = map.entrySet();
277 <        assertEquals(5, s.size());
278 <        Iterator it = s.iterator();
275 >        TreeMap<Item,String> map = map5();
276 >        Set<Map.Entry<Item,String>> s = map.entrySet();
277 >        mustEqual(5, s.size());
278 >        Iterator<Map.Entry<Item,String>> it = s.iterator();
279          while (it.hasNext()) {
280 <            Map.Entry e = (Map.Entry) it.next();
280 >            Map.Entry<Item,String> e = it.next();
281              assertTrue(
282                         (e.getKey().equals(one) && e.getValue().equals("A")) ||
283                         (e.getKey().equals(two) && e.getValue().equals("B")) ||
# Line 291 | Line 291 | public class TreeMapTest extends JSR166T
291       * descendingEntrySet contains all pairs
292       */
293      public void testDescendingEntrySet() {
294 <        TreeMap map = map5();
295 <        Set s = map.descendingMap().entrySet();
296 <        assertEquals(5, s.size());
297 <        Iterator it = s.iterator();
294 >        TreeMap<Item,String> map = map5();
295 >        Set<Map.Entry<Item,String>> s = map.descendingMap().entrySet();
296 >        mustEqual(5, s.size());
297 >        Iterator<Map.Entry<Item,String>> it = s.iterator();
298          while (it.hasNext()) {
299 <            Map.Entry e = (Map.Entry) it.next();
299 >            Map.Entry<Item,String> e = it.next();
300              assertTrue(
301                         (e.getKey().equals(one) && e.getValue().equals("A")) ||
302                         (e.getKey().equals(two) && e.getValue().equals("B")) ||
# Line 310 | Line 310 | public class TreeMapTest extends JSR166T
310       * entrySet.toArray contains all entries
311       */
312      public void testEntrySetToArray() {
313 <        TreeMap map = map5();
314 <        Set s = map.entrySet();
313 >        TreeMap<Item,String> map = map5();
314 >        Set<Map.Entry<Item,String>> s = map.entrySet();
315          Object[] ar = s.toArray();
316 <        assertEquals(5, ar.length);
316 >        mustEqual(5, ar.length);
317          for (int i = 0; i < 5; ++i) {
318              assertTrue(map.containsKey(((Map.Entry)(ar[i])).getKey()));
319              assertTrue(map.containsValue(((Map.Entry)(ar[i])).getValue()));
# Line 324 | Line 324 | public class TreeMapTest extends JSR166T
324       * descendingEntrySet.toArray contains all entries
325       */
326      public void testDescendingEntrySetToArray() {
327 <        TreeMap map = map5();
328 <        Set s = map.descendingMap().entrySet();
327 >        TreeMap<Item,String> map = map5();
328 >        Set<Map.Entry<Item,String>> s = map.descendingMap().entrySet();
329          Object[] ar = s.toArray();
330 <        assertEquals(5, ar.length);
330 >        mustEqual(5, ar.length);
331          for (int i = 0; i < 5; ++i) {
332              assertTrue(map.containsKey(((Map.Entry)(ar[i])).getKey()));
333              assertTrue(map.containsValue(((Map.Entry)(ar[i])).getValue()));
# Line 338 | Line 338 | public class TreeMapTest extends JSR166T
338       * putAll adds all key-value pairs from the given map
339       */
340      public void testPutAll() {
341 <        TreeMap empty = new TreeMap();
342 <        TreeMap map = map5();
341 >        TreeMap<Item,String> empty = new TreeMap<Item,String>();
342 >        TreeMap<Item,String> map = map5();
343          empty.putAll(map);
344 <        assertEquals(5, empty.size());
344 >        mustEqual(5, empty.size());
345          assertTrue(empty.containsKey(one));
346          assertTrue(empty.containsKey(two));
347          assertTrue(empty.containsKey(three));
# Line 353 | Line 353 | public class TreeMapTest extends JSR166T
353       * remove removes the correct key-value pair from the map
354       */
355      public void testRemove() {
356 <        TreeMap map = map5();
356 >        TreeMap<Item,String> map = map5();
357          map.remove(five);
358 <        assertEquals(4, map.size());
358 >        mustEqual(4, map.size());
359          assertFalse(map.containsKey(five));
360      }
361  
# Line 363 | Line 363 | public class TreeMapTest extends JSR166T
363       * lowerEntry returns preceding entry.
364       */
365      public void testLowerEntry() {
366 <        TreeMap map = map5();
367 <        Map.Entry e1 = map.lowerEntry(three);
368 <        assertEquals(two, e1.getKey());
366 >        TreeMap<Item,String> map = map5();
367 >        Map.Entry<Item,String> e1 = map.lowerEntry(three);
368 >        mustEqual(two, e1.getKey());
369  
370 <        Map.Entry e2 = map.lowerEntry(six);
371 <        assertEquals(five, e2.getKey());
370 >        Map.Entry<Item,String> e2 = map.lowerEntry(six);
371 >        mustEqual(five, e2.getKey());
372  
373 <        Map.Entry e3 = map.lowerEntry(one);
373 >        Map.Entry<Item,String> e3 = map.lowerEntry(one);
374          assertNull(e3);
375  
376 <        Map.Entry e4 = map.lowerEntry(zero);
376 >        Map.Entry<Item,String> e4 = map.lowerEntry(zero);
377          assertNull(e4);
378      }
379  
# Line 381 | Line 381 | public class TreeMapTest extends JSR166T
381       * higherEntry returns next entry.
382       */
383      public void testHigherEntry() {
384 <        TreeMap map = map5();
385 <        Map.Entry e1 = map.higherEntry(three);
386 <        assertEquals(four, e1.getKey());
384 >        TreeMap<Item,String> map = map5();
385 >        Map.Entry<Item,String> e1 = map.higherEntry(three);
386 >        mustEqual(four, e1.getKey());
387  
388 <        Map.Entry e2 = map.higherEntry(zero);
389 <        assertEquals(one, e2.getKey());
388 >        Map.Entry<Item,String> e2 = map.higherEntry(zero);
389 >        mustEqual(one, e2.getKey());
390  
391 <        Map.Entry e3 = map.higherEntry(five);
391 >        Map.Entry<Item,String> e3 = map.higherEntry(five);
392          assertNull(e3);
393  
394 <        Map.Entry e4 = map.higherEntry(six);
394 >        Map.Entry<Item,String> e4 = map.higherEntry(six);
395          assertNull(e4);
396      }
397  
# Line 399 | Line 399 | public class TreeMapTest extends JSR166T
399       * floorEntry returns preceding entry.
400       */
401      public void testFloorEntry() {
402 <        TreeMap map = map5();
403 <        Map.Entry e1 = map.floorEntry(three);
404 <        assertEquals(three, e1.getKey());
402 >        TreeMap<Item,String> map = map5();
403 >        Map.Entry<Item,String> e1 = map.floorEntry(three);
404 >        mustEqual(three, e1.getKey());
405  
406 <        Map.Entry e2 = map.floorEntry(six);
407 <        assertEquals(five, e2.getKey());
406 >        Map.Entry<Item,String> e2 = map.floorEntry(six);
407 >        mustEqual(five, e2.getKey());
408  
409 <        Map.Entry e3 = map.floorEntry(one);
410 <        assertEquals(one, e3.getKey());
409 >        Map.Entry<Item,String> e3 = map.floorEntry(one);
410 >        mustEqual(one, e3.getKey());
411  
412 <        Map.Entry e4 = map.floorEntry(zero);
412 >        Map.Entry<Item,String> e4 = map.floorEntry(zero);
413          assertNull(e4);
414      }
415  
# Line 417 | Line 417 | public class TreeMapTest extends JSR166T
417       * ceilingEntry returns next entry.
418       */
419      public void testCeilingEntry() {
420 <        TreeMap map = map5();
421 <        Map.Entry e1 = map.ceilingEntry(three);
422 <        assertEquals(three, e1.getKey());
420 >        TreeMap<Item,String> map = map5();
421 >        Map.Entry<Item,String> e1 = map.ceilingEntry(three);
422 >        mustEqual(three, e1.getKey());
423  
424 <        Map.Entry e2 = map.ceilingEntry(zero);
425 <        assertEquals(one, e2.getKey());
424 >        Map.Entry<Item,String> e2 = map.ceilingEntry(zero);
425 >        mustEqual(one, e2.getKey());
426  
427 <        Map.Entry e3 = map.ceilingEntry(five);
428 <        assertEquals(five, e3.getKey());
427 >        Map.Entry<Item,String> e3 = map.ceilingEntry(five);
428 >        mustEqual(five, e3.getKey());
429  
430 <        Map.Entry e4 = map.ceilingEntry(six);
430 >        Map.Entry<Item,String> e4 = map.ceilingEntry(six);
431          assertNull(e4);
432      }
433  
# Line 435 | Line 435 | public class TreeMapTest extends JSR166T
435       * lowerKey returns preceding element
436       */
437      public void testLowerKey() {
438 <        TreeMap q = map5();
438 >        TreeMap<Item,String> q = map5();
439          Object e1 = q.lowerKey(three);
440 <        assertEquals(two, e1);
440 >        mustEqual(two, e1);
441  
442          Object e2 = q.lowerKey(six);
443 <        assertEquals(five, e2);
443 >        mustEqual(five, e2);
444  
445          Object e3 = q.lowerKey(one);
446          assertNull(e3);
# Line 453 | Line 453 | public class TreeMapTest extends JSR166T
453       * higherKey returns next element
454       */
455      public void testHigherKey() {
456 <        TreeMap q = map5();
456 >        TreeMap<Item,String> q = map5();
457          Object e1 = q.higherKey(three);
458 <        assertEquals(four, e1);
458 >        mustEqual(four, e1);
459  
460          Object e2 = q.higherKey(zero);
461 <        assertEquals(one, e2);
461 >        mustEqual(one, e2);
462  
463          Object e3 = q.higherKey(five);
464          assertNull(e3);
# Line 471 | Line 471 | public class TreeMapTest extends JSR166T
471       * floorKey returns preceding element
472       */
473      public void testFloorKey() {
474 <        TreeMap q = map5();
474 >        TreeMap<Item,String> q = map5();
475          Object e1 = q.floorKey(three);
476 <        assertEquals(three, e1);
476 >        mustEqual(three, e1);
477  
478          Object e2 = q.floorKey(six);
479 <        assertEquals(five, e2);
479 >        mustEqual(five, e2);
480  
481          Object e3 = q.floorKey(one);
482 <        assertEquals(one, e3);
482 >        mustEqual(one, e3);
483  
484          Object e4 = q.floorKey(zero);
485          assertNull(e4);
# Line 489 | Line 489 | public class TreeMapTest extends JSR166T
489       * ceilingKey returns next element
490       */
491      public void testCeilingKey() {
492 <        TreeMap q = map5();
492 >        TreeMap<Item,String> q = map5();
493          Object e1 = q.ceilingKey(three);
494 <        assertEquals(three, e1);
494 >        mustEqual(three, e1);
495  
496          Object e2 = q.ceilingKey(zero);
497 <        assertEquals(one, e2);
497 >        mustEqual(one, e2);
498  
499          Object e3 = q.ceilingKey(five);
500 <        assertEquals(five, e3);
500 >        mustEqual(five, e3);
501  
502          Object e4 = q.ceilingKey(six);
503          assertNull(e4);
# Line 507 | Line 507 | public class TreeMapTest extends JSR166T
507       * pollFirstEntry returns entries in order
508       */
509      public void testPollFirstEntry() {
510 <        TreeMap map = map5();
511 <        Map.Entry e = map.pollFirstEntry();
512 <        assertEquals(one, e.getKey());
513 <        assertEquals("A", e.getValue());
510 >        TreeMap<Item,String> map = map5();
511 >        Map.Entry<Item,String> e = map.pollFirstEntry();
512 >        mustEqual(one, e.getKey());
513 >        mustEqual("A", e.getValue());
514          e = map.pollFirstEntry();
515 <        assertEquals(two, e.getKey());
515 >        mustEqual(two, e.getKey());
516          map.put(one, "A");
517          e = map.pollFirstEntry();
518 <        assertEquals(one, e.getKey());
519 <        assertEquals("A", e.getValue());
518 >        mustEqual(one, e.getKey());
519 >        mustEqual("A", e.getValue());
520          e = map.pollFirstEntry();
521 <        assertEquals(three, e.getKey());
521 >        mustEqual(three, e.getKey());
522          map.remove(four);
523          e = map.pollFirstEntry();
524 <        assertEquals(five, e.getKey());
524 >        mustEqual(five, e.getKey());
525          try {
526              e.setValue("A");
527              shouldThrow();
# Line 534 | Line 534 | public class TreeMapTest extends JSR166T
534       * pollLastEntry returns entries in order
535       */
536      public void testPollLastEntry() {
537 <        TreeMap map = map5();
538 <        Map.Entry e = map.pollLastEntry();
539 <        assertEquals(five, e.getKey());
540 <        assertEquals("E", e.getValue());
537 >        TreeMap<Item,String> map = map5();
538 >        Map.Entry<Item,String> e = map.pollLastEntry();
539 >        mustEqual(five, e.getKey());
540 >        mustEqual("E", e.getValue());
541          e = map.pollLastEntry();
542 <        assertEquals(four, e.getKey());
542 >        mustEqual(four, e.getKey());
543          map.put(five, "E");
544          e = map.pollLastEntry();
545 <        assertEquals(five, e.getKey());
546 <        assertEquals("E", e.getValue());
545 >        mustEqual(five, e.getKey());
546 >        mustEqual("E", e.getValue());
547          e = map.pollLastEntry();
548 <        assertEquals(three, e.getKey());
548 >        mustEqual(three, e.getKey());
549          map.remove(two);
550          e = map.pollLastEntry();
551 <        assertEquals(one, e.getKey());
551 >        mustEqual(one, e.getKey());
552          try {
553              e.setValue("E");
554              shouldThrow();
# Line 561 | Line 561 | public class TreeMapTest extends JSR166T
561       * size returns the correct values
562       */
563      public void testSize() {
564 <        TreeMap map = map5();
565 <        TreeMap empty = new TreeMap();
566 <        assertEquals(0, empty.size());
567 <        assertEquals(5, map.size());
564 >        TreeMap<Item,String> map = map5();
565 >        TreeMap<Item,String> empty = new TreeMap<Item,String>();
566 >        mustEqual(0, empty.size());
567 >        mustEqual(5, map.size());
568      }
569  
570      /**
571       * toString contains toString of elements
572       */
573      public void testToString() {
574 <        TreeMap map = map5();
574 >        TreeMap<Item,String> map = map5();
575          String s = map.toString();
576          for (int i = 1; i <= 5; ++i) {
577              assertTrue(s.contains(String.valueOf(i)));
# Line 584 | Line 584 | public class TreeMapTest extends JSR166T
584       * get(null) of nonempty map throws NPE
585       */
586      public void testGet_NullPointerException() {
587 <        TreeMap c = map5();
587 >        TreeMap<Item,String> c = map5();
588          try {
589              c.get(null);
590              shouldThrow();
# Line 595 | Line 595 | public class TreeMapTest extends JSR166T
595       * containsKey(null) of nonempty map throws NPE
596       */
597      public void testContainsKey_NullPointerException() {
598 <        TreeMap c = map5();
598 >        TreeMap<Item,String> c = map5();
599          try {
600              c.containsKey(null);
601              shouldThrow();
# Line 606 | Line 606 | public class TreeMapTest extends JSR166T
606       * remove(null) throws NPE for nonempty map
607       */
608      public void testRemove1_NullPointerException() {
609 <        TreeMap c = new TreeMap();
610 <        c.put("sadsdf", "asdads");
609 >        TreeMap<Item,String> c = new TreeMap<Item,String>();
610 >        c.put(one, "asdads");
611          try {
612              c.remove(null);
613              shouldThrow();
# Line 618 | Line 618 | public class TreeMapTest extends JSR166T
618       * A deserialized/reserialized map equals original
619       */
620      public void testSerialization() throws Exception {
621 <        NavigableMap x = map5();
622 <        NavigableMap y = serialClone(x);
621 >        NavigableMap<Item,String> x = map5();
622 >        NavigableMap<Item,String> y = serialClone(x);
623  
624          assertNotSame(x, y);
625 <        assertEquals(x.size(), y.size());
626 <        assertEquals(x.toString(), y.toString());
627 <        assertEquals(x, y);
628 <        assertEquals(y, x);
625 >        mustEqual(x.size(), y.size());
626 >        mustEqual(x.toString(), y.toString());
627 >        mustEqual(x, y);
628 >        mustEqual(y, x);
629      }
630  
631      /**
632       * subMap returns map with keys in requested range
633       */
634      public void testSubMapContents() {
635 <        TreeMap map = map5();
636 <        NavigableMap sm = map.subMap(two, true, four, false);
637 <        assertEquals(two, sm.firstKey());
638 <        assertEquals(three, sm.lastKey());
639 <        assertEquals(2, sm.size());
635 >        TreeMap<Item,String> map = map5();
636 >        NavigableMap<Item,String> sm = map.subMap(two, true, four, false);
637 >        mustEqual(two, sm.firstKey());
638 >        mustEqual(three, sm.lastKey());
639 >        mustEqual(2, sm.size());
640          assertFalse(sm.containsKey(one));
641          assertTrue(sm.containsKey(two));
642          assertTrue(sm.containsKey(three));
643          assertFalse(sm.containsKey(four));
644          assertFalse(sm.containsKey(five));
645 <        Iterator i = sm.keySet().iterator();
646 <        Object k;
647 <        k = (Integer)(i.next());
648 <        assertEquals(two, k);
649 <        k = (Integer)(i.next());
650 <        assertEquals(three, k);
645 >        Iterator<? extends Item> i = sm.keySet().iterator();
646 >        Item k;
647 >        k = (Item)(i.next());
648 >        mustEqual(two, k);
649 >        k = (Item)(i.next());
650 >        mustEqual(three, k);
651          assertFalse(i.hasNext());
652 <        Iterator r = sm.descendingKeySet().iterator();
653 <        k = (Integer)(r.next());
654 <        assertEquals(three, k);
655 <        k = (Integer)(r.next());
656 <        assertEquals(two, k);
652 >        Iterator<? extends Item> r = sm.descendingKeySet().iterator();
653 >        k = (Item)(r.next());
654 >        mustEqual(three, k);
655 >        k = (Item)(r.next());
656 >        mustEqual(two, k);
657          assertFalse(r.hasNext());
658  
659 <        Iterator j = sm.keySet().iterator();
659 >        Iterator<? extends Item> j = sm.keySet().iterator();
660          j.next();
661          j.remove();
662          assertFalse(map.containsKey(two));
663 <        assertEquals(4, map.size());
664 <        assertEquals(1, sm.size());
665 <        assertEquals(three, sm.firstKey());
666 <        assertEquals(three, sm.lastKey());
667 <        assertEquals("C", sm.remove(three));
663 >        mustEqual(4, map.size());
664 >        mustEqual(1, sm.size());
665 >        mustEqual(three, sm.firstKey());
666 >        mustEqual(three, sm.lastKey());
667 >        mustEqual("C", sm.remove(three));
668          assertTrue(sm.isEmpty());
669 <        assertEquals(3, map.size());
669 >        mustEqual(3, map.size());
670      }
671  
672      public void testSubMapContents2() {
673 <        TreeMap map = map5();
674 <        NavigableMap sm = map.subMap(two, true, three, false);
675 <        assertEquals(1, sm.size());
676 <        assertEquals(two, sm.firstKey());
677 <        assertEquals(two, sm.lastKey());
673 >        TreeMap<Item,String> map = map5();
674 >        NavigableMap<Item,String> sm = map.subMap(two, true, three, false);
675 >        mustEqual(1, sm.size());
676 >        mustEqual(two, sm.firstKey());
677 >        mustEqual(two, sm.lastKey());
678          assertFalse(sm.containsKey(one));
679          assertTrue(sm.containsKey(two));
680          assertFalse(sm.containsKey(three));
681          assertFalse(sm.containsKey(four));
682          assertFalse(sm.containsKey(five));
683 <        Iterator i = sm.keySet().iterator();
684 <        Object k;
685 <        k = (Integer)(i.next());
686 <        assertEquals(two, k);
683 >        Iterator<? extends Item> i = sm.keySet().iterator();
684 >        Item k;
685 >        k = (Item)(i.next());
686 >        mustEqual(two, k);
687          assertFalse(i.hasNext());
688 <        Iterator r = sm.descendingKeySet().iterator();
689 <        k = (Integer)(r.next());
690 <        assertEquals(two, k);
688 >        Iterator<? extends Item> r = sm.descendingKeySet().iterator();
689 >        k = (Item)(r.next());
690 >        mustEqual(two, k);
691          assertFalse(r.hasNext());
692  
693 <        Iterator j = sm.keySet().iterator();
693 >        Iterator<? extends Item> j = sm.keySet().iterator();
694          j.next();
695          j.remove();
696          assertFalse(map.containsKey(two));
697 <        assertEquals(4, map.size());
698 <        assertEquals(0, sm.size());
697 >        mustEqual(4, map.size());
698 >        mustEqual(0, sm.size());
699          assertTrue(sm.isEmpty());
700          assertSame(sm.remove(three), null);
701 <        assertEquals(4, map.size());
701 >        mustEqual(4, map.size());
702      }
703  
704      /**
705       * headMap returns map with keys in requested range
706       */
707      public void testHeadMapContents() {
708 <        TreeMap map = map5();
709 <        NavigableMap sm = map.headMap(four, false);
708 >        TreeMap<Item,String> map = map5();
709 >        NavigableMap<Item, String> sm = map.headMap(four, false);
710          assertTrue(sm.containsKey(one));
711          assertTrue(sm.containsKey(two));
712          assertTrue(sm.containsKey(three));
713          assertFalse(sm.containsKey(four));
714          assertFalse(sm.containsKey(five));
715 <        Iterator i = sm.keySet().iterator();
716 <        Object k;
717 <        k = (Integer)(i.next());
718 <        assertEquals(one, k);
719 <        k = (Integer)(i.next());
720 <        assertEquals(two, k);
721 <        k = (Integer)(i.next());
722 <        assertEquals(three, k);
715 >        Iterator<? extends Item> i = sm.keySet().iterator();
716 >        Item k;
717 >        k = (Item)(i.next());
718 >        mustEqual(one, k);
719 >        k = (Item)(i.next());
720 >        mustEqual(two, k);
721 >        k = (Item)(i.next());
722 >        mustEqual(three, k);
723          assertFalse(i.hasNext());
724          sm.clear();
725          assertTrue(sm.isEmpty());
726 <        assertEquals(2, map.size());
727 <        assertEquals(four, map.firstKey());
726 >        mustEqual(2, map.size());
727 >        mustEqual(four, map.firstKey());
728      }
729  
730      /**
731       * headMap returns map with keys in requested range
732       */
733      public void testTailMapContents() {
734 <        TreeMap map = map5();
735 <        NavigableMap sm = map.tailMap(two, true);
734 >        TreeMap<Item,String> map = map5();
735 >        NavigableMap<Item,String> sm = map.tailMap(two, true);
736          assertFalse(sm.containsKey(one));
737          assertTrue(sm.containsKey(two));
738          assertTrue(sm.containsKey(three));
739          assertTrue(sm.containsKey(four));
740          assertTrue(sm.containsKey(five));
741 <        Iterator i = sm.keySet().iterator();
742 <        Object k;
743 <        k = (Integer)(i.next());
744 <        assertEquals(two, k);
745 <        k = (Integer)(i.next());
746 <        assertEquals(three, k);
747 <        k = (Integer)(i.next());
748 <        assertEquals(four, k);
749 <        k = (Integer)(i.next());
750 <        assertEquals(five, k);
741 >        Iterator<? extends Item> i = sm.keySet().iterator();
742 >        Item k = (i.next());
743 >        mustEqual(two, k);
744 >        k = (i.next());
745 >        mustEqual(three, k);
746 >        k = (i.next());
747 >        mustEqual(four, k);
748 >        k = (i.next());
749 >        mustEqual(five, k);
750          assertFalse(i.hasNext());
751 <        Iterator r = sm.descendingKeySet().iterator();
752 <        k = (Integer)(r.next());
753 <        assertEquals(five, k);
754 <        k = (Integer)(r.next());
755 <        assertEquals(four, k);
756 <        k = (Integer)(r.next());
757 <        assertEquals(three, k);
758 <        k = (Integer)(r.next());
759 <        assertEquals(two, k);
751 >        Iterator<? extends Item> r = sm.descendingKeySet().iterator();
752 >        k = (r.next());
753 >        mustEqual(five, k);
754 >        k = (r.next());
755 >        mustEqual(four, k);
756 >        k = (r.next());
757 >        mustEqual(three, k);
758 >        k = (r.next());
759 >        mustEqual(two, k);
760          assertFalse(r.hasNext());
761  
762 <        Iterator ei = sm.entrySet().iterator();
763 <        Map.Entry e;
764 <        e = (Map.Entry)(ei.next());
765 <        assertEquals(two, e.getKey());
766 <        assertEquals("B", e.getValue());
767 <        e = (Map.Entry)(ei.next());
768 <        assertEquals(three, e.getKey());
769 <        assertEquals("C", e.getValue());
770 <        e = (Map.Entry)(ei.next());
771 <        assertEquals(four, e.getKey());
772 <        assertEquals("D", e.getValue());
773 <        e = (Map.Entry)(ei.next());
774 <        assertEquals(five, e.getKey());
775 <        assertEquals("E", e.getValue());
762 >        Iterator<Map.Entry<Item,String>> ei = sm.entrySet().iterator();
763 >        Map.Entry<Item,String> e;
764 >        e = (ei.next());
765 >        mustEqual(two, e.getKey());
766 >        mustEqual("B", e.getValue());
767 >        e = (ei.next());
768 >        mustEqual(three, e.getKey());
769 >        mustEqual("C", e.getValue());
770 >        e = (ei.next());
771 >        mustEqual(four, e.getKey());
772 >        mustEqual("D", e.getValue());
773 >        e = (ei.next());
774 >        mustEqual(five, e.getKey());
775 >        mustEqual("E", e.getValue());
776          assertFalse(i.hasNext());
777  
778 <        NavigableMap ssm = sm.tailMap(four, true);
779 <        assertEquals(four, ssm.firstKey());
780 <        assertEquals(five, ssm.lastKey());
781 <        assertEquals("D", ssm.remove(four));
782 <        assertEquals(1, ssm.size());
783 <        assertEquals(3, sm.size());
784 <        assertEquals(4, map.size());
778 >        NavigableMap<Item,String> ssm = sm.tailMap(four, true);
779 >        mustEqual(four, ssm.firstKey());
780 >        mustEqual(five, ssm.lastKey());
781 >        mustEqual("D", ssm.remove(four));
782 >        mustEqual(1, ssm.size());
783 >        mustEqual(3, sm.size());
784 >        mustEqual(4, map.size());
785      }
786  
787      Random rnd = new Random(666);
# Line 793 | Line 792 | public class TreeMapTest extends JSR166T
792       */
793      public void testRecursiveSubMaps() throws Exception {
794          int mapSize = expensiveTests ? 1000 : 100;
795 <        Class cl = TreeMap.class;
796 <        NavigableMap<Integer, Integer> map = newMap(cl);
795 >        Class<?> cl = TreeMap.class;
796 >        NavigableMap<Item, Item> map = newMap(cl);
797          bs = new BitSet(mapSize);
798  
799          populate(map, mapSize);
# Line 805 | Line 804 | public class TreeMapTest extends JSR166T
804          check(map,                 0, mapSize - 1, true);
805          check(map.descendingMap(), 0, mapSize - 1, false);
806  
807 <        bashSubMap(map.subMap(0, true, mapSize, false),
807 >        bashSubMap(map.subMap(zero, true, itemFor(mapSize), false),
808                     0, mapSize - 1, true);
809      }
810  
811 <    static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception {
812 <        NavigableMap<Integer, Integer> result
813 <            = (NavigableMap<Integer, Integer>) cl.getConstructor().newInstance();
814 <        assertEquals(0, result.size());
811 >    static NavigableMap<Item, Item> newMap(Class<?> cl) throws Exception {
812 >        @SuppressWarnings("unchecked")
813 >        NavigableMap<Item, Item> result
814 >            = (NavigableMap<Item, Item>) cl.getConstructor().newInstance();
815 >        mustEqual(0, result.size());
816          assertFalse(result.keySet().iterator().hasNext());
817          return result;
818      }
819  
820 <    void populate(NavigableMap<Integer, Integer> map, int limit) {
820 >    void populate(NavigableMap<Item, Item> map, int limit) {
821          for (int i = 0, n = 2 * limit / 3; i < n; i++) {
822              int key = rnd.nextInt(limit);
823              put(map, key);
824          }
825      }
826  
827 <    void mutateMap(NavigableMap<Integer, Integer> map, int min, int max) {
827 >    void mutateMap(NavigableMap<Item, Item> map, int min, int max) {
828          int size = map.size();
829          int rangeSize = max - min + 1;
830  
# Line 834 | Line 834 | public class TreeMapTest extends JSR166T
834          }
835  
836          // Remove a bunch of entries with iterator
837 <        for (Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) {
837 >        for (Iterator<Item> it = map.keySet().iterator(); it.hasNext(); ) {
838              if (rnd.nextBoolean()) {
839 <                bs.clear(it.next());
839 >                bs.clear(it.next().value);
840                  it.remove();
841              }
842          }
# Line 849 | Line 849 | public class TreeMapTest extends JSR166T
849          }
850      }
851  
852 <    void mutateSubMap(NavigableMap<Integer, Integer> map, int min, int max) {
852 >    void mutateSubMap(NavigableMap<Item, Item> map, int min, int max) {
853          int size = map.size();
854          int rangeSize = max - min + 1;
855  
# Line 859 | Line 859 | public class TreeMapTest extends JSR166T
859          }
860  
861          // Remove a bunch of entries with iterator
862 <        for (Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) {
862 >        for (Iterator<Item> it = map.keySet().iterator(); it.hasNext(); ) {
863              if (rnd.nextBoolean()) {
864 <                bs.clear(it.next());
864 >                bs.clear(it.next().value);
865                  it.remove();
866              }
867          }
# Line 873 | Line 873 | public class TreeMapTest extends JSR166T
873                  put(map, key);
874              } else {
875                  try {
876 <                    map.put(key, 2 * key);
876 >                    map.put(itemFor(key), itemFor(2 * key));
877                      shouldThrow();
878                  } catch (IllegalArgumentException success) {}
879              }
880          }
881      }
882  
883 <    void put(NavigableMap<Integer, Integer> map, int key) {
884 <        if (map.put(key, 2 * key) == null)
883 >    void put(NavigableMap<Item, Item> map, int key) {
884 >        if (map.put(itemFor(key), itemFor(2 * key)) == null)
885              bs.set(key);
886      }
887  
888 <    void remove(NavigableMap<Integer, Integer> map, int key) {
889 <        if (map.remove(key) != null)
888 >    void remove(NavigableMap<Item, Item> map, int key) {
889 >        if (map.remove(itemFor(key)) != null)
890              bs.clear(key);
891      }
892  
893 <    void bashSubMap(NavigableMap<Integer, Integer> map,
893 >    void bashSubMap(NavigableMap<Item, Item> map,
894                      int min, int max, boolean ascending) {
895          check(map, min, max, ascending);
896          check(map.descendingMap(), min, max, !ascending);
# Line 906 | Line 906 | public class TreeMapTest extends JSR166T
906  
907          // headMap - pick direction and endpoint inclusion randomly
908          boolean incl = rnd.nextBoolean();
909 <        NavigableMap<Integer,Integer> hm = map.headMap(midPoint, incl);
909 >        NavigableMap<Item,Item> hm = map.headMap(itemFor(midPoint), incl);
910          if (ascending) {
911              if (rnd.nextBoolean())
912                  bashSubMap(hm, min, midPoint - (incl ? 0 : 1), true);
# Line 923 | Line 923 | public class TreeMapTest extends JSR166T
923  
924          // tailMap - pick direction and endpoint inclusion randomly
925          incl = rnd.nextBoolean();
926 <        NavigableMap<Integer,Integer> tm = map.tailMap(midPoint,incl);
926 >        NavigableMap<Item,Item> tm = map.tailMap(itemFor(midPoint),incl);
927          if (ascending) {
928              if (rnd.nextBoolean())
929                  bashSubMap(tm, midPoint + (incl ? 0 : 1), max, true);
# Line 948 | Line 948 | public class TreeMapTest extends JSR166T
948          boolean lowIncl = rnd.nextBoolean();
949          boolean highIncl = rnd.nextBoolean();
950          if (ascending) {
951 <            NavigableMap<Integer,Integer> sm = map.subMap(
952 <                endpoints[0], lowIncl, endpoints[1], highIncl);
951 >            NavigableMap<Item,Item> sm = map.subMap(
952 >                itemFor(endpoints[0]), lowIncl, itemFor(endpoints[1]), highIncl);
953              if (rnd.nextBoolean())
954                  bashSubMap(sm, endpoints[0] + (lowIncl ? 0 : 1),
955                             endpoints[1] - (highIncl ? 0 : 1), true);
# Line 957 | Line 957 | public class TreeMapTest extends JSR166T
957                  bashSubMap(sm.descendingMap(), endpoints[0] + (lowIncl ? 0 : 1),
958                             endpoints[1] - (highIncl ? 0 : 1), false);
959          } else {
960 <            NavigableMap<Integer,Integer> sm = map.subMap(
961 <                endpoints[1], highIncl, endpoints[0], lowIncl);
960 >            NavigableMap<Item,Item> sm = map.subMap(
961 >                itemFor(endpoints[1]), highIncl, itemFor(endpoints[0]), lowIncl);
962              if (rnd.nextBoolean())
963                  bashSubMap(sm, endpoints[0] + (lowIncl ? 0 : 1),
964                             endpoints[1] - (highIncl ? 0 : 1), false);
# Line 971 | Line 971 | public class TreeMapTest extends JSR166T
971      /**
972       * min and max are both inclusive.  If max < min, interval is empty.
973       */
974 <    void check(NavigableMap<Integer, Integer> map,
974 >    void check(NavigableMap<Item, Item> map,
975                        final int min, final int max, final boolean ascending) {
976          class ReferenceSet {
977              int lower(int key) {
# Line 1035 | Line 1035 | public class TreeMapTest extends JSR166T
1035          int size = 0;
1036          for (int i = min; i <= max; i++) {
1037              boolean bsContainsI = bs.get(i);
1038 <            assertEquals(bsContainsI, map.containsKey(i));
1038 >            mustEqual(bsContainsI, map.containsKey(itemFor(i)));
1039              if (bsContainsI)
1040                  size++;
1041          }
1042 <        assertEquals(size, map.size());
1042 >        mustEqual(size, map.size());
1043  
1044          // Test contents using contains keySet iterator
1045          int size2 = 0;
1046          int previousKey = -1;
1047 <        for (int key : map.keySet()) {
1048 <            assertTrue(bs.get(key));
1047 >        for (Item key : map.keySet()) {
1048 >            assertTrue(bs.get(key.value));
1049              size2++;
1050              assertTrue(previousKey < 0 ||
1051 <                (ascending ? key - previousKey > 0 : key - previousKey < 0));
1052 <            previousKey = key;
1051 >                (ascending ? key.value - previousKey > 0 : key.value - previousKey < 0));
1052 >            previousKey = key.value;
1053          }
1054 <        assertEquals(size2, size);
1054 >        mustEqual(size2, size);
1055  
1056          // Test navigation ops
1057          for (int key = min - 1; key <= max + 1; key++) {
1058 <            assertEq(map.lowerKey(key), rs.lower(key));
1059 <            assertEq(map.floorKey(key), rs.floor(key));
1060 <            assertEq(map.higherKey(key), rs.higher(key));
1061 <            assertEq(map.ceilingKey(key), rs.ceiling(key));
1058 >            Item k = itemFor(key);
1059 >            assertEq(map.lowerKey(k), rs.lower(key));
1060 >            assertEq(map.floorKey(k), rs.floor(key));
1061 >            assertEq(map.higherKey(k), rs.higher(key));
1062 >            assertEq(map.ceilingKey(k), rs.ceiling(key));
1063          }
1064  
1065          // Test extrema
# Line 1066 | Line 1067 | public class TreeMapTest extends JSR166T
1067              assertEq(map.firstKey(), rs.first());
1068              assertEq(map.lastKey(), rs.last());
1069          } else {
1070 <            assertEq(rs.first(), -1);
1071 <            assertEq(rs.last(),  -1);
1070 >            mustEqual(rs.first(), -1);
1071 >            mustEqual(rs.last(),  -1);
1072              try {
1073                  map.firstKey();
1074                  shouldThrow();
# Line 1079 | Line 1080 | public class TreeMapTest extends JSR166T
1080          }
1081      }
1082  
1083 <    static void assertEq(Integer i, int j) {
1083 >    static void assertEq(Item i, int j) {
1084          if (i == null)
1085 <            assertEquals(j, -1);
1085 >            mustEqual(j, -1);
1086          else
1087 <            assertEquals((int) i, j);
1087 >            mustEqual(i, j);
1088      }
1089  
1090 <    static boolean eq(Integer i, int j) {
1091 <        return i == null ? j == -1 : i == j;
1090 >    static boolean eq(Item i, int j) {
1091 >        return i == null ? j == -1 : i.value == j;
1092      }
1093  
1094   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines