21 |
|
|
22 |
|
public class TreeSetTest extends JSR166TestCase { |
23 |
|
public static void main(String[] args) { |
24 |
< |
junit.textui.TestRunner.run(suite()); |
24 |
> |
main(suite(), args); |
25 |
|
} |
26 |
|
public static Test suite() { |
27 |
|
return new TestSuite(TreeSetTest.class); |
81 |
|
*/ |
82 |
|
public void testConstructor3() { |
83 |
|
try { |
84 |
< |
TreeSet q = new TreeSet((Collection)null); |
84 |
> |
new TreeSet((Collection)null); |
85 |
|
shouldThrow(); |
86 |
|
} catch (NullPointerException success) {} |
87 |
|
} |
92 |
|
public void testConstructor4() { |
93 |
|
try { |
94 |
|
Integer[] ints = new Integer[SIZE]; |
95 |
< |
TreeSet q = new TreeSet(Arrays.asList(ints)); |
95 |
> |
new TreeSet(Arrays.asList(ints)); |
96 |
|
shouldThrow(); |
97 |
|
} catch (NullPointerException success) {} |
98 |
|
} |
105 |
|
Integer[] ints = new Integer[SIZE]; |
106 |
|
for (int i = 0; i < SIZE-1; ++i) |
107 |
|
ints[i] = new Integer(i); |
108 |
< |
TreeSet q = new TreeSet(Arrays.asList(ints)); |
108 |
> |
new TreeSet(Arrays.asList(ints)); |
109 |
|
shouldThrow(); |
110 |
|
} catch (NullPointerException success) {} |
111 |
|
} |
170 |
|
* add(null) throws NPE if nonempty |
171 |
|
*/ |
172 |
|
public void testAddNull() { |
173 |
+ |
TreeSet q = populatedSet(SIZE); |
174 |
|
try { |
174 |
– |
TreeSet q = populatedSet(SIZE); |
175 |
|
q.add(null); |
176 |
|
shouldThrow(); |
177 |
|
} catch (NullPointerException success) {} |
199 |
|
* Add of non-Comparable throws CCE |
200 |
|
*/ |
201 |
|
public void testAddNonComparable() { |
202 |
+ |
TreeSet q = new TreeSet(); |
203 |
|
try { |
203 |
– |
TreeSet q = new TreeSet(); |
204 |
– |
q.add(new Object()); |
204 |
|
q.add(new Object()); |
205 |
|
q.add(new Object()); |
206 |
|
shouldThrow(); |
211 |
|
* addAll(null) throws NPE |
212 |
|
*/ |
213 |
|
public void testAddAll1() { |
214 |
+ |
TreeSet q = new TreeSet(); |
215 |
|
try { |
216 |
– |
TreeSet q = new TreeSet(); |
216 |
|
q.addAll(null); |
217 |
|
shouldThrow(); |
218 |
|
} catch (NullPointerException success) {} |
222 |
|
* addAll of a collection with null elements throws NPE |
223 |
|
*/ |
224 |
|
public void testAddAll2() { |
225 |
+ |
TreeSet q = new TreeSet(); |
226 |
+ |
Integer[] ints = new Integer[SIZE]; |
227 |
|
try { |
227 |
– |
TreeSet q = new TreeSet(); |
228 |
– |
Integer[] ints = new Integer[SIZE]; |
228 |
|
q.addAll(Arrays.asList(ints)); |
229 |
|
shouldThrow(); |
230 |
|
} catch (NullPointerException success) {} |
235 |
|
* possibly adding some elements |
236 |
|
*/ |
237 |
|
public void testAddAll3() { |
238 |
+ |
TreeSet q = new TreeSet(); |
239 |
+ |
Integer[] ints = new Integer[SIZE]; |
240 |
+ |
for (int i = 0; i < SIZE-1; ++i) |
241 |
+ |
ints[i] = new Integer(i); |
242 |
|
try { |
240 |
– |
TreeSet q = new TreeSet(); |
241 |
– |
Integer[] ints = new Integer[SIZE]; |
242 |
– |
for (int i = 0; i < SIZE-1; ++i) |
243 |
– |
ints[i] = new Integer(i); |
243 |
|
q.addAll(Arrays.asList(ints)); |
244 |
|
shouldThrow(); |
245 |
|
} catch (NullPointerException success) {} |
477 |
|
*/ |
478 |
|
public void testIterator() { |
479 |
|
TreeSet q = populatedSet(SIZE); |
481 |
– |
int i = 0; |
480 |
|
Iterator it = q.iterator(); |
481 |
< |
while (it.hasNext()) { |
481 |
> |
int i; |
482 |
> |
for (i = 0; it.hasNext(); i++) |
483 |
|
assertTrue(q.contains(it.next())); |
485 |
– |
++i; |
486 |
– |
} |
484 |
|
assertEquals(i, SIZE); |
485 |
+ |
assertIteratorExhausted(it); |
486 |
|
} |
487 |
|
|
488 |
|
/** |
489 |
|
* iterator of empty set has no elements |
490 |
|
*/ |
491 |
|
public void testEmptyIterator() { |
492 |
< |
TreeSet q = new TreeSet(); |
495 |
< |
int i = 0; |
496 |
< |
Iterator it = q.iterator(); |
497 |
< |
while (it.hasNext()) { |
498 |
< |
assertTrue(q.contains(it.next())); |
499 |
< |
++i; |
500 |
< |
} |
501 |
< |
assertEquals(0, i); |
492 |
> |
assertIteratorExhausted(new TreeSet().iterator()); |
493 |
|
} |
494 |
|
|
495 |
|
/** |
729 |
|
// Add entries till we're back to original size |
730 |
|
while (set.size() < size) { |
731 |
|
int element = min + rnd.nextInt(rangeSize); |
732 |
< |
assertTrue(element >= min && element<= max); |
732 |
> |
assertTrue(element >= min && element <= max); |
733 |
|
put(set, element); |
734 |
|
} |
735 |
|
} |
754 |
|
// Add entries till we're back to original size |
755 |
|
while (set.size() < size) { |
756 |
|
int element = min - 5 + rnd.nextInt(rangeSize + 10); |
757 |
< |
if (element >= min && element<= max) { |
757 |
> |
if (element >= min && element <= max) { |
758 |
|
put(set, element); |
759 |
|
} else { |
760 |
|
try { |