--- jsr166/src/test/tck/LinkedListTest.java 2003/12/27 19:26:43 1.7 +++ jsr166/src/test/tck/LinkedListTest.java 2004/12/28 16:15:59 1.8 @@ -448,4 +448,147 @@ public class LinkedListTest extends JSR1 assertEquals(four,q.peek()); } + /** + * peekFirst returns element inserted with push + */ + public void testPush() { + LinkedList q = populatedQueue(3); + q.pollLast(); + q.push(four); + assertEquals(four,q.peekFirst()); + } + + /** + * pop removes next element, or throws NSEE if empty + */ + public void testPop() { + LinkedList q = populatedQueue(SIZE); + for (int i = 0; i < SIZE; ++i) { + assertEquals(i, ((Integer)q.pop()).intValue()); + } + try { + q.pop(); + shouldThrow(); + } catch (NoSuchElementException success){ + } + } + + /** + * OfferFirst succeeds + */ + public void testOfferFirst() { + LinkedList q = new LinkedList(); + assertTrue(q.offerFirst(new Integer(0))); + assertTrue(q.offerFirst(new Integer(1))); + } + + /** + * OfferLast succeeds + */ + public void testOfferLast() { + LinkedList q = new LinkedList(); + assertTrue(q.offerLast(new Integer(0))); + assertTrue(q.offerLast(new Integer(1))); + } + + /** + * pollLast succeeds unless empty + */ + public void testPollLast() { + LinkedList q = populatedQueue(SIZE); + for (int i = SIZE-1; i >= 0; --i) { + assertEquals(i, ((Integer)q.pollLast()).intValue()); + } + assertNull(q.pollLast()); + } + + /** + * peekFirst returns next element, or null if empty + */ + public void testPeekFirst() { + LinkedList q = populatedQueue(SIZE); + for (int i = 0; i < SIZE; ++i) { + assertEquals(i, ((Integer)q.peekFirst()).intValue()); + q.pollFirst(); + assertTrue(q.peekFirst() == null || + i != ((Integer)q.peekFirst()).intValue()); + } + assertNull(q.peekFirst()); + } + + + /** + * peekLast returns next element, or null if empty + */ + public void testPeekLast() { + LinkedList q = populatedQueue(SIZE); + for (int i = SIZE-1; i >= 0; --i) { + assertEquals(i, ((Integer)q.peekLast()).intValue()); + q.pollLast(); + assertTrue(q.peekLast() == null || + i != ((Integer)q.peekLast()).intValue()); + } + assertNull(q.peekLast()); + } + + public void testFirstElement() { + LinkedList q = populatedQueue(SIZE); + for (int i = 0; i < SIZE; ++i) { + assertEquals(i, ((Integer)q.getFirst()).intValue()); + q.pollFirst(); + } + try { + q.getFirst(); + shouldThrow(); + } + catch (NoSuchElementException success) {} + } + + /** + * getLast returns next element, or throws NSEE if empty + */ + public void testLastElement() { + LinkedList q = populatedQueue(SIZE); + for (int i = SIZE-1; i >= 0; --i) { + assertEquals(i, ((Integer)q.getLast()).intValue()); + q.pollLast(); + } + try { + q.getLast(); + shouldThrow(); + } + catch (NoSuchElementException success) {} + assertNull(q.peekLast()); + } + + /** + * removeFirstOccurrence(x) removes x and returns true if present + */ + public void testRemoveFirstOccurrence() { + LinkedList q = populatedQueue(SIZE); + for (int i = 1; i < SIZE; i+=2) { + assertTrue(q.removeFirstOccurrence(new Integer(i))); + } + for (int i = 0; i < SIZE; i+=2) { + assertTrue(q.removeFirstOccurrence(new Integer(i))); + assertFalse(q.removeFirstOccurrence(new Integer(i+1))); + } + assertTrue(q.isEmpty()); + } + + /** + * removeLastOccurrence(x) removes x and returns true if present + */ + public void testRemoveLastOccurrence() { + LinkedList q = populatedQueue(SIZE); + for (int i = 1; i < SIZE; i+=2) { + assertTrue(q.removeLastOccurrence(new Integer(i))); + } + for (int i = 0; i < SIZE; i+=2) { + assertTrue(q.removeLastOccurrence(new Integer(i))); + assertFalse(q.removeLastOccurrence(new Integer(i+1))); + } + assertTrue(q.isEmpty()); + } + }