// TestQueue -- Test Case forQueue
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.framework.Test;
public class TestQueue
extends TestCase
{
// JUnit Framework -----------------------------------------------
public TestQueue (String name) { super (name); }
public static Test suite () {
TestSuite suite = new TestSuite (TestQueue.class);
return suite;
}
protected void setUp () {
q = new Queue();
}
protected void tearDown () {
q = null;
}
// Test Data -----------------------------------------------------
Queue q;
// Tests ---------------------------------------------------------
public void testCreation () {
assert ("created", q != null);
}
public void testOne () throws Exception {
q.add(12);
assertEquals(12, q.get());
}
public void testSeveral () throws Exception {
q.add(1);
q.add(2);
q.add(3);
q.add(4);
assertEquals(1, q.get());
assertEquals(2, q.get());
assertEquals(3, q.get());
assertEquals(4, q.get());
}
public void testSize () throws Exception {
q = new Queue(3);
q.add(1);
q.add(2);
q.add(3);
assert (q.isFull());
assertEquals(1, q.get());
assertEquals(2, q.get());
assertEquals(3, q.get());
assert (q.isEmpty());
}
public void testOverflow () throws Exception {
boolean caught = false;
q = new Queue(3);
q.add(1);
q.add(2);
q.add(3);
try {
q.add(4);
}
catch (QueueException e) {
caught = true;
}
assert (caught);
}
public void testUnderflow () throws Exception {
boolean caught = false;
q = new Queue(3);
try {
q.get();
}
catch (QueueException e) {
caught = true;
}
assert (caught);
}
public void testRollover () throws Exception {
q = new Queue(3);
for (int i=1; i<10; ++i) {
q.add(1);
q.add(2);
q.add(3);
assertEquals(1, q.get());
assertEquals(2, q.get());
assertEquals(3, q.get());
}
}
}
|