package edu.cmu.cs211.snake.tests; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertFalse; import java.util.LinkedList; import java.util.Queue; import java.util.Random; import org.junit.Test; import edu.cmu.cs211.snake.util.ArrayQueue; /** * This is an example of the beginning of a JUnit test * case for ArrayQueue. */ public class ArrayQueueTest { /** * This is an example of a randomized stress test. The goal here is to bring * out corner cases. It's also important to do more targeted testing. Try to * test odd things that might happen. For example, the circular behavior of * the array queue is a good place to find issues. */ @Test public void randomAddRemoveTest () { Random r = new Random (); Queue mine = new ArrayQueue (); Queue compare = new LinkedList (); int NTESTS = 10000; for (int i = 0; i < NTESTS; i ++) { if (compare.size() == 0 || r.nextBoolean()) { Object o = new Object (); mine.offer (o); compare.offer (o); } else { assertEquals ("object from peek()", compare.peek(), mine.peek()); assertEquals ("size after peek()", compare.size(), mine.size()); assertEquals ("object from poll()", compare.poll(), mine.poll()); } assertEquals ("size after operations", compare.size(), mine.size()); } } /** * More targeted test for the resize event in your array queue. Please look at * the testing document for more ideas... * */ @Test public void resizeTest () { } }