/**
 * Tests a Queue implementation.
 *
 * @author Zach Tomaszewski
 * @version 29 Oct 2003
 */
public class TestQueue {

  /**
   * Steps through a sample queue object, calling each of Queue's
   * methods in a number of different contexts.  Prints the results
   * to the screen (standard out).
   */
  public static void main (String[] args){
  
    //RENAME YOUR QUEUE IMPLEMENTATION CLASS HERE
    Queue queue = new MyQueue();

    try{  
      System.out.print("New queue is empty? [true]: ");
      System.out.println(queue.isEmpty());
      System.out.print("Size is [0]: ");
      System.out.println(queue.size());
      System.out.println();

      System.out.print("Adding an element (1): ");
      queue.enqueue(new Integer(1));
      System.out.println("done.");
      System.out.print("Queue is now empty? [false]: ");
      System.out.println(queue.isEmpty());
      System.out.print("Size is now [1]: ");
      System.out.println(queue.size());
      System.out.print("Peeking at this added item [1]: ");
      System.out.println(queue.peek().toString());
      System.out.println();
      
      System.out.print("Removing the element: ");
      System.out.println(queue.dequeue().toString());
      System.out.print("Queue is empty? [true]: ");
      System.out.println(queue.isEmpty());
      System.out.print("Size is [0]: ");
      System.out.println(queue.size());
      System.out.println(
      );
      System.out.print("Adding a number of elements (1 2 3 4): ");
      queue.enqueue(new Integer(1));
      queue.enqueue(new Integer(2));
      queue.enqueue(new Integer(3));
      queue.enqueue(new Integer(4));
      System.out.println("done.");
      System.out.print("Size is [4]: ");
      System.out.println(queue.size());
      System.out.print("Removing an element [1]: ");
      System.out.println(queue.dequeue().toString());
      System.out.print("DequeingAndPrinting the rest [2 3 4]: ");
      System.out.println(queue.dequeueAndPrint());
      System.out.print("Adding elements again (1 2 3 4): ");
      queue.enqueue(new Integer(1));
      queue.enqueue(new Integer(2));
      queue.enqueue(new Integer(3));
      queue.enqueue(new Integer(4));
      System.out.println("done.");
      System.out.print("Popping all: ");
      queue.dequeueAll();
      System.out.println("done.");
      System.out.print("Queue is now empty? [true]: ");
      System.out.println(queue.isEmpty());
      
    }catch (QueueException qe){
      System.out.println("Caught an unexpected QueueException."); 
      System.out.println("Please fix your code and try again.");
    }
  
    System.out.println("\nChecking exceptions now...");
    try {
      System.out.print("Dequeuing empty queue: ");
      queue.dequeue();
      System.out.println("failed.");
    }catch (QueueException qe){
      System.out.println("caught.");
    }

    try {
      System.out.print("Dequeuing and printing empty queue: ");
      queue.dequeueAndPrint();
      System.out.println("failed.");
    }catch (QueueException qe){
      System.out.println("caught.");
    }
    System.out.println("\nDone testing Queue implementation.");
  }

}//end class
