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); |
29 |
|
* Create a queue of given size containing consecutive |
30 |
|
* Integers 0 ... n. |
31 |
|
*/ |
32 |
< |
private PriorityQueue populatedQueue(int n) { |
33 |
< |
PriorityQueue q = new PriorityQueue(n); |
32 |
> |
private PriorityQueue<Integer> populatedQueue(int n) { |
33 |
> |
PriorityQueue<Integer> q = new PriorityQueue<Integer>(n); |
34 |
|
assertTrue(q.isEmpty()); |
35 |
|
for (int i = n-1; i >= 0; i-=2) |
36 |
|
assertTrue(q.offer(new Integer(i))); |
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 |
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 |
|
/** |
415 |
|
* toArray(a) contains all elements |
416 |
|
*/ |
417 |
|
public void testToArray2() { |
418 |
< |
PriorityQueue q = populatedQueue(SIZE); |
418 |
> |
PriorityQueue<Integer> q = populatedQueue(SIZE); |
419 |
|
Integer[] ints = new Integer[SIZE]; |
420 |
< |
ints = (Integer[])q.toArray(ints); |
420 |
> |
Integer[] array = q.toArray(ints); |
421 |
> |
assertSame(ints, array); |
422 |
|
Arrays.sort(ints); |
423 |
|
for (int i = 0; i < ints.length; i++) |
424 |
< |
assertEquals(ints[i], q.poll()); |
424 |
> |
assertSame(ints[i], q.poll()); |
425 |
|
} |
426 |
|
|
427 |
|
/** |
441 |
|
/** |
442 |
|
* iterator.remove removes current element |
443 |
|
*/ |
444 |
< |
public void testIteratorRemove () { |
444 |
> |
public void testIteratorRemove() { |
445 |
|
final PriorityQueue q = new PriorityQueue(3); |
446 |
|
q.add(new Integer(2)); |
447 |
|
q.add(new Integer(1)); |