package edu.hawaii.ics.yucheng;
import java.util.NoSuchElementException;
import junit.framework.TestCase;
/**
* Tests the LinkedListQueue class.
*/
public class LinkedListQueueTest extends TestCase {
/**
* Tests the constructor.
*
* @throws Exception
*/
public void testConstructor() throws Exception {
new LinkedListQueue<String>();
}
/**
* Tests the isEmpty method.
*
* @throws Exception
*/
public void testIsEmpty() throws Exception {
final LinkedListQueue<String> q = new LinkedListQueue<String>();
assertTrue(q.isEmpty());
q.push("A");
assertFalse(q.isEmpty());
q.pop();
assertTrue(q.isEmpty());
}
/**
* Tests the pop method.
*
* @throws Exception
*/
public void testPop1() throws Exception {
final LinkedListQueue<String> q = new LinkedListQueue<String>();
try {
q.pop();
fail();
} catch (final NoSuchElementException e) {
// This is expected.
}
}
/**
* Tests the pop method.
*
* @throws Exception
*/
public void testPop2() throws Exception {
final LinkedListQueue<String> q = new LinkedListQueue<String>();
assertTrue(q.isEmpty());
q.push("A");
assertFalse(q.isEmpty());
assertEquals("A", q.pop());
assertTrue(q.isEmpty());
}
/**
* Tests the pop method.
*
* @throws Exception
*/
public void testPop3() throws Exception {
final LinkedListQueue<String> q = new LinkedListQueue<String>();
assertTrue(q.isEmpty());
q.push("A");
q.push("B");
q.push("C");
assertFalse(q.isEmpty());
assertEquals("A", q.pop());
assertEquals("B", q.pop());
assertEquals("C", q.pop());
assertTrue(q.isEmpty());
}
/**
* Tests the toString method.
*
* @throws Exception
*/
public void testToString() throws Exception {
final LinkedListQueue<String> q = new LinkedListQueue<String>();
q.push("A");
q.push("B");
assertEquals("{ A, B }", q.toString());
}
}