
import junit.framework.*;

/**
 * Test case for our Deque.
 *
 */
public class DequeTest extends TestCase 
{

	public static void main (String[] args) 
	{
		junit.textui.TestRunner.run ( suite() );
	}
	
	public DequeTest( String str )
	{
		super( str );
	}	
	
	public static Test suite() 
	{
		return new TestSuite(DequeTest.class);
	}
	
	//*********************  Test methods ************************
	
	public void testConstructor1()
	{
		assertNotNull(new Deque());
	}
	
	public void testDynamic()
	{
		Deque dq = new Deque();
		for( int i = 0; i < 90; ++i )
			dq.pushFront( "hello" );
		dq.pushFront( "there" );
		for( int i = 0; i < 90; ++i )
			assertNotNull( dq.popBack() );
		assertEquals( "there", (String)(dq.popFront()) );
	}
	
	public void testDynamic2()
	{
		Deque dq = new Deque();
		for( int i = 0; i < 90; ++i )
			dq.pushBack( "hello" );
		dq.pushBack( "there" );
		for( int i = 0; i < 90; ++i )
			assertNotNull( dq.popFront() );
		assertEquals( "there", (String)(dq.popBack()) );
	}
	
	public void testFront()
	{
		Deque dq = new Deque();
		dq.pushFront( "hello" );
		dq.pushFront( "there" );
		assertEquals( "there", (String)(dq.popFront()) );
		assertEquals( "hello", (String)(dq.popFront()) );
	}
	
	public void testFront2()
	{
		Deque dq = new Deque();
		dq.pushFront( "hello" );
		dq.pushBack( "there" );
		assertEquals( "hello", (String)(dq.popFront()) );
		assertEquals( "there", (String)(dq.popFront()) );
	}
	
	public void testFront3()
	{
		Deque dq = new Deque();
		for( int i = 0; i < 200; ++i )
		{
			dq.pushBack( "hello" );
			dq.pushBack( "hello" );
			dq.pushBack( "hello" );
			dq.pushBack( "hello" );
			dq.pushBack( "hello" );
			assertEquals( "hello", (String)(dq.popFront()) );
			assertEquals( "hello", (String)(dq.popFront()) );
			assertEquals( "hello", (String)(dq.popFront()) );
			assertEquals( "hello", (String)(dq.popFront()) );
		}
	}
	public void testFront4()
	{
		Deque dq = new Deque();
		for( int i = 0; i < 200; ++i )
		{
			dq.pushFront( "hello" );
			dq.pushFront( "hello" );
			dq.pushFront( "hello" );
			dq.pushFront( "hello" );
			dq.pushFront( "hello" );
			assertEquals( "hello" , (String)(dq.popBack()));
			assertEquals( "hello" , (String)(dq.popBack()));
			assertEquals( "hello" , (String)(dq.popBack()));
			assertEquals( "hello" , (String)(dq.popBack()));
		}
	}
	
	public void testBack()
	{
		Deque dq = new Deque();
		dq.pushBack( "hello" );
		dq.pushBack( "there" );
		assertEquals( "there" , (String)(dq.popBack()));
		assertEquals( "hello" , (String)(dq.popBack()));
	}
	
	public void testBoth()
	{
		Deque dq = new Deque();
		dq.pushFront( "hello" );
		dq.pushFront( "there" );
		assertEquals( "there" , (String)(dq.popFront()));
		assertEquals( "hello", (String)(dq.popBack()) );
	}
	
	public void testGet()
	{
		Deque dq = new Deque();
		dq.pushFront( "hello" );
		dq.pushFront( "there" );
		assertEquals( "there", (String)(dq.front()) );
		assertEquals( "hello", (String)(dq.back()) );
	}
	
	public void testEmpty()
	{
		Deque dq = new Deque();
		dq.pushFront( "hello" );
		dq.pushFront( "there" );
		assertFalse( dq.isEmpty() );
		dq.popBack();
		dq.popBack();
		assertTrue( dq.isEmpty() );
	}
	
	public void testClear()
	{
		Deque dq = new Deque();
		dq.pushBack( "hello" );
		dq.clear();
		assertNull( dq.popBack() );
	}

}
