    1   package baseCode.dataStructure;
    2
    3   import junit.framework.TestCase;
    4   import baseCode.dataStructure.Queue;
    5
    6   /***
    7    * <p>
    8    * </p>
    9    * <p>
    10   * </p>
    11   * <p>
    12   * Copyright (c) 2004
    13   * </p>
    14   * <p>
    15   * Institution: Columbia University
    16   * </p>
    17   *
    18   * @author Paul Pavlidis
    19   * @version $Id: TestQueue.java,v 1.1 2005/03/17 13:58:41 pavlidis Exp $
    20   */
    21
    22  public class TestQueue extends TestCase {
    23     private Queue queue = null;
    24     private Queue shortQueue = null;
    25
    26     protected void setUp() throws Exception {
    27        super.setUp();
    28        queue = new Queue();
    29        queue.enqueue( new Integer( 1 ) );
    30        queue.enqueue( new Integer( 2 ) );
    31        queue.enqueue( new Integer( 3 ) );
    32        queue.enqueue( new Integer( 4 ) );
    33        queue.enqueue( new Integer( 5 ) );
    34
    35        shortQueue = new Queue( 3 );
    36     }
    37
    38     protected void tearDown() throws Exception {
    39        queue = null;
    40        super.tearDown();
    41     }
    42
    43     public void testEnqueue() {
    44        Integer expectedReturn = new Integer( 101 );
    45        queue.enqueue( new Integer( 100 ) );
    46        queue.enqueue( new Integer( 101 ) );
    47        queue.enqueue( new Integer( 102 ) );
    48        queue.enqueue( new Integer( 103 ) );
    49        queue.dequeue();
    50        queue.dequeue();
    51        queue.dequeue();
    52        queue.dequeue();
    53        queue.dequeue();
    54        queue.dequeue();
    55        Integer actualReturn = ( Integer ) queue.dequeue();
    56        assertEquals( "return value", expectedReturn, actualReturn );
    57     }
    58
    59     public void testDequeue() {
    60        Integer expectedReturn = new Integer( 3 );
    61        queue.dequeue();
    62        queue.dequeue();
    63        Integer actualReturn = ( Integer ) queue.dequeue();
    64        assertEquals( "return value", expectedReturn, actualReturn );
    65     }
    66
    67     public void testEmptyDequeue() {
    68        queue.dequeue();
    69        queue.dequeue();
    70        queue.dequeue();
    71        queue.dequeue();
    72        queue.dequeue();
    73        queue.dequeue();
    74        Integer actualReturn = ( Integer ) queue.dequeue();
    75        Integer expectedReturn = null;
    76        assertEquals( "return value", expectedReturn, actualReturn );
    77     }
    78
    79     public void testFullEnqueue() {
    80        try {
    81           shortQueue.enqueue( new Integer( 495 ) );
    82           shortQueue.enqueue( new Integer( 495 ) );
    83           shortQueue.enqueue( new Integer( 495 ) );
    84           shortQueue.enqueue( new Integer( 495 ) );
    85           shortQueue.enqueue( new Integer( 495 ) );
    86           fail( "Should raise an IndexOutOfBoundsException" );
    87        } catch ( IndexOutOfBoundsException success ) {
    88
    89        }
    90
    91     }
    92
    93  }