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