13 |
|
|
14 |
|
public class PriorityQueueTest extends JSR166TestCase { |
15 |
|
public static void main(String[] args) { |
16 |
< |
junit.textui.TestRunner.run (suite()); |
16 |
> |
junit.textui.TestRunner.run(suite()); |
17 |
|
} |
18 |
|
public static Test suite() { |
19 |
|
return new TestSuite(PriorityQueueTest.class); |
21 |
|
|
22 |
|
static class MyReverseComparator implements Comparator { |
23 |
|
public int compare(Object x, Object y) { |
24 |
< |
int i = ((Integer)x).intValue(); |
25 |
< |
int j = ((Integer)y).intValue(); |
26 |
< |
if (i < j) return 1; |
27 |
< |
if (i > j) return -1; |
28 |
< |
return 0; |
24 |
> |
return ((Comparable)y).compareTo(x); |
25 |
|
} |
26 |
|
} |
27 |
|
|
213 |
|
shouldThrow(); |
214 |
|
} catch (NullPointerException success) {} |
215 |
|
} |
216 |
+ |
|
217 |
|
/** |
218 |
|
* addAll of a collection with null elements throws NPE |
219 |
|
*/ |
225 |
|
shouldThrow(); |
226 |
|
} catch (NullPointerException success) {} |
227 |
|
} |
228 |
+ |
|
229 |
|
/** |
230 |
|
* addAll of a collection with any null elements throws NPE after |
231 |
|
* possibly adding some elements |
262 |
|
public void testPoll() { |
263 |
|
PriorityQueue q = populatedQueue(SIZE); |
264 |
|
for (int i = 0; i < SIZE; ++i) { |
265 |
< |
assertEquals(i, ((Integer)q.poll()).intValue()); |
265 |
> |
assertEquals(i, q.poll()); |
266 |
|
} |
267 |
|
assertNull(q.poll()); |
268 |
|
} |
273 |
|
public void testPeek() { |
274 |
|
PriorityQueue q = populatedQueue(SIZE); |
275 |
|
for (int i = 0; i < SIZE; ++i) { |
276 |
< |
assertEquals(i, ((Integer)q.peek()).intValue()); |
277 |
< |
q.poll(); |
276 |
> |
assertEquals(i, q.peek()); |
277 |
> |
assertEquals(i, q.poll()); |
278 |
|
assertTrue(q.peek() == null || |
279 |
< |
i != ((Integer)q.peek()).intValue()); |
279 |
> |
!q.peek().equals(i)); |
280 |
|
} |
281 |
|
assertNull(q.peek()); |
282 |
|
} |
287 |
|
public void testElement() { |
288 |
|
PriorityQueue q = populatedQueue(SIZE); |
289 |
|
for (int i = 0; i < SIZE; ++i) { |
290 |
< |
assertEquals(i, ((Integer)q.element()).intValue()); |
291 |
< |
q.poll(); |
290 |
> |
assertEquals(i, q.element()); |
291 |
> |
assertEquals(i, q.poll()); |
292 |
|
} |
293 |
|
try { |
294 |
|
q.element(); |
302 |
|
public void testRemove() { |
303 |
|
PriorityQueue q = populatedQueue(SIZE); |
304 |
|
for (int i = 0; i < SIZE; ++i) { |
305 |
< |
assertEquals(i, ((Integer)q.remove()).intValue()); |
305 |
> |
assertEquals(i, q.remove()); |
306 |
|
} |
307 |
|
try { |
308 |
|
q.remove(); |
408 |
|
Object[] o = q.toArray(); |
409 |
|
Arrays.sort(o); |
410 |
|
for (int i = 0; i < o.length; i++) |
411 |
< |
assertEquals(o[i], q.poll()); |
411 |
> |
assertSame(o[i], q.poll()); |
412 |
|
} |
413 |
|
|
414 |
|
/** |
417 |
|
public void testToArray2() { |
418 |
|
PriorityQueue q = populatedQueue(SIZE); |
419 |
|
Integer[] ints = new Integer[SIZE]; |
420 |
< |
ints = (Integer[])q.toArray(ints); |
420 |
> |
assertSame(ints, q.toArray(ints)); |
421 |
|
Arrays.sort(ints); |
422 |
|
for (int i = 0; i < ints.length; i++) |
423 |
< |
assertEquals(ints[i], q.poll()); |
423 |
> |
assertSame(ints[i], q.poll()); |
424 |
|
} |
425 |
|
|
426 |
|
/** |
440 |
|
/** |
441 |
|
* iterator.remove removes current element |
442 |
|
*/ |
443 |
< |
public void testIteratorRemove () { |
443 |
> |
public void testIteratorRemove() { |
444 |
|
final PriorityQueue q = new PriorityQueue(3); |
445 |
|
q.add(new Integer(2)); |
446 |
|
q.add(new Integer(1)); |