import static org.junit.Assert.*; import org.junit.*; import java.util.NoSuchElementException; import java.util.*; /* This is a sample junit test file for the AwesomeQueue class. It exists only to verify that AwesomeQueue passes a series of tests designed to spot bugs. Running a JUnit test: Run it in Eclipse by going to the 'Run' menu, selecting 'Run Configurations', and double clicking 'JUnit test'. If there are multiple junit files laying around, you may have to select which one you want. Running it will execute all the methods marked with the '@Test' annotation, then give you a report of whether they passed or not. For the most part, tests pass as long as they don't fail an assertion or throw an exception. */ public class QueueTester { private AwesomeQueue queue; @Before //this method will be run before each '@Test' due to the '@Before' annotation. //use it to initialize data structures, and other things you need to do before each test public void init() { queue=new AwesomeQueue(); } @Test //the '@Test' annotation marks it as, surprisingly enough, a test. //each test will be run independently public void testIsEmptyOnEmpty() { assertTrue(queue.isEmpty()); } @Test public void testIsEmptyOnNotEmpty() { queue.enqueue(5); assertTrue(!queue.isEmpty()); } @Test public void testOneEnqueue() { queue.enqueue(5); } @Test public void testOneDequeue() { queue.enqueue(5); assertTrue(5==queue.dequeue()); } @Test public void testOrdering() { queue.enqueue(1); queue.enqueue(2); queue.enqueue(3); assertEquals(1,queue.dequeue()); assertEquals(2,queue.dequeue()); assertEquals(3,queue.dequeue()); } @Test(expected=NoSuchElementException.class) public void testDequeueOnEmpty() { queue.dequeue(); } @Test //this checks to make sure that enqueueing then dequeueing doesn't break isEmpty() public void testEmptyAfterDequeue() { queue.enqueue(5); queue.dequeue(); assertTrue(queue.isEmpty()); } @Ignore //you can use the '@Ignore' annotation to effectively hide a test public void ignoreMe() { throw new RuntimeException("Error"); } //you can, of course, declare other methods besides tests; just exclude the '@Test'. //This one gets used by several tests that call it with different arguments. //this performs n random operations on an AwesomeQueue and java's LinkedList, and verifies that they end up the same. //this is useful for testing because 1) it can test for very large examples and 2) it tests enqueues and dequeues in all sorts of interleaved orderings, possibly picking out obscure bugs //Note: this uses random values, which means that running tests different times could have different results (if, say, there is a bug in your code but hitting it is rare) private void testNOperations(int n) { Random r=new Random(); LinkedList goodQueue=new LinkedList(); int num; for(int i=0;i