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 |
|
} |
91 |
|
*/ |
92 |
|
public void testConstructor4() { |
93 |
|
try { |
94 |
< |
Integer[] ints = new Integer[SIZE]; |
95 |
< |
TreeSet q = new TreeSet(Arrays.asList(ints)); |
94 |
> |
new TreeSet(Arrays.asList(new Integer[SIZE])); |
95 |
|
shouldThrow(); |
96 |
|
} catch (NullPointerException success) {} |
97 |
|
} |
100 |
|
* Initializing from Collection with some null elements throws NPE |
101 |
|
*/ |
102 |
|
public void testConstructor5() { |
103 |
+ |
Integer[] ints = new Integer[SIZE]; |
104 |
+ |
for (int i = 0; i < SIZE - 1; ++i) |
105 |
+ |
ints[i] = new Integer(i); |
106 |
|
try { |
107 |
< |
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)); |
107 |
> |
new TreeSet(Arrays.asList(ints)); |
108 |
|
shouldThrow(); |
109 |
|
} catch (NullPointerException success) {} |
110 |
|
} |
132 |
|
for (int i = 0; i < SIZE; ++i) |
133 |
|
ints[i] = new Integer(i); |
134 |
|
q.addAll(Arrays.asList(ints)); |
135 |
< |
for (int i = SIZE-1; i >= 0; --i) |
135 |
> |
for (int i = SIZE - 1; i >= 0; --i) |
136 |
|
assertEquals(ints[i], q.pollFirst()); |
137 |
|
} |
138 |
|
|
156 |
|
public void testSize() { |
157 |
|
TreeSet q = populatedSet(SIZE); |
158 |
|
for (int i = 0; i < SIZE; ++i) { |
159 |
< |
assertEquals(SIZE-i, q.size()); |
159 |
> |
assertEquals(SIZE - i, q.size()); |
160 |
|
q.pollFirst(); |
161 |
|
} |
162 |
|
for (int i = 0; i < SIZE; ++i) { |
169 |
|
* add(null) throws NPE if nonempty |
170 |
|
*/ |
171 |
|
public void testAddNull() { |
172 |
+ |
TreeSet q = populatedSet(SIZE); |
173 |
|
try { |
174 |
– |
TreeSet q = populatedSet(SIZE); |
174 |
|
q.add(null); |
175 |
|
shouldThrow(); |
176 |
|
} catch (NullPointerException success) {} |
198 |
|
* Add of non-Comparable throws CCE |
199 |
|
*/ |
200 |
|
public void testAddNonComparable() { |
201 |
+ |
TreeSet q = new TreeSet(); |
202 |
|
try { |
203 |
– |
TreeSet q = new TreeSet(); |
204 |
– |
q.add(new Object()); |
203 |
|
q.add(new Object()); |
204 |
|
q.add(new Object()); |
205 |
|
shouldThrow(); |
210 |
|
* addAll(null) throws NPE |
211 |
|
*/ |
212 |
|
public void testAddAll1() { |
213 |
+ |
TreeSet q = new TreeSet(); |
214 |
|
try { |
216 |
– |
TreeSet q = new TreeSet(); |
215 |
|
q.addAll(null); |
216 |
|
shouldThrow(); |
217 |
|
} catch (NullPointerException success) {} |
221 |
|
* addAll of a collection with null elements throws NPE |
222 |
|
*/ |
223 |
|
public void testAddAll2() { |
224 |
+ |
TreeSet q = new TreeSet(); |
225 |
+ |
Integer[] ints = new Integer[SIZE]; |
226 |
|
try { |
227 |
– |
TreeSet q = new TreeSet(); |
228 |
– |
Integer[] ints = new Integer[SIZE]; |
227 |
|
q.addAll(Arrays.asList(ints)); |
228 |
|
shouldThrow(); |
229 |
|
} catch (NullPointerException success) {} |
234 |
|
* possibly adding some elements |
235 |
|
*/ |
236 |
|
public void testAddAll3() { |
237 |
+ |
TreeSet q = new TreeSet(); |
238 |
+ |
Integer[] ints = new Integer[SIZE]; |
239 |
+ |
for (int i = 0; i < SIZE - 1; ++i) |
240 |
+ |
ints[i] = new Integer(i); |
241 |
|
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); |
242 |
|
q.addAll(Arrays.asList(ints)); |
243 |
|
shouldThrow(); |
244 |
|
} catch (NullPointerException success) {} |
251 |
|
Integer[] empty = new Integer[0]; |
252 |
|
Integer[] ints = new Integer[SIZE]; |
253 |
|
for (int i = 0; i < SIZE; ++i) |
254 |
< |
ints[i] = new Integer(SIZE-1-i); |
254 |
> |
ints[i] = new Integer(SIZE - 1 - i); |
255 |
|
TreeSet q = new TreeSet(); |
256 |
|
assertFalse(q.addAll(Arrays.asList(empty))); |
257 |
|
assertTrue(q.addAll(Arrays.asList(ints))); |
275 |
|
*/ |
276 |
|
public void testPollLast() { |
277 |
|
TreeSet q = populatedSet(SIZE); |
278 |
< |
for (int i = SIZE-1; i >= 0; --i) { |
278 |
> |
for (int i = SIZE - 1; i >= 0; --i) { |
279 |
|
assertEquals(i, q.pollLast()); |
280 |
|
} |
281 |
|
assertNull(q.pollFirst()); |
356 |
|
assertTrue(changed); |
357 |
|
|
358 |
|
assertTrue(q.containsAll(p)); |
359 |
< |
assertEquals(SIZE-i, q.size()); |
359 |
> |
assertEquals(SIZE - i, q.size()); |
360 |
|
p.pollFirst(); |
361 |
|
} |
362 |
|
} |
369 |
|
TreeSet q = populatedSet(SIZE); |
370 |
|
TreeSet p = populatedSet(i); |
371 |
|
assertTrue(q.removeAll(p)); |
372 |
< |
assertEquals(SIZE-i, q.size()); |
372 |
> |
assertEquals(SIZE - i, q.size()); |
373 |
|
for (int j = 0; j < i; ++j) { |
374 |
|
Integer x = (Integer)(p.pollFirst()); |
375 |
|
assertFalse(q.contains(x)); |
476 |
|
*/ |
477 |
|
public void testIterator() { |
478 |
|
TreeSet q = populatedSet(SIZE); |
481 |
– |
int i = 0; |
479 |
|
Iterator it = q.iterator(); |
480 |
< |
while (it.hasNext()) { |
480 |
> |
int i; |
481 |
> |
for (i = 0; it.hasNext(); i++) |
482 |
|
assertTrue(q.contains(it.next())); |
485 |
– |
++i; |
486 |
– |
} |
483 |
|
assertEquals(i, SIZE); |
484 |
+ |
assertIteratorExhausted(it); |
485 |
|
} |
486 |
|
|
487 |
|
/** |
488 |
|
* iterator of empty set has no elements |
489 |
|
*/ |
490 |
|
public void testEmptyIterator() { |
491 |
< |
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); |
491 |
> |
assertIteratorExhausted(new TreeSet().iterator()); |
492 |
|
} |
493 |
|
|
494 |
|
/** |
728 |
|
// Add entries till we're back to original size |
729 |
|
while (set.size() < size) { |
730 |
|
int element = min + rnd.nextInt(rangeSize); |
731 |
< |
assertTrue(element >= min && element<= max); |
731 |
> |
assertTrue(element >= min && element <= max); |
732 |
|
put(set, element); |
733 |
|
} |
734 |
|
} |
753 |
|
// Add entries till we're back to original size |
754 |
|
while (set.size() < size) { |
755 |
|
int element = min - 5 + rnd.nextInt(rangeSize + 10); |
756 |
< |
if (element >= min && element<= max) { |
756 |
> |
if (element >= min && element <= max) { |
757 |
|
put(set, element); |
758 |
|
} else { |
759 |
|
try { |
903 |
|
else if (element > max) |
904 |
|
return -1; |
905 |
|
int result = bs.nextSetBit(element); |
906 |
< |
return result > max ? -1 : result; |
906 |
> |
return (result > max) ? -1 : result; |
907 |
|
} |
908 |
|
int higherAscending(int element) { |
909 |
|
return ceilingAscending(element + 1); |
910 |
|
} |
911 |
|
private int firstAscending() { |
912 |
|
int result = ceilingAscending(min); |
913 |
< |
return result > max ? -1 : result; |
913 |
> |
return (result > max) ? -1 : result; |
914 |
|
} |
915 |
|
private int lastAscending() { |
916 |
|
int result = floorAscending(max); |
917 |
< |
return result < min ? -1 : result; |
917 |
> |
return (result < min) ? -1 : result; |
918 |
|
} |
919 |
|
} |
920 |
|
ReferenceSet rs = new ReferenceSet(); |
975 |
|
} |
976 |
|
|
977 |
|
static boolean eq(Integer i, int j) { |
978 |
< |
return i == null ? j == -1 : i == j; |
978 |
> |
return (i == null) ? j == -1 : i == j; |
979 |
|
} |
980 |
|
|
981 |
|
} |