//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //JUnit Queue Tests //Description: Test suite for the Queue Class that uses Junit. //CS 284 //Programmed by Jonathan Voris //3/7/06 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import junit.framework.TestCase; import junit.framework.TestSuite; import junit.framework.Test; public class JUnitQueueTest extends TestCase { private Queue emptyQ, fullQ; String[] testVars = {"spam", "eggs", "ham", "bacon"}; protected void setUp() { emptyQ = new Queue(); fullQ = new Queue(); for (int x = 0; x < testVars.length; x++) { fullQ.insert(testVars[x]); } } public static Test suite() { return new TestSuite(JUnitQueueTest.class); } public static void main(String[] args) { junit.textui.TestRunner.run(suite()); } public void testInitial() { assertTrue(emptyQ.getSize() == 0); assertTrue(emptyQ.isEmpty()); } public void testInsertion() { for (int x = 0; x < testVars.length; x++) { assertTrue(emptyQ.insert(testVars[x]) == testVars[x]); assertTrue(emptyQ.peek() == testVars[0]); assertTrue(emptyQ.getSize() == x+1); assertFalse(emptyQ.isEmpty()); } } public void testRemovals() { for (int x = 0; x < testVars.length-1; x++) { assertTrue(fullQ.remove() == testVars[x]); assertTrue(fullQ.peek() == testVars[x+1]); assertTrue(fullQ.getSize() == (testVars.length - (x+1))); assertFalse(fullQ.isEmpty()); } } public void testPeekException() { try { emptyQ.peek(); } catch (EmptyQueueException eqe) { return; } fail("Should raise an EmptyQueueException"); } public void testRemoveException() { try { emptyQ.remove(); } catch (EmptyQueueException eqe) { return; } fail("Should raise an EmptyQueueException"); } }