1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
< |
import junit.framework.*; |
8 |
< |
import java.util.*; |
9 |
< |
import java.util.concurrent.*; |
10 |
< |
import java.io.*; |
7 |
> |
import java.util.Arrays; |
8 |
> |
import java.util.BitSet; |
9 |
> |
import java.util.Collection; |
10 |
> |
import java.util.Comparator; |
11 |
> |
import java.util.Iterator; |
12 |
> |
import java.util.NavigableSet; |
13 |
> |
import java.util.NoSuchElementException; |
14 |
> |
import java.util.Random; |
15 |
> |
import java.util.Set; |
16 |
> |
import java.util.SortedSet; |
17 |
> |
import java.util.TreeSet; |
18 |
> |
|
19 |
> |
import junit.framework.Test; |
20 |
> |
import junit.framework.TestSuite; |
21 |
|
|
22 |
|
public class TreeSetTest extends JSR166TestCase { |
23 |
|
public static void main(String[] args) { |
24 |
< |
junit.textui.TestRunner.run (suite()); |
24 |
> |
junit.textui.TestRunner.run(suite()); |
25 |
|
} |
26 |
|
public static Test suite() { |
27 |
< |
return new TestSuite(TreeSetTest.class); |
27 |
> |
return new TestSuite(TreeSetTest.class); |
28 |
|
} |
29 |
|
|
30 |
< |
static class MyReverseComparator implements Comparator { |
30 |
> |
static class MyReverseComparator implements Comparator { |
31 |
|
public int compare(Object x, Object y) { |
32 |
< |
int i = ((Integer)x).intValue(); |
23 |
< |
int j = ((Integer)y).intValue(); |
24 |
< |
if (i < j) return 1; |
25 |
< |
if (i > j) return -1; |
26 |
< |
return 0; |
32 |
> |
return ((Comparable)y).compareTo(x); |
33 |
|
} |
34 |
|
} |
35 |
|
|
39 |
|
static final int SIZE = 20; |
40 |
|
|
41 |
|
/** |
42 |
< |
* Create a set of given size containing consecutive |
42 |
> |
* Returns a new set of given size containing consecutive |
43 |
|
* Integers 0 ... n. |
44 |
|
*/ |
45 |
< |
private TreeSet populatedSet(int n) { |
46 |
< |
TreeSet q = new TreeSet(); |
45 |
> |
private TreeSet<Integer> populatedSet(int n) { |
46 |
> |
TreeSet<Integer> q = new TreeSet<Integer>(); |
47 |
|
assertTrue(q.isEmpty()); |
48 |
< |
for(int i = n-1; i >= 0; i-=2) |
49 |
< |
assertTrue(q.add(new Integer(i))); |
50 |
< |
for(int i = (n & 1); i < n; i+=2) |
51 |
< |
assertTrue(q.add(new Integer(i))); |
48 |
> |
for (int i = n-1; i >= 0; i-=2) |
49 |
> |
assertTrue(q.add(new Integer(i))); |
50 |
> |
for (int i = (n & 1); i < n; i+=2) |
51 |
> |
assertTrue(q.add(new Integer(i))); |
52 |
|
assertFalse(q.isEmpty()); |
53 |
< |
assertEquals(n, q.size()); |
53 |
> |
assertEquals(n, q.size()); |
54 |
|
return q; |
55 |
|
} |
56 |
|
|
57 |
|
/** |
58 |
< |
* Create set of first 5 ints |
58 |
> |
* Returns a new set of first 5 ints. |
59 |
|
*/ |
60 |
|
private TreeSet set5() { |
61 |
|
TreeSet q = new TreeSet(); |
65 |
|
q.add(three); |
66 |
|
q.add(four); |
67 |
|
q.add(five); |
68 |
< |
assertEquals(5, q.size()); |
68 |
> |
assertEquals(5, q.size()); |
69 |
|
return q; |
70 |
|
} |
71 |
< |
|
71 |
> |
|
72 |
|
/** |
73 |
|
* A new set has unbounded capacity |
74 |
|
*/ |
83 |
|
try { |
84 |
|
TreeSet q = new TreeSet((Collection)null); |
85 |
|
shouldThrow(); |
86 |
< |
} |
81 |
< |
catch (NullPointerException success) {} |
86 |
> |
} catch (NullPointerException success) {} |
87 |
|
} |
88 |
|
|
89 |
|
/** |
94 |
|
Integer[] ints = new Integer[SIZE]; |
95 |
|
TreeSet q = new TreeSet(Arrays.asList(ints)); |
96 |
|
shouldThrow(); |
97 |
< |
} |
93 |
< |
catch (NullPointerException success) {} |
97 |
> |
} catch (NullPointerException success) {} |
98 |
|
} |
99 |
|
|
100 |
|
/** |
107 |
|
ints[i] = new Integer(i); |
108 |
|
TreeSet q = new TreeSet(Arrays.asList(ints)); |
109 |
|
shouldThrow(); |
110 |
< |
} |
107 |
< |
catch (NullPointerException success) {} |
110 |
> |
} catch (NullPointerException success) {} |
111 |
|
} |
112 |
|
|
113 |
|
/** |
114 |
|
* Set contains all elements of collection used to initialize |
115 |
|
*/ |
116 |
|
public void testConstructor6() { |
117 |
< |
try { |
118 |
< |
Integer[] ints = new Integer[SIZE]; |
119 |
< |
for (int i = 0; i < SIZE; ++i) |
120 |
< |
ints[i] = new Integer(i); |
121 |
< |
TreeSet q = new TreeSet(Arrays.asList(ints)); |
122 |
< |
for (int i = 0; i < SIZE; ++i) |
120 |
< |
assertEquals(ints[i], q.pollFirst()); |
121 |
< |
} |
122 |
< |
finally {} |
117 |
> |
Integer[] ints = new Integer[SIZE]; |
118 |
> |
for (int i = 0; i < SIZE; ++i) |
119 |
> |
ints[i] = new Integer(i); |
120 |
> |
TreeSet q = new TreeSet(Arrays.asList(ints)); |
121 |
> |
for (int i = 0; i < SIZE; ++i) |
122 |
> |
assertEquals(ints[i], q.pollFirst()); |
123 |
|
} |
124 |
|
|
125 |
|
/** |
126 |
|
* The comparator used in constructor is used |
127 |
|
*/ |
128 |
|
public void testConstructor7() { |
129 |
< |
try { |
130 |
< |
MyReverseComparator cmp = new MyReverseComparator(); |
131 |
< |
TreeSet q = new TreeSet(cmp); |
132 |
< |
assertEquals(cmp, q.comparator()); |
133 |
< |
Integer[] ints = new Integer[SIZE]; |
134 |
< |
for (int i = 0; i < SIZE; ++i) |
135 |
< |
ints[i] = new Integer(i); |
136 |
< |
q.addAll(Arrays.asList(ints)); |
137 |
< |
for (int i = SIZE-1; i >= 0; --i) |
138 |
< |
assertEquals(ints[i], q.pollFirst()); |
139 |
< |
} |
140 |
< |
finally {} |
129 |
> |
MyReverseComparator cmp = new MyReverseComparator(); |
130 |
> |
TreeSet q = new TreeSet(cmp); |
131 |
> |
assertEquals(cmp, q.comparator()); |
132 |
> |
Integer[] ints = new Integer[SIZE]; |
133 |
> |
for (int i = 0; i < SIZE; ++i) |
134 |
> |
ints[i] = new Integer(i); |
135 |
> |
q.addAll(Arrays.asList(ints)); |
136 |
> |
for (int i = SIZE-1; i >= 0; --i) |
137 |
> |
assertEquals(ints[i], q.pollFirst()); |
138 |
|
} |
139 |
|
|
140 |
|
/** |
170 |
|
* add(null) throws NPE if nonempty |
171 |
|
*/ |
172 |
|
public void testAddNull() { |
173 |
< |
try { |
173 |
> |
try { |
174 |
|
TreeSet q = populatedSet(SIZE); |
175 |
|
q.add(null); |
176 |
|
shouldThrow(); |
177 |
< |
} catch (NullPointerException success) { } |
177 |
> |
} catch (NullPointerException success) {} |
178 |
|
} |
179 |
|
|
180 |
|
/** |
205 |
|
q.add(new Object()); |
206 |
|
q.add(new Object()); |
207 |
|
shouldThrow(); |
208 |
< |
} |
212 |
< |
catch(ClassCastException success) {} |
208 |
> |
} catch (ClassCastException success) {} |
209 |
|
} |
210 |
|
|
211 |
|
/** |
216 |
|
TreeSet q = new TreeSet(); |
217 |
|
q.addAll(null); |
218 |
|
shouldThrow(); |
219 |
< |
} |
224 |
< |
catch (NullPointerException success) {} |
219 |
> |
} catch (NullPointerException success) {} |
220 |
|
} |
221 |
+ |
|
222 |
|
/** |
223 |
|
* addAll of a collection with null elements throws NPE |
224 |
|
*/ |
228 |
|
Integer[] ints = new Integer[SIZE]; |
229 |
|
q.addAll(Arrays.asList(ints)); |
230 |
|
shouldThrow(); |
231 |
< |
} |
236 |
< |
catch (NullPointerException success) {} |
231 |
> |
} catch (NullPointerException success) {} |
232 |
|
} |
233 |
+ |
|
234 |
|
/** |
235 |
|
* addAll of a collection with any null elements throws NPE after |
236 |
|
* possibly adding some elements |
243 |
|
ints[i] = new Integer(i); |
244 |
|
q.addAll(Arrays.asList(ints)); |
245 |
|
shouldThrow(); |
246 |
< |
} |
251 |
< |
catch (NullPointerException success) {} |
246 |
> |
} catch (NullPointerException success) {} |
247 |
|
} |
248 |
|
|
249 |
|
/** |
250 |
|
* Set contains all elements of successful addAll |
251 |
|
*/ |
252 |
|
public void testAddAll5() { |
253 |
< |
try { |
254 |
< |
Integer[] empty = new Integer[0]; |
255 |
< |
Integer[] ints = new Integer[SIZE]; |
256 |
< |
for (int i = 0; i < SIZE; ++i) |
257 |
< |
ints[i] = new Integer(SIZE-1-i); |
258 |
< |
TreeSet q = new TreeSet(); |
259 |
< |
assertFalse(q.addAll(Arrays.asList(empty))); |
260 |
< |
assertTrue(q.addAll(Arrays.asList(ints))); |
261 |
< |
for (int i = 0; i < SIZE; ++i) |
267 |
< |
assertEquals(new Integer(i), q.pollFirst()); |
268 |
< |
} |
269 |
< |
finally {} |
253 |
> |
Integer[] empty = new Integer[0]; |
254 |
> |
Integer[] ints = new Integer[SIZE]; |
255 |
> |
for (int i = 0; i < SIZE; ++i) |
256 |
> |
ints[i] = new Integer(SIZE-1-i); |
257 |
> |
TreeSet q = new TreeSet(); |
258 |
> |
assertFalse(q.addAll(Arrays.asList(empty))); |
259 |
> |
assertTrue(q.addAll(Arrays.asList(ints))); |
260 |
> |
for (int i = 0; i < SIZE; ++i) |
261 |
> |
assertEquals(new Integer(i), q.pollFirst()); |
262 |
|
} |
263 |
|
|
264 |
|
/** |
267 |
|
public void testPollFirst() { |
268 |
|
TreeSet q = populatedSet(SIZE); |
269 |
|
for (int i = 0; i < SIZE; ++i) { |
270 |
< |
assertEquals(i, ((Integer)q.pollFirst()).intValue()); |
270 |
> |
assertEquals(i, q.pollFirst()); |
271 |
|
} |
272 |
< |
assertNull(q.pollFirst()); |
272 |
> |
assertNull(q.pollFirst()); |
273 |
|
} |
274 |
|
|
275 |
|
/** |
278 |
|
public void testPollLast() { |
279 |
|
TreeSet q = populatedSet(SIZE); |
280 |
|
for (int i = SIZE-1; i >= 0; --i) { |
281 |
< |
assertEquals(i, ((Integer)q.pollLast()).intValue()); |
281 |
> |
assertEquals(i, q.pollLast()); |
282 |
|
} |
283 |
< |
assertNull(q.pollFirst()); |
283 |
> |
assertNull(q.pollFirst()); |
284 |
|
} |
285 |
|
|
294 |
– |
|
286 |
|
/** |
287 |
|
* remove(x) removes x and returns true if present |
288 |
|
*/ |
289 |
|
public void testRemoveElement() { |
290 |
|
TreeSet q = populatedSet(SIZE); |
291 |
|
for (int i = 1; i < SIZE; i+=2) { |
292 |
< |
assertTrue(q.remove(new Integer(i))); |
292 |
> |
assertTrue(q.contains(i)); |
293 |
> |
assertTrue(q.remove(i)); |
294 |
> |
assertFalse(q.contains(i)); |
295 |
> |
assertTrue(q.contains(i-1)); |
296 |
|
} |
297 |
|
for (int i = 0; i < SIZE; i+=2) { |
298 |
< |
assertTrue(q.remove(new Integer(i))); |
299 |
< |
assertFalse(q.remove(new Integer(i+1))); |
298 |
> |
assertTrue(q.contains(i)); |
299 |
> |
assertTrue(q.remove(i)); |
300 |
> |
assertFalse(q.contains(i)); |
301 |
> |
assertFalse(q.remove(i+1)); |
302 |
> |
assertFalse(q.contains(i+1)); |
303 |
|
} |
304 |
|
assertTrue(q.isEmpty()); |
305 |
|
} |
306 |
< |
|
306 |
> |
|
307 |
|
/** |
308 |
|
* contains(x) reports true when elements added but not yet removed |
309 |
|
*/ |
379 |
|
} |
380 |
|
} |
381 |
|
|
385 |
– |
|
386 |
– |
|
382 |
|
/** |
383 |
|
* lower returns preceding element |
384 |
|
*/ |
395 |
|
|
396 |
|
Object e4 = q.lower(zero); |
397 |
|
assertNull(e4); |
403 |
– |
|
398 |
|
} |
399 |
|
|
400 |
|
/** |
413 |
|
|
414 |
|
Object e4 = q.higher(six); |
415 |
|
assertNull(e4); |
422 |
– |
|
416 |
|
} |
417 |
|
|
418 |
|
/** |
431 |
|
|
432 |
|
Object e4 = q.floor(zero); |
433 |
|
assertNull(e4); |
441 |
– |
|
434 |
|
} |
435 |
|
|
436 |
|
/** |
449 |
|
|
450 |
|
Object e4 = q.ceiling(six); |
451 |
|
assertNull(e4); |
460 |
– |
|
452 |
|
} |
453 |
|
|
454 |
|
/** |
455 |
< |
* toArray contains all elements |
455 |
> |
* toArray contains all elements in sorted order |
456 |
|
*/ |
457 |
|
public void testToArray() { |
458 |
|
TreeSet q = populatedSet(SIZE); |
459 |
< |
Object[] o = q.toArray(); |
460 |
< |
Arrays.sort(o); |
461 |
< |
for(int i = 0; i < o.length; i++) |
471 |
< |
assertEquals(o[i], q.pollFirst()); |
459 |
> |
Object[] o = q.toArray(); |
460 |
> |
for (int i = 0; i < o.length; i++) |
461 |
> |
assertSame(o[i], q.pollFirst()); |
462 |
|
} |
463 |
|
|
464 |
|
/** |
465 |
< |
* toArray(a) contains all elements |
465 |
> |
* toArray(a) contains all elements in sorted order |
466 |
|
*/ |
467 |
|
public void testToArray2() { |
468 |
< |
TreeSet q = populatedSet(SIZE); |
469 |
< |
Integer[] ints = new Integer[SIZE]; |
470 |
< |
ints = (Integer[])q.toArray(ints); |
471 |
< |
Arrays.sort(ints); |
472 |
< |
for(int i = 0; i < ints.length; i++) |
473 |
< |
assertEquals(ints[i], q.pollFirst()); |
468 |
> |
TreeSet<Integer> q = populatedSet(SIZE); |
469 |
> |
Integer[] ints = new Integer[SIZE]; |
470 |
> |
Integer[] array = q.toArray(ints); |
471 |
> |
assertSame(ints, array); |
472 |
> |
for (int i = 0; i < ints.length; i++) |
473 |
> |
assertSame(ints[i], q.pollFirst()); |
474 |
|
} |
475 |
< |
|
475 |
> |
|
476 |
|
/** |
477 |
|
* iterator iterates through all elements |
478 |
|
*/ |
479 |
|
public void testIterator() { |
480 |
|
TreeSet q = populatedSet(SIZE); |
481 |
|
int i = 0; |
482 |
< |
Iterator it = q.iterator(); |
483 |
< |
while(it.hasNext()) { |
482 |
> |
Iterator it = q.iterator(); |
483 |
> |
while (it.hasNext()) { |
484 |
|
assertTrue(q.contains(it.next())); |
485 |
|
++i; |
486 |
|
} |
493 |
|
public void testEmptyIterator() { |
494 |
|
TreeSet q = new TreeSet(); |
495 |
|
int i = 0; |
496 |
< |
Iterator it = q.iterator(); |
497 |
< |
while(it.hasNext()) { |
496 |
> |
Iterator it = q.iterator(); |
497 |
> |
while (it.hasNext()) { |
498 |
|
assertTrue(q.contains(it.next())); |
499 |
|
++i; |
500 |
|
} |
501 |
< |
assertEquals(i, 0); |
501 |
> |
assertEquals(0, i); |
502 |
|
} |
503 |
|
|
504 |
|
/** |
505 |
|
* iterator.remove removes current element |
506 |
|
*/ |
507 |
< |
public void testIteratorRemove () { |
507 |
> |
public void testIteratorRemove() { |
508 |
|
final TreeSet q = new TreeSet(); |
509 |
|
q.add(new Integer(2)); |
510 |
|
q.add(new Integer(1)); |
520 |
|
assertFalse(it.hasNext()); |
521 |
|
} |
522 |
|
|
533 |
– |
|
523 |
|
/** |
524 |
|
* toString contains toStrings of elements |
525 |
|
*/ |
527 |
|
TreeSet q = populatedSet(SIZE); |
528 |
|
String s = q.toString(); |
529 |
|
for (int i = 0; i < SIZE; ++i) { |
530 |
< |
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
530 |
> |
assertTrue(s.contains(String.valueOf(i))); |
531 |
|
} |
532 |
< |
} |
532 |
> |
} |
533 |
|
|
534 |
|
/** |
535 |
< |
* A deserialized serialized set has same elements |
535 |
> |
* A deserialized serialized set has same elements |
536 |
|
*/ |
537 |
< |
public void testSerialization() { |
538 |
< |
TreeSet q = populatedSet(SIZE); |
539 |
< |
try { |
540 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
541 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
542 |
< |
out.writeObject(q); |
543 |
< |
out.close(); |
544 |
< |
|
545 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
546 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
547 |
< |
TreeSet r = (TreeSet)in.readObject(); |
559 |
< |
assertEquals(q.size(), r.size()); |
560 |
< |
while (!q.isEmpty()) |
561 |
< |
assertEquals(q.pollFirst(), r.pollFirst()); |
562 |
< |
} catch(Exception e){ |
563 |
< |
e.printStackTrace(); |
564 |
< |
unexpectedException(); |
537 |
> |
public void testSerialization() throws Exception { |
538 |
> |
NavigableSet x = populatedSet(SIZE); |
539 |
> |
NavigableSet y = serialClone(x); |
540 |
> |
|
541 |
> |
assertNotSame(x, y); |
542 |
> |
assertEquals(x.size(), y.size()); |
543 |
> |
assertEquals(x, y); |
544 |
> |
assertEquals(y, x); |
545 |
> |
while (!x.isEmpty()) { |
546 |
> |
assertFalse(y.isEmpty()); |
547 |
> |
assertEquals(x.pollFirst(), y.pollFirst()); |
548 |
|
} |
549 |
+ |
assertTrue(y.isEmpty()); |
550 |
|
} |
551 |
|
|
552 |
|
/** |
674 |
|
/** |
675 |
|
* Subsets of subsets subdivide correctly |
676 |
|
*/ |
677 |
< |
public void testRecursiveSubSets() { |
678 |
< |
int setSize = 1000; |
679 |
< |
Class cl = TreeSet.class; |
677 |
> |
public void testRecursiveSubSets() throws Exception { |
678 |
> |
int setSize = expensiveTests ? 1000 : 100; |
679 |
> |
Class cl = TreeSet.class; |
680 |
|
|
681 |
|
NavigableSet<Integer> set = newSet(cl); |
682 |
|
bs = new BitSet(setSize); |
689 |
|
check(set, 0, setSize - 1, true); |
690 |
|
check(set.descendingSet(), 0, setSize - 1, false); |
691 |
|
|
692 |
< |
bashSubSet(set.navigableSubSet(0, true, setSize, false), |
692 |
> |
bashSubSet(set.subSet(0, true, setSize, false), |
693 |
|
0, setSize - 1, true); |
694 |
|
} |
695 |
|
|
696 |
< |
static NavigableSet<Integer> newSet(Class cl) { |
697 |
< |
NavigableSet<Integer> result = null; |
698 |
< |
try { |
699 |
< |
result = (NavigableSet<Integer>) cl.newInstance(); |
700 |
< |
} catch(Exception e) { |
701 |
< |
fail(); |
702 |
< |
} |
703 |
< |
assertEquals(result.size(), 0); |
696 |
> |
/** |
697 |
> |
* addAll is idempotent |
698 |
> |
*/ |
699 |
> |
public void testAddAll_idempotent() throws Exception { |
700 |
> |
Set x = populatedSet(SIZE); |
701 |
> |
Set y = new TreeSet(x); |
702 |
> |
y.addAll(x); |
703 |
> |
assertEquals(x, y); |
704 |
> |
assertEquals(y, x); |
705 |
> |
} |
706 |
> |
|
707 |
> |
static NavigableSet<Integer> newSet(Class cl) throws Exception { |
708 |
> |
NavigableSet<Integer> result = (NavigableSet<Integer>) cl.newInstance(); |
709 |
> |
assertEquals(0, result.size()); |
710 |
|
assertFalse(result.iterator().hasNext()); |
711 |
|
return result; |
712 |
|
} |
728 |
|
} |
729 |
|
|
730 |
|
// Remove a bunch of entries with iterator |
731 |
< |
for(Iterator<Integer> it = set.iterator(); it.hasNext(); ) { |
731 |
> |
for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) { |
732 |
|
if (rnd.nextBoolean()) { |
733 |
|
bs.clear(it.next()); |
734 |
|
it.remove(); |
753 |
|
} |
754 |
|
|
755 |
|
// Remove a bunch of entries with iterator |
756 |
< |
for(Iterator<Integer> it = set.iterator(); it.hasNext(); ) { |
756 |
> |
for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) { |
757 |
|
if (rnd.nextBoolean()) { |
758 |
|
bs.clear(it.next()); |
759 |
|
it.remove(); |
768 |
|
} else { |
769 |
|
try { |
770 |
|
set.add(element); |
771 |
< |
fail(); |
772 |
< |
} catch(IllegalArgumentException e) { |
783 |
< |
// expected |
784 |
< |
} |
771 |
> |
shouldThrow(); |
772 |
> |
} catch (IllegalArgumentException success) {} |
773 |
|
} |
774 |
|
} |
775 |
|
} |
800 |
|
|
801 |
|
// headSet - pick direction and endpoint inclusion randomly |
802 |
|
boolean incl = rnd.nextBoolean(); |
803 |
< |
NavigableSet<Integer> hm = set.navigableHeadSet(midPoint, incl); |
803 |
> |
NavigableSet<Integer> hm = set.headSet(midPoint, incl); |
804 |
|
if (ascending) { |
805 |
|
if (rnd.nextBoolean()) |
806 |
|
bashSubSet(hm, min, midPoint - (incl ? 0 : 1), true); |
817 |
|
|
818 |
|
// tailSet - pick direction and endpoint inclusion randomly |
819 |
|
incl = rnd.nextBoolean(); |
820 |
< |
NavigableSet<Integer> tm = set.navigableTailSet(midPoint,incl); |
820 |
> |
NavigableSet<Integer> tm = set.tailSet(midPoint,incl); |
821 |
|
if (ascending) { |
822 |
|
if (rnd.nextBoolean()) |
823 |
|
bashSubSet(tm, midPoint + (incl ? 0 : 1), max, true); |
842 |
|
boolean lowIncl = rnd.nextBoolean(); |
843 |
|
boolean highIncl = rnd.nextBoolean(); |
844 |
|
if (ascending) { |
845 |
< |
NavigableSet<Integer> sm = set.navigableSubSet( |
845 |
> |
NavigableSet<Integer> sm = set.subSet( |
846 |
|
endpoints[0], lowIncl, endpoints[1], highIncl); |
847 |
|
if (rnd.nextBoolean()) |
848 |
|
bashSubSet(sm, endpoints[0] + (lowIncl ? 0 : 1), |
851 |
|
bashSubSet(sm.descendingSet(), endpoints[0] + (lowIncl ? 0 : 1), |
852 |
|
endpoints[1] - (highIncl ? 0 : 1), false); |
853 |
|
} else { |
854 |
< |
NavigableSet<Integer> sm = set.navigableSubSet( |
854 |
> |
NavigableSet<Integer> sm = set.subSet( |
855 |
|
endpoints[1], highIncl, endpoints[0], lowIncl); |
856 |
|
if (rnd.nextBoolean()) |
857 |
|
bashSubSet(sm, endpoints[0] + (lowIncl ? 0 : 1), |
867 |
|
*/ |
868 |
|
void check(NavigableSet<Integer> set, |
869 |
|
final int min, final int max, final boolean ascending) { |
870 |
< |
class ReferenceSet { |
870 |
> |
class ReferenceSet { |
871 |
|
int lower(int element) { |
872 |
|
return ascending ? |
873 |
|
lowerAscending(element) : higherAscending(element); |
902 |
|
// BitSet should support this! Test would run much faster |
903 |
|
while (element >= min) { |
904 |
|
if (bs.get(element)) |
905 |
< |
return(element); |
905 |
> |
return element; |
906 |
|
element--; |
907 |
|
} |
908 |
|
return -1; |
937 |
|
if (bsContainsI) |
938 |
|
size++; |
939 |
|
} |
940 |
< |
assertEquals(set.size(), size); |
940 |
> |
assertEquals(size, set.size()); |
941 |
|
|
942 |
|
// Test contents using contains elementSet iterator |
943 |
|
int size2 = 0; |
968 |
|
assertEq(rs.last(), -1); |
969 |
|
try { |
970 |
|
set.first(); |
971 |
< |
fail(); |
972 |
< |
} catch(NoSuchElementException e) { |
985 |
< |
// expected |
986 |
< |
} |
971 |
> |
shouldThrow(); |
972 |
> |
} catch (NoSuchElementException success) {} |
973 |
|
try { |
974 |
|
set.last(); |
975 |
< |
fail(); |
976 |
< |
} catch(NoSuchElementException e) { |
991 |
< |
// expected |
992 |
< |
} |
975 |
> |
shouldThrow(); |
976 |
> |
} catch (NoSuchElementException success) {} |
977 |
|
} |
978 |
|
} |
979 |
|
|