33 |
|
} |
34 |
|
|
35 |
|
/** |
36 |
< |
* |
36 |
> |
* new queue is empty |
37 |
|
*/ |
38 |
|
public void testConstructor1() { |
39 |
|
assertEquals(0, new LinkedList().size()); |
40 |
|
} |
41 |
|
|
42 |
|
/** |
43 |
< |
* |
43 |
> |
* Initializing from null Collection throws NPE |
44 |
|
*/ |
45 |
|
public void testConstructor3() { |
46 |
|
try { |
51 |
|
} |
52 |
|
|
53 |
|
/** |
54 |
< |
* |
54 |
> |
* Queue contains all elements of collection used to initialize |
55 |
> |
|
56 |
|
*/ |
57 |
|
public void testConstructor6() { |
58 |
|
try { |
67 |
|
} |
68 |
|
|
69 |
|
/** |
70 |
< |
* |
70 |
> |
* isEmpty is true before add, false after |
71 |
|
*/ |
72 |
|
public void testEmpty() { |
73 |
|
LinkedList q = new LinkedList(); |
81 |
|
} |
82 |
|
|
83 |
|
/** |
84 |
< |
* |
84 |
> |
* size changes when elements added and removed |
85 |
|
*/ |
86 |
|
public void testSize() { |
87 |
|
LinkedList q = populatedQueue(SIZE); |
96 |
|
} |
97 |
|
|
98 |
|
/** |
99 |
< |
* |
99 |
> |
* offer(null) succeeds |
100 |
|
*/ |
101 |
|
public void testOfferNull() { |
102 |
|
try { |
108 |
|
} |
109 |
|
|
110 |
|
/** |
111 |
< |
* |
111 |
> |
* Offer succeeds |
112 |
|
*/ |
113 |
|
public void testOffer() { |
114 |
|
LinkedList q = new LinkedList(); |
117 |
|
} |
118 |
|
|
119 |
|
/** |
120 |
< |
* |
120 |
> |
* add succeeds |
121 |
|
*/ |
122 |
|
public void testAdd() { |
123 |
|
LinkedList q = new LinkedList(); |
128 |
|
} |
129 |
|
|
130 |
|
/** |
131 |
< |
* |
131 |
> |
* addAll(null) throws NPE |
132 |
|
*/ |
133 |
|
public void testAddAll1() { |
134 |
|
try { |
140 |
|
} |
141 |
|
|
142 |
|
/** |
143 |
< |
* |
143 |
> |
* Queue contains all elements, in traversal order, of successful addAll |
144 |
|
*/ |
145 |
|
public void testAddAll5() { |
146 |
|
try { |
158 |
|
} |
159 |
|
|
160 |
|
/** |
161 |
< |
* |
161 |
> |
* addAll with too large an index throws IOOBE |
162 |
> |
*/ |
163 |
> |
public void testAddAll2_IndexOutOfBoundsException() { |
164 |
> |
try { |
165 |
> |
LinkedList l = new LinkedList(); |
166 |
> |
l.add(new Object()); |
167 |
> |
LinkedList m = new LinkedList(); |
168 |
> |
m.add(new Object()); |
169 |
> |
l.addAll(4,m); |
170 |
> |
shouldThrow(); |
171 |
> |
} catch(IndexOutOfBoundsException success) {} |
172 |
> |
} |
173 |
> |
|
174 |
> |
/** |
175 |
> |
* addAll with negative index throws IOOBE |
176 |
> |
*/ |
177 |
> |
public void testAddAll4_BadIndex() { |
178 |
> |
try { |
179 |
> |
LinkedList l = new LinkedList(); |
180 |
> |
l.add(new Object()); |
181 |
> |
LinkedList m = new LinkedList(); |
182 |
> |
m.add(new Object()); |
183 |
> |
l.addAll(-1,m); |
184 |
> |
shouldThrow(); |
185 |
> |
} catch(IndexOutOfBoundsException success){} |
186 |
> |
} |
187 |
> |
|
188 |
> |
/** |
189 |
> |
* poll succeeds unless empty |
190 |
|
*/ |
191 |
|
public void testPoll() { |
192 |
|
LinkedList q = populatedQueue(SIZE); |
197 |
|
} |
198 |
|
|
199 |
|
/** |
200 |
< |
* |
200 |
> |
* peek returns next element, or null if empty |
201 |
|
*/ |
202 |
|
public void testPeek() { |
203 |
|
LinkedList q = populatedQueue(SIZE); |
211 |
|
} |
212 |
|
|
213 |
|
/** |
214 |
< |
* |
214 |
> |
* |
215 |
|
*/ |
216 |
|
public void testElement() { |
217 |
|
LinkedList q = populatedQueue(SIZE); |
227 |
|
} |
228 |
|
|
229 |
|
/** |
230 |
< |
* |
230 |
> |
* element returns next element, or throws NSEE if empty |
231 |
|
*/ |
232 |
|
public void testRemove() { |
233 |
|
LinkedList q = populatedQueue(SIZE); |
242 |
|
} |
243 |
|
|
244 |
|
/** |
245 |
< |
* |
245 |
> |
* remove(x) removes x and returns true if present |
246 |
|
*/ |
247 |
|
public void testRemoveElement() { |
248 |
|
LinkedList q = populatedQueue(SIZE); |
257 |
|
} |
258 |
|
|
259 |
|
/** |
260 |
< |
* |
260 |
> |
* contains(x) reports true when elements added but not yet removed |
261 |
|
*/ |
262 |
|
public void testContains() { |
263 |
|
LinkedList q = populatedQueue(SIZE); |
269 |
|
} |
270 |
|
|
271 |
|
/** |
272 |
< |
* |
272 |
> |
* clear removes all elements |
273 |
|
*/ |
274 |
|
public void testClear() { |
275 |
|
LinkedList q = populatedQueue(SIZE); |
283 |
|
} |
284 |
|
|
285 |
|
/** |
286 |
< |
* |
286 |
> |
* containsAll(c) is true when c contains a subset of elements |
287 |
|
*/ |
288 |
|
public void testContainsAll() { |
289 |
|
LinkedList q = populatedQueue(SIZE); |
297 |
|
} |
298 |
|
|
299 |
|
/** |
300 |
< |
* |
300 |
> |
* retainAll(c) retains only those elements of c and reports true if changed |
301 |
|
*/ |
302 |
|
public void testRetainAll() { |
303 |
|
LinkedList q = populatedQueue(SIZE); |
316 |
|
} |
317 |
|
|
318 |
|
/** |
319 |
< |
* |
319 |
> |
* removeAll(c) removes only those elements of c and reports true if changed |
320 |
|
*/ |
321 |
|
public void testRemoveAll() { |
322 |
|
for (int i = 1; i < SIZE; ++i) { |
332 |
|
} |
333 |
|
|
334 |
|
/** |
335 |
< |
* |
335 |
> |
* toArray contains all elements |
336 |
|
*/ |
337 |
|
public void testToArray() { |
338 |
|
LinkedList q = populatedQueue(SIZE); |
343 |
|
} |
344 |
|
|
345 |
|
/** |
346 |
< |
* |
346 |
> |
* toArray(a) contains all elements |
347 |
|
*/ |
348 |
|
public void testToArray2() { |
349 |
|
LinkedList q = populatedQueue(SIZE); |
353 |
|
for(int i = 0; i < ints.length; i++) |
354 |
|
assertEquals(ints[i], q.poll()); |
355 |
|
} |
356 |
+ |
|
357 |
+ |
/** |
358 |
+ |
* toArray(null) throws NPE |
359 |
+ |
*/ |
360 |
+ |
public void testToArray_BadArg() { |
361 |
+ |
try { |
362 |
+ |
LinkedList l = new LinkedList(); |
363 |
+ |
l.add(new Object()); |
364 |
+ |
Object o[] = l.toArray(null); |
365 |
+ |
shouldThrow(); |
366 |
+ |
} catch(NullPointerException success){} |
367 |
+ |
} |
368 |
+ |
|
369 |
+ |
/** |
370 |
+ |
* toArray with incompatable aray type throws CCE |
371 |
+ |
*/ |
372 |
+ |
public void testToArray1_BadArg() { |
373 |
+ |
try { |
374 |
+ |
LinkedList l = new LinkedList(); |
375 |
+ |
l.add(new Integer(5)); |
376 |
+ |
Object o[] = l.toArray(new String[10] ); |
377 |
+ |
shouldThrow(); |
378 |
+ |
} catch(ArrayStoreException success){} |
379 |
+ |
} |
380 |
|
|
381 |
|
/** |
382 |
< |
* |
382 |
> |
* iterator iterates through all elements |
383 |
|
*/ |
384 |
|
public void testIterator() { |
385 |
|
LinkedList q = populatedQueue(SIZE); |
393 |
|
} |
394 |
|
|
395 |
|
/** |
396 |
< |
* |
396 |
> |
* iterator ordering is FIFO |
397 |
|
*/ |
398 |
|
public void testIteratorOrdering() { |
346 |
– |
|
399 |
|
final LinkedList q = new LinkedList(); |
348 |
– |
|
400 |
|
q.add(new Integer(1)); |
401 |
|
q.add(new Integer(2)); |
402 |
|
q.add(new Integer(3)); |
352 |
– |
|
403 |
|
int k = 0; |
404 |
|
for (Iterator it = q.iterator(); it.hasNext();) { |
405 |
|
int i = ((Integer)(it.next())).intValue(); |
410 |
|
} |
411 |
|
|
412 |
|
/** |
413 |
< |
* |
413 |
> |
* iterator.remove removes current element |
414 |
|
*/ |
415 |
|
public void testIteratorRemove () { |
416 |
|
final LinkedList q = new LinkedList(); |
367 |
– |
|
417 |
|
q.add(new Integer(1)); |
418 |
|
q.add(new Integer(2)); |
419 |
|
q.add(new Integer(3)); |
371 |
– |
|
420 |
|
Iterator it = q.iterator(); |
421 |
|
it.next(); |
422 |
|
it.remove(); |
375 |
– |
|
423 |
|
it = q.iterator(); |
424 |
|
assertEquals(it.next(), new Integer(2)); |
425 |
|
assertEquals(it.next(), new Integer(3)); |
428 |
|
|
429 |
|
|
430 |
|
/** |
431 |
< |
* |
431 |
> |
* toString contains toStrings of elements |
432 |
|
*/ |
433 |
|
public void testToString() { |
434 |
|
LinkedList q = populatedQueue(SIZE); |
439 |
|
} |
440 |
|
|
441 |
|
/** |
442 |
< |
* |
442 |
> |
* peek returns element inserted with addFirst |
443 |
|
*/ |
444 |
|
public void testAddFirst() { |
445 |
|
LinkedList q = populatedQueue(3); |
446 |
< |
q.addFirst(new Integer(4)); |
447 |
< |
assertEquals(new Integer(4),q.get(0)); |
446 |
> |
q.addFirst(four); |
447 |
> |
assertEquals(four,q.peek()); |
448 |
|
} |
449 |
|
|
403 |
– |
/** |
404 |
– |
* |
405 |
– |
*/ |
406 |
– |
public void testAddLast() { |
407 |
– |
LinkedList q = populatedQueue(3); |
408 |
– |
q.addLast(new Integer(3)); |
409 |
– |
assertEquals(new Integer(3),q.get(3)); |
410 |
– |
} |
411 |
– |
|
412 |
– |
/** |
413 |
– |
* |
414 |
– |
*/ |
415 |
– |
public void testGetFirst() { |
416 |
– |
LinkedList q = populatedQueue(3); |
417 |
– |
assertEquals(new Integer(0),q.getFirst()); |
418 |
– |
} |
419 |
– |
|
420 |
– |
/** |
421 |
– |
* |
422 |
– |
*/ |
423 |
– |
public void testGetLast() { |
424 |
– |
LinkedList q = populatedQueue(3); |
425 |
– |
assertEquals(new Integer(2),q.getLast()); |
426 |
– |
} |
427 |
– |
|
428 |
– |
/** |
429 |
– |
* |
430 |
– |
*/ |
431 |
– |
public void testIndexOf() { |
432 |
– |
LinkedList q = populatedQueue(3); |
433 |
– |
assertEquals(0,q.indexOf(new Integer(0))); |
434 |
– |
assertEquals(1,q.indexOf(new Integer(1))); |
435 |
– |
assertEquals(2,q.indexOf(new Integer(2))); |
436 |
– |
assertEquals(-1, q.indexOf("not there")); |
437 |
– |
} |
438 |
– |
|
439 |
– |
/** |
440 |
– |
* |
441 |
– |
*/ |
442 |
– |
public void testLastIndexOf() { |
443 |
– |
LinkedList q = populatedQueue(3); |
444 |
– |
q.add(new Integer(2)); |
445 |
– |
assertEquals(3,q.lastIndexOf(new Integer(2))); |
446 |
– |
assertEquals(-1, q.lastIndexOf("not there")); |
447 |
– |
} |
448 |
– |
|
449 |
– |
/** |
450 |
– |
* |
451 |
– |
*/ |
452 |
– |
public void testSet() { |
453 |
– |
LinkedList q = populatedQueue(3); |
454 |
– |
q.set(0,(new Integer(1))); |
455 |
– |
assertFalse(q.contains(new Integer(0))); |
456 |
– |
assertEquals(new Integer(1), q.get(0)); |
457 |
– |
} |
458 |
– |
|
459 |
– |
|
460 |
– |
/** |
461 |
– |
* |
462 |
– |
*/ |
463 |
– |
public void testGetFirst_NoSuchElementException() { |
464 |
– |
try { |
465 |
– |
LinkedList l = new LinkedList(); |
466 |
– |
l.getFirst(); |
467 |
– |
shouldThrow(); |
468 |
– |
} |
469 |
– |
catch(NoSuchElementException success) {} |
470 |
– |
} |
471 |
– |
|
472 |
– |
/** |
473 |
– |
* |
474 |
– |
*/ |
475 |
– |
public void testRemoveFirst() { |
476 |
– |
try { |
477 |
– |
LinkedList l = new LinkedList(); |
478 |
– |
l.removeFirst(); |
479 |
– |
shouldThrow(); |
480 |
– |
} |
481 |
– |
catch(NoSuchElementException success) {} |
482 |
– |
} |
483 |
– |
|
484 |
– |
/** |
485 |
– |
* |
486 |
– |
*/ |
487 |
– |
public void testRemoveLast() { |
488 |
– |
try { |
489 |
– |
LinkedList l = new LinkedList(); |
490 |
– |
l.removeLast(); |
491 |
– |
shouldThrow(); |
492 |
– |
} |
493 |
– |
catch(NoSuchElementException success) {} |
494 |
– |
} |
495 |
– |
|
496 |
– |
/** |
497 |
– |
* |
498 |
– |
*/ |
499 |
– |
public void testGetLast_NoSuchElementException() { |
500 |
– |
try { |
501 |
– |
LinkedList l = new LinkedList(); |
502 |
– |
l.getLast(); |
503 |
– |
shouldThrow(); |
504 |
– |
} |
505 |
– |
catch(NoSuchElementException success) {} |
506 |
– |
} |
507 |
– |
|
508 |
– |
|
509 |
– |
/** |
510 |
– |
* |
511 |
– |
*/ |
512 |
– |
public void testAddAll_NullPointerException() { |
513 |
– |
try { |
514 |
– |
LinkedList l = new LinkedList(); |
515 |
– |
l.addAll((Collection)null); |
516 |
– |
shouldThrow(); |
517 |
– |
} |
518 |
– |
catch(NullPointerException success){} |
519 |
– |
} |
520 |
– |
|
521 |
– |
|
522 |
– |
/** |
523 |
– |
* |
524 |
– |
*/ |
525 |
– |
public void testAddAll1_OutOfBounds() { |
526 |
– |
try { |
527 |
– |
LinkedList l = new LinkedList(); |
528 |
– |
l.addAll(4,new LinkedList()); |
529 |
– |
shouldThrow(); |
530 |
– |
} |
531 |
– |
catch(IndexOutOfBoundsException success) {} |
532 |
– |
} |
533 |
– |
|
534 |
– |
|
535 |
– |
/** |
536 |
– |
* |
537 |
– |
*/ |
538 |
– |
public void testAddAll2_IndexOutOfBoundsException() { |
539 |
– |
try { |
540 |
– |
LinkedList l = new LinkedList(); |
541 |
– |
l.add(new Object()); |
542 |
– |
LinkedList m = new LinkedList(); |
543 |
– |
m.add(new Object()); |
544 |
– |
l.addAll(4,m); |
545 |
– |
shouldThrow(); |
546 |
– |
} catch(IndexOutOfBoundsException success) {} |
547 |
– |
} |
548 |
– |
|
549 |
– |
/** |
550 |
– |
* |
551 |
– |
*/ |
552 |
– |
public void testAddAll4_BadIndex() { |
553 |
– |
try { |
554 |
– |
LinkedList l = new LinkedList(); |
555 |
– |
l.add(new Object()); |
556 |
– |
LinkedList m = new LinkedList(); |
557 |
– |
m.add(new Object()); |
558 |
– |
l.addAll(-1,m); |
559 |
– |
shouldThrow(); |
560 |
– |
} catch(IndexOutOfBoundsException success){} |
561 |
– |
} |
562 |
– |
|
563 |
– |
/** |
564 |
– |
* |
565 |
– |
*/ |
566 |
– |
public void testget1() { |
567 |
– |
try { |
568 |
– |
LinkedList l = new LinkedList(); |
569 |
– |
l.add(new Object()); |
570 |
– |
l.get(-1); |
571 |
– |
shouldThrow(); |
572 |
– |
} catch(IndexOutOfBoundsException success) {} |
573 |
– |
} |
574 |
– |
|
575 |
– |
/** |
576 |
– |
* |
577 |
– |
*/ |
578 |
– |
public void testget2() { |
579 |
– |
try { |
580 |
– |
LinkedList l = new LinkedList(); |
581 |
– |
l.add(new Object()); |
582 |
– |
l.get(5); |
583 |
– |
shouldThrow(); |
584 |
– |
} catch(IndexOutOfBoundsException success){} |
585 |
– |
} |
586 |
– |
|
587 |
– |
/** |
588 |
– |
* |
589 |
– |
*/ |
590 |
– |
public void testset1() { |
591 |
– |
try { |
592 |
– |
LinkedList l = new LinkedList(); |
593 |
– |
l.add(new Object()); |
594 |
– |
l.set(-1,new Object()); |
595 |
– |
shouldThrow(); |
596 |
– |
} catch(IndexOutOfBoundsException success){} |
597 |
– |
} |
598 |
– |
|
599 |
– |
/** |
600 |
– |
* |
601 |
– |
*/ |
602 |
– |
public void testset2() { |
603 |
– |
try { |
604 |
– |
LinkedList l = new LinkedList(); |
605 |
– |
l.add(new Object()); |
606 |
– |
l.set(5,new Object()); |
607 |
– |
shouldThrow(); |
608 |
– |
} catch(IndexOutOfBoundsException success){} |
609 |
– |
} |
610 |
– |
|
611 |
– |
/** |
612 |
– |
* |
613 |
– |
*/ |
614 |
– |
public void testadd1() { |
615 |
– |
try { |
616 |
– |
LinkedList l = new LinkedList(); |
617 |
– |
l.add(new Object()); |
618 |
– |
l.add(-1,new Object()); |
619 |
– |
shouldThrow(); |
620 |
– |
} catch(IndexOutOfBoundsException success){} |
621 |
– |
} |
622 |
– |
|
623 |
– |
public void add2() { |
624 |
– |
try { |
625 |
– |
LinkedList l = new LinkedList(); |
626 |
– |
l.add(new Object()); |
627 |
– |
l.add(5,new Object()); |
628 |
– |
shouldThrow(); |
629 |
– |
} catch(IndexOutOfBoundsException success) {} |
630 |
– |
} |
631 |
– |
|
632 |
– |
/** |
633 |
– |
* |
634 |
– |
*/ |
635 |
– |
public void testremove() { |
636 |
– |
try { |
637 |
– |
LinkedList l = new LinkedList(); |
638 |
– |
l.add(new Object()); |
639 |
– |
l.remove(-1); |
640 |
– |
shouldThrow(); |
641 |
– |
} catch(IndexOutOfBoundsException success){} |
642 |
– |
} |
643 |
– |
|
644 |
– |
/** |
645 |
– |
* |
646 |
– |
*/ |
647 |
– |
public void testremove1() { |
648 |
– |
try { |
649 |
– |
LinkedList l = new LinkedList(); |
650 |
– |
l.add(new Object()); |
651 |
– |
l.remove(5); |
652 |
– |
shouldThrow(); |
653 |
– |
} catch(IndexOutOfBoundsException success){} |
654 |
– |
} |
655 |
– |
|
656 |
– |
|
657 |
– |
/** |
658 |
– |
* |
659 |
– |
*/ |
660 |
– |
public void testremove2() { |
661 |
– |
try { |
662 |
– |
LinkedList l = new LinkedList(); |
663 |
– |
l.remove(); |
664 |
– |
shouldThrow(); |
665 |
– |
} catch(NoSuchElementException e){} |
666 |
– |
} |
667 |
– |
|
668 |
– |
/** |
669 |
– |
* |
670 |
– |
*/ |
671 |
– |
public void testlistIt1() { |
672 |
– |
try { |
673 |
– |
LinkedList l = new LinkedList(); |
674 |
– |
l.add(new Object()); |
675 |
– |
l.listIterator(5); |
676 |
– |
shouldThrow(); |
677 |
– |
} catch(IndexOutOfBoundsException success){} |
678 |
– |
} |
679 |
– |
|
680 |
– |
/** |
681 |
– |
* |
682 |
– |
*/ |
683 |
– |
public void testlistIt2() { |
684 |
– |
try { |
685 |
– |
LinkedList l = new LinkedList(); |
686 |
– |
l.add(new Object()); |
687 |
– |
l.listIterator(-1); |
688 |
– |
shouldThrow(); |
689 |
– |
} catch(IndexOutOfBoundsException success){} |
690 |
– |
} |
691 |
– |
|
692 |
– |
/** |
693 |
– |
* |
694 |
– |
*/ |
695 |
– |
public void testlistIt3() { |
696 |
– |
try { |
697 |
– |
LinkedList l = new LinkedList(); |
698 |
– |
l.add(new Object()); |
699 |
– |
ListIterator a = l.listIterator(0); |
700 |
– |
l.removeFirst(); |
701 |
– |
a.next(); |
702 |
– |
shouldThrow(); |
703 |
– |
} catch(ConcurrentModificationException success){} |
704 |
– |
} |
705 |
– |
|
706 |
– |
/** |
707 |
– |
* |
708 |
– |
*/ |
709 |
– |
public void testToArray_BadArg() { |
710 |
– |
try { |
711 |
– |
LinkedList l = new LinkedList(); |
712 |
– |
l.add(new Object()); |
713 |
– |
Object o[] = l.toArray(null); |
714 |
– |
shouldThrow(); |
715 |
– |
} catch(NullPointerException success){} |
716 |
– |
} |
717 |
– |
|
718 |
– |
/** |
719 |
– |
* |
720 |
– |
*/ |
721 |
– |
public void testToArray1_BadArg() { |
722 |
– |
try { |
723 |
– |
LinkedList l = new LinkedList(); |
724 |
– |
l.add(new Integer(5)); |
725 |
– |
Object o[] = l.toArray(new String[10] ); |
726 |
– |
shouldThrow(); |
727 |
– |
} catch(ArrayStoreException success){} |
728 |
– |
} |
729 |
– |
|
450 |
|
} |