40 |
|
* Returns a new map from Items 1-5 to Strings "A"-"E". |
41 |
|
*/ |
42 |
|
private static TreeMap<Item,String> map5() { |
43 |
< |
TreeMap<Item,String> map = new TreeMap<Item,String>(); |
43 |
> |
TreeMap<Item,String> map = new TreeMap<>(); |
44 |
|
assertTrue(map.isEmpty()); |
45 |
|
map.put(one, "A"); |
46 |
|
map.put(five, "E"); |
66 |
|
*/ |
67 |
|
public void testConstructFromSorted() { |
68 |
|
TreeMap<Item,String> map = map5(); |
69 |
< |
TreeMap<Item,String> map2 = new TreeMap<Item,String>(map); |
69 |
> |
TreeMap<Item,String> map2 = new TreeMap<>(map); |
70 |
|
mustEqual(map, map2); |
71 |
|
} |
72 |
|
|
108 |
|
public void testGet() { |
109 |
|
TreeMap<Item,String> map = map5(); |
110 |
|
mustEqual("A", map.get(one)); |
111 |
< |
TreeMap<Item,String> empty = new TreeMap<Item,String>(); |
111 |
> |
TreeMap<Item,String> empty = new TreeMap<>(); |
112 |
|
assertNull(empty.get(one)); |
113 |
|
} |
114 |
|
|
116 |
|
* isEmpty is true of empty map and false for non-empty |
117 |
|
*/ |
118 |
|
public void testIsEmpty() { |
119 |
< |
TreeMap<Item,String> empty = new TreeMap<Item,String>(); |
119 |
> |
TreeMap<Item,String> empty = new TreeMap<>(); |
120 |
|
TreeMap<Item,String> map = map5(); |
121 |
|
assertTrue(empty.isEmpty()); |
122 |
|
assertFalse(map.isEmpty()); |
338 |
|
* putAll adds all key-value pairs from the given map |
339 |
|
*/ |
340 |
|
public void testPutAll() { |
341 |
< |
TreeMap<Item,String> empty = new TreeMap<Item,String>(); |
341 |
> |
TreeMap<Item,String> empty = new TreeMap<>(); |
342 |
|
TreeMap<Item,String> map = map5(); |
343 |
|
empty.putAll(map); |
344 |
|
mustEqual(5, empty.size()); |
562 |
|
*/ |
563 |
|
public void testSize() { |
564 |
|
TreeMap<Item,String> map = map5(); |
565 |
< |
TreeMap<Item,String> empty = new TreeMap<Item,String>(); |
565 |
> |
TreeMap<Item,String> empty = new TreeMap<>(); |
566 |
|
mustEqual(0, empty.size()); |
567 |
|
mustEqual(5, map.size()); |
568 |
|
} |
606 |
|
* remove(null) throws NPE for nonempty map |
607 |
|
*/ |
608 |
|
public void testRemove1_NullPointerException() { |
609 |
< |
TreeMap<Item,String> c = new TreeMap<Item,String>(); |
609 |
> |
TreeMap<Item,String> c = new TreeMap<>(); |
610 |
|
c.put(one, "asdads"); |
611 |
|
try { |
612 |
|
c.remove(null); |