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); |
17 |
> |
return new TestSuite(TreeMapTest.class); |
18 |
|
} |
19 |
|
|
20 |
|
/** |
21 |
|
* Create a map from Integers 1-5 to Strings "A"-"E". |
22 |
|
*/ |
23 |
< |
private static TreeMap map5() { |
24 |
< |
TreeMap map = new TreeMap(); |
23 |
> |
private static TreeMap map5() { |
24 |
> |
TreeMap map = new TreeMap(); |
25 |
|
assertTrue(map.isEmpty()); |
26 |
< |
map.put(one, "A"); |
27 |
< |
map.put(five, "E"); |
28 |
< |
map.put(three, "C"); |
29 |
< |
map.put(two, "B"); |
30 |
< |
map.put(four, "D"); |
26 |
> |
map.put(one, "A"); |
27 |
> |
map.put(five, "E"); |
28 |
> |
map.put(three, "C"); |
29 |
> |
map.put(two, "B"); |
30 |
> |
map.put(four, "D"); |
31 |
|
assertFalse(map.isEmpty()); |
32 |
|
assertEquals(5, map.size()); |
33 |
< |
return map; |
33 |
> |
return map; |
34 |
|
} |
35 |
|
|
36 |
|
/** |
38 |
|
*/ |
39 |
|
public void testClear() { |
40 |
|
TreeMap map = map5(); |
41 |
< |
map.clear(); |
42 |
< |
assertEquals(map.size(), 0); |
41 |
> |
map.clear(); |
42 |
> |
assertEquals(map.size(), 0); |
43 |
|
} |
44 |
|
|
45 |
|
/** |
46 |
< |
* |
46 |
> |
* |
47 |
|
*/ |
48 |
|
public void testConstructFromSorted() { |
49 |
|
TreeMap map = map5(); |
59 |
|
TreeMap map2 = map5(); |
60 |
|
assertEquals(map1, map2); |
61 |
|
assertEquals(map2, map1); |
62 |
< |
map1.clear(); |
62 |
> |
map1.clear(); |
63 |
|
assertFalse(map1.equals(map2)); |
64 |
|
assertFalse(map2.equals(map1)); |
65 |
|
} |
69 |
|
*/ |
70 |
|
public void testContainsKey() { |
71 |
|
TreeMap map = map5(); |
72 |
< |
assertTrue(map.containsKey(one)); |
72 |
> |
assertTrue(map.containsKey(one)); |
73 |
|
assertFalse(map.containsKey(zero)); |
74 |
|
} |
75 |
|
|
78 |
|
*/ |
79 |
|
public void testContainsValue() { |
80 |
|
TreeMap map = map5(); |
81 |
< |
assertTrue(map.containsValue("A")); |
81 |
> |
assertTrue(map.containsValue("A")); |
82 |
|
assertFalse(map.containsValue("Z")); |
83 |
|
} |
84 |
|
|
88 |
|
*/ |
89 |
|
public void testGet() { |
90 |
|
TreeMap map = map5(); |
91 |
< |
assertEquals("A", (String)map.get(one)); |
91 |
> |
assertEquals("A", (String)map.get(one)); |
92 |
|
TreeMap empty = new TreeMap(); |
93 |
|
assertNull(empty.get(one)); |
94 |
|
} |
99 |
|
public void testIsEmpty() { |
100 |
|
TreeMap empty = new TreeMap(); |
101 |
|
TreeMap map = map5(); |
102 |
< |
assertTrue(empty.isEmpty()); |
102 |
> |
assertTrue(empty.isEmpty()); |
103 |
|
assertFalse(map.isEmpty()); |
104 |
|
} |
105 |
|
|
108 |
|
*/ |
109 |
|
public void testFirstKey() { |
110 |
|
TreeMap map = map5(); |
111 |
< |
assertEquals(one, map.firstKey()); |
111 |
> |
assertEquals(one, map.firstKey()); |
112 |
|
} |
113 |
|
|
114 |
|
/** |
116 |
|
*/ |
117 |
|
public void testLastKey() { |
118 |
|
TreeMap map = map5(); |
119 |
< |
assertEquals(five, map.lastKey()); |
119 |
> |
assertEquals(five, map.lastKey()); |
120 |
|
} |
121 |
|
|
122 |
|
|
125 |
|
*/ |
126 |
|
public void testKeySetToArray() { |
127 |
|
TreeMap map = map5(); |
128 |
< |
Set s = map.keySet(); |
128 |
> |
Set s = map.keySet(); |
129 |
|
Object[] ar = s.toArray(); |
130 |
|
assertTrue(s.containsAll(Arrays.asList(ar))); |
131 |
< |
assertEquals(5, ar.length); |
131 |
> |
assertEquals(5, ar.length); |
132 |
|
ar[0] = m10; |
133 |
|
assertFalse(s.containsAll(Arrays.asList(ar))); |
134 |
|
} |
138 |
|
*/ |
139 |
|
public void testDescendingKeySetToArray() { |
140 |
|
TreeMap map = map5(); |
141 |
< |
Set s = map.descendingKeySet(); |
141 |
> |
Set s = map.descendingKeySet(); |
142 |
|
Object[] ar = s.toArray(); |
143 |
< |
assertEquals(5, ar.length); |
143 |
> |
assertEquals(5, ar.length); |
144 |
|
assertTrue(s.containsAll(Arrays.asList(ar))); |
145 |
|
ar[0] = m10; |
146 |
|
assertFalse(s.containsAll(Arrays.asList(ar))); |
151 |
|
*/ |
152 |
|
public void testKeySet() { |
153 |
|
TreeMap map = map5(); |
154 |
< |
Set s = map.keySet(); |
155 |
< |
assertEquals(5, s.size()); |
156 |
< |
assertTrue(s.contains(one)); |
157 |
< |
assertTrue(s.contains(two)); |
158 |
< |
assertTrue(s.contains(three)); |
159 |
< |
assertTrue(s.contains(four)); |
160 |
< |
assertTrue(s.contains(five)); |
154 |
> |
Set s = map.keySet(); |
155 |
> |
assertEquals(5, s.size()); |
156 |
> |
assertTrue(s.contains(one)); |
157 |
> |
assertTrue(s.contains(two)); |
158 |
> |
assertTrue(s.contains(three)); |
159 |
> |
assertTrue(s.contains(four)); |
160 |
> |
assertTrue(s.contains(five)); |
161 |
|
} |
162 |
|
|
163 |
|
/** |
165 |
|
*/ |
166 |
|
public void testKeySetOrder() { |
167 |
|
TreeMap map = map5(); |
168 |
< |
Set s = map.keySet(); |
168 |
> |
Set s = map.keySet(); |
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 |
|
/** |
203 |
|
*/ |
204 |
|
public void testDescendingKeySetOrder() { |
205 |
|
TreeMap map = map5(); |
206 |
< |
Set s = map.descendingKeySet(); |
206 |
> |
Set s = map.descendingKeySet(); |
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 |
|
/** |
241 |
|
*/ |
242 |
|
public void testValues() { |
243 |
|
TreeMap map = map5(); |
244 |
< |
Collection s = map.values(); |
245 |
< |
assertEquals(5, s.size()); |
246 |
< |
assertTrue(s.contains("A")); |
247 |
< |
assertTrue(s.contains("B")); |
248 |
< |
assertTrue(s.contains("C")); |
249 |
< |
assertTrue(s.contains("D")); |
250 |
< |
assertTrue(s.contains("E")); |
244 |
> |
Collection s = map.values(); |
245 |
> |
assertEquals(5, s.size()); |
246 |
> |
assertTrue(s.contains("A")); |
247 |
> |
assertTrue(s.contains("B")); |
248 |
> |
assertTrue(s.contains("C")); |
249 |
> |
assertTrue(s.contains("D")); |
250 |
> |
assertTrue(s.contains("E")); |
251 |
|
} |
252 |
|
|
253 |
|
/** |
255 |
|
*/ |
256 |
|
public void testEntrySet() { |
257 |
|
TreeMap map = map5(); |
258 |
< |
Set s = map.entrySet(); |
259 |
< |
assertEquals(5, s.size()); |
258 |
> |
Set s = map.entrySet(); |
259 |
> |
assertEquals(5, s.size()); |
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")) || |
274 |
|
*/ |
275 |
|
public void testDescendingEntrySet() { |
276 |
|
TreeMap map = map5(); |
277 |
< |
Set s = map.descendingMap().entrySet(); |
278 |
< |
assertEquals(5, s.size()); |
277 |
> |
Set s = map.descendingMap().entrySet(); |
278 |
> |
assertEquals(5, s.size()); |
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")) || |
293 |
|
*/ |
294 |
|
public void testEntrySetToArray() { |
295 |
|
TreeMap map = map5(); |
296 |
< |
Set s = map.entrySet(); |
296 |
> |
Set s = map.entrySet(); |
297 |
|
Object[] ar = s.toArray(); |
298 |
|
assertEquals(5, ar.length); |
299 |
|
for (int i = 0; i < 5; ++i) { |
307 |
|
*/ |
308 |
|
public void testDescendingEntrySetToArray() { |
309 |
|
TreeMap map = map5(); |
310 |
< |
Set s = map.descendingMap().entrySet(); |
310 |
> |
Set s = map.descendingMap().entrySet(); |
311 |
|
Object[] ar = s.toArray(); |
312 |
|
assertEquals(5, ar.length); |
313 |
|
for (int i = 0; i < 5; ++i) { |
322 |
|
public void testPutAll() { |
323 |
|
TreeMap empty = new TreeMap(); |
324 |
|
TreeMap map = map5(); |
325 |
< |
empty.putAll(map); |
326 |
< |
assertEquals(5, empty.size()); |
327 |
< |
assertTrue(empty.containsKey(one)); |
328 |
< |
assertTrue(empty.containsKey(two)); |
329 |
< |
assertTrue(empty.containsKey(three)); |
330 |
< |
assertTrue(empty.containsKey(four)); |
331 |
< |
assertTrue(empty.containsKey(five)); |
325 |
> |
empty.putAll(map); |
326 |
> |
assertEquals(5, empty.size()); |
327 |
> |
assertTrue(empty.containsKey(one)); |
328 |
> |
assertTrue(empty.containsKey(two)); |
329 |
> |
assertTrue(empty.containsKey(three)); |
330 |
> |
assertTrue(empty.containsKey(four)); |
331 |
> |
assertTrue(empty.containsKey(five)); |
332 |
|
} |
333 |
|
|
334 |
|
/** |
336 |
|
*/ |
337 |
|
public void testRemove() { |
338 |
|
TreeMap map = map5(); |
339 |
< |
map.remove(five); |
340 |
< |
assertEquals(4, map.size()); |
341 |
< |
assertFalse(map.containsKey(five)); |
339 |
> |
map.remove(five); |
340 |
> |
assertEquals(4, map.size()); |
341 |
> |
assertFalse(map.containsKey(five)); |
342 |
|
} |
343 |
|
|
344 |
|
/** |
516 |
|
try { |
517 |
|
e.setValue("A"); |
518 |
|
shouldThrow(); |
519 |
< |
} catch (Exception ok) { |
476 |
< |
} |
519 |
> |
} catch (UnsupportedOperationException success) {} |
520 |
|
e = map.pollFirstEntry(); |
521 |
|
assertNull(e); |
522 |
|
} |
543 |
|
try { |
544 |
|
e.setValue("E"); |
545 |
|
shouldThrow(); |
546 |
< |
} catch (Exception ok) { |
504 |
< |
} |
546 |
> |
} catch (UnsupportedOperationException success) {} |
547 |
|
e = map.pollLastEntry(); |
548 |
|
assertNull(e); |
549 |
|
} |
554 |
|
public void testSize() { |
555 |
|
TreeMap map = map5(); |
556 |
|
TreeMap empty = new TreeMap(); |
557 |
< |
assertEquals(0, empty.size()); |
558 |
< |
assertEquals(5, map.size()); |
557 |
> |
assertEquals(0, empty.size()); |
558 |
> |
assertEquals(5, map.size()); |
559 |
|
} |
560 |
|
|
561 |
|
/** |
567 |
|
for (int i = 1; i <= 5; ++i) { |
568 |
|
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
569 |
|
} |
570 |
< |
} |
570 |
> |
} |
571 |
|
|
572 |
|
// Exception tests |
573 |
|
|
579 |
|
TreeMap c = map5(); |
580 |
|
c.get(null); |
581 |
|
shouldThrow(); |
582 |
< |
} catch(NullPointerException e){} |
582 |
> |
} catch (NullPointerException success) {} |
583 |
|
} |
584 |
|
|
585 |
|
/** |
590 |
|
TreeMap c = map5(); |
591 |
|
c.containsKey(null); |
592 |
|
shouldThrow(); |
593 |
< |
} catch(NullPointerException e){} |
593 |
> |
} catch (NullPointerException success) {} |
594 |
|
} |
595 |
|
|
596 |
|
/** |
602 |
|
c.put("sadsdf", "asdads"); |
603 |
|
c.remove(null); |
604 |
|
shouldThrow(); |
605 |
< |
} catch(NullPointerException e){} |
605 |
> |
} catch (NullPointerException success) {} |
606 |
|
} |
607 |
|
|
608 |
|
/** |
609 |
|
* A deserialized map equals original |
610 |
|
*/ |
611 |
< |
public void testSerialization() { |
611 |
> |
public void testSerialization() throws Exception { |
612 |
|
TreeMap q = map5(); |
613 |
|
|
614 |
< |
try { |
615 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
616 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
617 |
< |
out.writeObject(q); |
618 |
< |
out.close(); |
619 |
< |
|
620 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
621 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
622 |
< |
TreeMap r = (TreeMap)in.readObject(); |
623 |
< |
assertEquals(q.size(), r.size()); |
624 |
< |
assertTrue(q.equals(r)); |
583 |
< |
assertTrue(r.equals(q)); |
584 |
< |
} catch(Exception e){ |
585 |
< |
e.printStackTrace(); |
586 |
< |
unexpectedException(); |
587 |
< |
} |
614 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
615 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
616 |
> |
out.writeObject(q); |
617 |
> |
out.close(); |
618 |
> |
|
619 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
620 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
621 |
> |
TreeMap r = (TreeMap)in.readObject(); |
622 |
> |
assertEquals(q.size(), r.size()); |
623 |
> |
assertTrue(q.equals(r)); |
624 |
> |
assertTrue(r.equals(q)); |
625 |
|
} |
626 |
|
|
627 |
|
/** |
629 |
|
*/ |
630 |
|
public void testSubMapContents() { |
631 |
|
TreeMap map = map5(); |
632 |
< |
NavigableMap sm = map.navigableSubMap(two, true, four, false); |
632 |
> |
NavigableMap sm = map.subMap(two, true, four, false); |
633 |
|
assertEquals(two, sm.firstKey()); |
634 |
|
assertEquals(three, sm.lastKey()); |
635 |
|
assertEquals(2, sm.size()); |
651 |
|
k = (Integer)(r.next()); |
652 |
|
assertEquals(two, k); |
653 |
|
assertFalse(r.hasNext()); |
654 |
< |
|
654 |
> |
|
655 |
|
Iterator j = sm.keySet().iterator(); |
656 |
|
j.next(); |
657 |
|
j.remove(); |
660 |
|
assertEquals(1, sm.size()); |
661 |
|
assertEquals(three, sm.firstKey()); |
662 |
|
assertEquals(three, sm.lastKey()); |
663 |
< |
assertTrue(sm.remove(three) != null); |
663 |
> |
assertEquals("C", sm.remove(three)); |
664 |
|
assertTrue(sm.isEmpty()); |
665 |
|
assertEquals(3, map.size()); |
666 |
|
} |
667 |
|
|
668 |
|
public void testSubMapContents2() { |
669 |
|
TreeMap map = map5(); |
670 |
< |
NavigableMap sm = map.navigableSubMap(two, true, three, false); |
670 |
> |
NavigableMap sm = map.subMap(two, true, three, false); |
671 |
|
assertEquals(1, sm.size()); |
672 |
|
assertEquals(two, sm.firstKey()); |
673 |
|
assertEquals(two, sm.lastKey()); |
685 |
|
k = (Integer)(r.next()); |
686 |
|
assertEquals(two, k); |
687 |
|
assertFalse(r.hasNext()); |
688 |
< |
|
688 |
> |
|
689 |
|
Iterator j = sm.keySet().iterator(); |
690 |
|
j.next(); |
691 |
|
j.remove(); |
693 |
|
assertEquals(4, map.size()); |
694 |
|
assertEquals(0, sm.size()); |
695 |
|
assertTrue(sm.isEmpty()); |
696 |
< |
assertTrue(sm.remove(three) == null); |
696 |
> |
assertSame(sm.remove(three), null); |
697 |
|
assertEquals(4, map.size()); |
698 |
|
} |
699 |
|
|
702 |
|
*/ |
703 |
|
public void testHeadMapContents() { |
704 |
|
TreeMap map = map5(); |
705 |
< |
NavigableMap sm = map.navigableHeadMap(four, false); |
705 |
> |
NavigableMap sm = map.headMap(four, false); |
706 |
|
assertTrue(sm.containsKey(one)); |
707 |
|
assertTrue(sm.containsKey(two)); |
708 |
|
assertTrue(sm.containsKey(three)); |
728 |
|
*/ |
729 |
|
public void testTailMapContents() { |
730 |
|
TreeMap map = map5(); |
731 |
< |
NavigableMap sm = map.navigableTailMap(two, true); |
731 |
> |
NavigableMap sm = map.tailMap(two, true); |
732 |
|
assertFalse(sm.containsKey(one)); |
733 |
|
assertTrue(sm.containsKey(two)); |
734 |
|
assertTrue(sm.containsKey(three)); |
772 |
|
assertEquals("E", e.getValue()); |
773 |
|
assertFalse(i.hasNext()); |
774 |
|
|
775 |
< |
NavigableMap ssm = sm.navigableTailMap(four, true); |
775 |
> |
NavigableMap ssm = sm.tailMap(four, true); |
776 |
|
assertEquals(four, ssm.firstKey()); |
777 |
|
assertEquals(five, ssm.lastKey()); |
778 |
< |
assertTrue(ssm.remove(four) != null); |
778 |
> |
assertEquals("D", ssm.remove(four)); |
779 |
|
assertEquals(1, ssm.size()); |
780 |
|
assertEquals(3, sm.size()); |
781 |
|
assertEquals(4, map.size()); |
787 |
|
/** |
788 |
|
* Submaps of submaps subdivide correctly |
789 |
|
*/ |
790 |
< |
public void testRecursiveSubMaps() { |
791 |
< |
int mapSize = 1000; |
792 |
< |
Class cl = TreeMap.class; |
790 |
> |
public void testRecursiveSubMaps() throws Exception { |
791 |
> |
int mapSize = 1000; |
792 |
> |
Class cl = TreeMap.class; |
793 |
|
NavigableMap<Integer, Integer> map = newMap(cl); |
794 |
|
bs = new BitSet(mapSize); |
795 |
|
|
801 |
|
check(map, 0, mapSize - 1, true); |
802 |
|
check(map.descendingMap(), 0, mapSize - 1, false); |
803 |
|
|
804 |
< |
bashSubMap(map.navigableSubMap(0, true, mapSize, false), |
804 |
> |
bashSubMap(map.subMap(0, true, mapSize, false), |
805 |
|
0, mapSize - 1, true); |
806 |
|
} |
807 |
|
|
808 |
< |
static NavigableMap<Integer, Integer> newMap(Class cl) { |
809 |
< |
NavigableMap<Integer, Integer> result = null; |
810 |
< |
try { |
774 |
< |
result = (NavigableMap<Integer, Integer>) cl.newInstance(); |
775 |
< |
} catch(Exception e) { |
776 |
< |
fail(); |
777 |
< |
} |
808 |
> |
static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception { |
809 |
> |
NavigableMap<Integer, Integer> result |
810 |
> |
= (NavigableMap<Integer, Integer>) cl.newInstance(); |
811 |
|
assertEquals(result.size(), 0); |
812 |
|
assertFalse(result.keySet().iterator().hasNext()); |
813 |
|
return result; |
830 |
|
} |
831 |
|
|
832 |
|
// Remove a bunch of entries with iterator |
833 |
< |
for(Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) { |
833 |
> |
for (Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) { |
834 |
|
if (rnd.nextBoolean()) { |
835 |
|
bs.clear(it.next()); |
836 |
|
it.remove(); |
855 |
|
} |
856 |
|
|
857 |
|
// Remove a bunch of entries with iterator |
858 |
< |
for(Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) { |
858 |
> |
for (Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) { |
859 |
|
if (rnd.nextBoolean()) { |
860 |
|
bs.clear(it.next()); |
861 |
|
it.remove(); |
870 |
|
} else { |
871 |
|
try { |
872 |
|
map.put(key, 2 * key); |
873 |
< |
fail(); |
874 |
< |
} catch(IllegalArgumentException e) { |
842 |
< |
// expected |
843 |
< |
} |
873 |
> |
shouldThrow(); |
874 |
> |
} catch (IllegalArgumentException success) {} |
875 |
|
} |
876 |
|
} |
877 |
|
} |
902 |
|
|
903 |
|
// headMap - pick direction and endpoint inclusion randomly |
904 |
|
boolean incl = rnd.nextBoolean(); |
905 |
< |
NavigableMap<Integer,Integer> hm = map.navigableHeadMap(midPoint, incl); |
905 |
> |
NavigableMap<Integer,Integer> hm = map.headMap(midPoint, incl); |
906 |
|
if (ascending) { |
907 |
|
if (rnd.nextBoolean()) |
908 |
|
bashSubMap(hm, min, midPoint - (incl ? 0 : 1), true); |
919 |
|
|
920 |
|
// tailMap - pick direction and endpoint inclusion randomly |
921 |
|
incl = rnd.nextBoolean(); |
922 |
< |
NavigableMap<Integer,Integer> tm = map.navigableTailMap(midPoint,incl); |
922 |
> |
NavigableMap<Integer,Integer> tm = map.tailMap(midPoint,incl); |
923 |
|
if (ascending) { |
924 |
|
if (rnd.nextBoolean()) |
925 |
|
bashSubMap(tm, midPoint + (incl ? 0 : 1), max, true); |
944 |
|
boolean lowIncl = rnd.nextBoolean(); |
945 |
|
boolean highIncl = rnd.nextBoolean(); |
946 |
|
if (ascending) { |
947 |
< |
NavigableMap<Integer,Integer> sm = map.navigableSubMap( |
947 |
> |
NavigableMap<Integer,Integer> sm = map.subMap( |
948 |
|
endpoints[0], lowIncl, endpoints[1], highIncl); |
949 |
|
if (rnd.nextBoolean()) |
950 |
|
bashSubMap(sm, endpoints[0] + (lowIncl ? 0 : 1), |
953 |
|
bashSubMap(sm.descendingMap(), endpoints[0] + (lowIncl ? 0 : 1), |
954 |
|
endpoints[1] - (highIncl ? 0 : 1), false); |
955 |
|
} else { |
956 |
< |
NavigableMap<Integer,Integer> sm = map.navigableSubMap( |
956 |
> |
NavigableMap<Integer,Integer> sm = map.subMap( |
957 |
|
endpoints[1], highIncl, endpoints[0], lowIncl); |
958 |
|
if (rnd.nextBoolean()) |
959 |
|
bashSubMap(sm, endpoints[0] + (lowIncl ? 0 : 1), |
1066 |
|
assertEq(rs.last(), -1); |
1067 |
|
try { |
1068 |
|
map.firstKey(); |
1069 |
< |
fail(); |
1070 |
< |
} catch(NoSuchElementException e) { |
1040 |
< |
// expected |
1041 |
< |
} |
1069 |
> |
shouldThrow(); |
1070 |
> |
} catch (NoSuchElementException success) {} |
1071 |
|
try { |
1072 |
|
map.lastKey(); |
1073 |
< |
fail(); |
1074 |
< |
} catch(NoSuchElementException e) { |
1046 |
< |
// expected |
1047 |
< |
} |
1073 |
> |
shouldThrow(); |
1074 |
> |
} catch (NoSuchElementException success) {} |
1075 |
|
} |
1076 |
|
} |
1077 |
|
|
1085 |
|
static boolean eq(Integer i, int j) { |
1086 |
|
return i == null ? j == -1 : i == j; |
1087 |
|
} |
1088 |
< |
|
1088 |
> |
|
1089 |
|
} |