11 |
|
|
12 |
|
public class TreeSetTest 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(TreeSetTest.class); |
17 |
> |
return new TestSuite(TreeSetTest.class); |
18 |
|
} |
19 |
|
|
20 |
|
static class MyReverseComparator implements Comparator { |
39 |
|
private TreeSet populatedSet(int n) { |
40 |
|
TreeSet q = new TreeSet(); |
41 |
|
assertTrue(q.isEmpty()); |
42 |
< |
for (int i = n-1; i >= 0; i-=2) |
43 |
< |
assertTrue(q.add(new Integer(i))); |
44 |
< |
for (int i = (n & 1); i < n; i+=2) |
45 |
< |
assertTrue(q.add(new Integer(i))); |
42 |
> |
for (int i = n-1; i >= 0; i-=2) |
43 |
> |
assertTrue(q.add(new Integer(i))); |
44 |
> |
for (int i = (n & 1); i < n; i+=2) |
45 |
> |
assertTrue(q.add(new Integer(i))); |
46 |
|
assertFalse(q.isEmpty()); |
47 |
< |
assertEquals(n, q.size()); |
47 |
> |
assertEquals(n, q.size()); |
48 |
|
return q; |
49 |
|
} |
50 |
|
|
59 |
|
q.add(three); |
60 |
|
q.add(four); |
61 |
|
q.add(five); |
62 |
< |
assertEquals(5, q.size()); |
62 |
> |
assertEquals(5, q.size()); |
63 |
|
return q; |
64 |
|
} |
65 |
|
|
173 |
|
* add(null) throws NPE if nonempty |
174 |
|
*/ |
175 |
|
public void testAddNull() { |
176 |
< |
try { |
176 |
> |
try { |
177 |
|
TreeSet q = populatedSet(SIZE); |
178 |
|
q.add(null); |
179 |
|
shouldThrow(); |
277 |
|
for (int i = 0; i < SIZE; ++i) { |
278 |
|
assertEquals(i, ((Integer)q.pollFirst()).intValue()); |
279 |
|
} |
280 |
< |
assertNull(q.pollFirst()); |
280 |
> |
assertNull(q.pollFirst()); |
281 |
|
} |
282 |
|
|
283 |
|
/** |
288 |
|
for (int i = SIZE-1; i >= 0; --i) { |
289 |
|
assertEquals(i, ((Integer)q.pollLast()).intValue()); |
290 |
|
} |
291 |
< |
assertNull(q.pollFirst()); |
291 |
> |
assertNull(q.pollFirst()); |
292 |
|
} |
293 |
|
|
294 |
|
|
465 |
|
*/ |
466 |
|
public void testToArray() { |
467 |
|
TreeSet q = populatedSet(SIZE); |
468 |
< |
Object[] o = q.toArray(); |
468 |
> |
Object[] o = q.toArray(); |
469 |
|
Arrays.sort(o); |
470 |
< |
for (int i = 0; i < o.length; i++) |
471 |
< |
assertEquals(o[i], q.pollFirst()); |
470 |
> |
for (int i = 0; i < o.length; i++) |
471 |
> |
assertEquals(o[i], q.pollFirst()); |
472 |
|
} |
473 |
|
|
474 |
|
/** |
476 |
|
*/ |
477 |
|
public void testToArray2() { |
478 |
|
TreeSet q = populatedSet(SIZE); |
479 |
< |
Integer[] ints = new Integer[SIZE]; |
480 |
< |
ints = (Integer[])q.toArray(ints); |
479 |
> |
Integer[] ints = new Integer[SIZE]; |
480 |
> |
ints = (Integer[])q.toArray(ints); |
481 |
|
Arrays.sort(ints); |
482 |
|
for (int i = 0; i < ints.length; i++) |
483 |
|
assertEquals(ints[i], q.pollFirst()); |
489 |
|
public void testIterator() { |
490 |
|
TreeSet q = populatedSet(SIZE); |
491 |
|
int i = 0; |
492 |
< |
Iterator it = q.iterator(); |
492 |
> |
Iterator it = q.iterator(); |
493 |
|
while (it.hasNext()) { |
494 |
|
assertTrue(q.contains(it.next())); |
495 |
|
++i; |
503 |
|
public void testEmptyIterator() { |
504 |
|
TreeSet q = new TreeSet(); |
505 |
|
int i = 0; |
506 |
< |
Iterator it = q.iterator(); |
506 |
> |
Iterator it = q.iterator(); |
507 |
|
while (it.hasNext()) { |
508 |
|
assertTrue(q.contains(it.next())); |
509 |
|
++i; |
559 |
|
assertEquals(q.size(), r.size()); |
560 |
|
while (!q.isEmpty()) |
561 |
|
assertEquals(q.pollFirst(), r.pollFirst()); |
562 |
< |
} catch (Exception e){ |
562 |
> |
} catch (Exception e) { |
563 |
|
e.printStackTrace(); |
564 |
|
unexpectedException(); |
565 |
|
} |
691 |
|
* Subsets of subsets subdivide correctly |
692 |
|
*/ |
693 |
|
public void testRecursiveSubSets() { |
694 |
< |
int setSize = 1000; |
695 |
< |
Class cl = TreeSet.class; |
694 |
> |
int setSize = 1000; |
695 |
> |
Class cl = TreeSet.class; |
696 |
|
|
697 |
|
NavigableSet<Integer> set = newSet(cl); |
698 |
|
bs = new BitSet(setSize); |
711 |
|
|
712 |
|
static NavigableSet<Integer> newSet(Class cl) { |
713 |
|
NavigableSet<Integer> result = null; |
714 |
< |
try { |
714 |
> |
try { |
715 |
|
result = (NavigableSet<Integer>) cl.newInstance(); |
716 |
< |
} catch (Exception e) { |
716 |
> |
} catch (Exception e) { |
717 |
|
fail(); |
718 |
< |
} |
718 |
> |
} |
719 |
|
assertEquals(result.size(), 0); |
720 |
|
assertFalse(result.iterator().hasNext()); |
721 |
|
return result; |