4 |
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
– |
import junit.framework.*; |
7 |
|
import java.util.Arrays; |
8 |
|
import java.util.BitSet; |
9 |
|
import java.util.Collection; |
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()); |
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<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) |
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) |
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()); |
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(); |
288 |
|
*/ |
289 |
|
public void testRemoveElement() { |
290 |
|
TreeSet q = populatedSet(SIZE); |
291 |
< |
for (int i = 1; i < SIZE; i+=2) { |
291 |
> |
for (int i = 1; i < SIZE; i += 2) { |
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) { |
297 |
> |
for (int i = 0; i < SIZE; i += 2) { |
298 |
|
assertTrue(q.contains(i)); |
299 |
|
assertTrue(q.remove(i)); |
300 |
|
assertFalse(q.contains(i)); |
498 |
|
assertTrue(q.contains(it.next())); |
499 |
|
++i; |
500 |
|
} |
501 |
< |
assertEquals(i, 0); |
501 |
> |
assertEquals(0, i); |
502 |
|
} |
503 |
|
|
504 |
|
/** |
538 |
|
NavigableSet x = populatedSet(SIZE); |
539 |
|
NavigableSet y = serialClone(x); |
540 |
|
|
541 |
< |
assertTrue(x != y); |
541 |
> |
assertNotSame(x, y); |
542 |
|
assertEquals(x.size(), y.size()); |
543 |
|
assertEquals(x, y); |
544 |
|
assertEquals(y, x); |
693 |
|
0, setSize - 1, true); |
694 |
|
} |
695 |
|
|
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(result.size(), 0); |
709 |
> |
assertEquals(0, result.size()); |
710 |
|
assertFalse(result.iterator().hasNext()); |
711 |
|
return result; |
712 |
|
} |
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; |