//StackGrader.java

import java.util.EmptyStackException;

/**
 * Tests an implementation of a Stack for correctness.
 *
 * @author Zach Tomaszewski
 * @version 18 Feb 2005
 */
public class StackGrader {

  /**
   * Runs a number of tests of a stack, printing the expected results and actual
   * results to the screen.
   */
  public static void main(String[] args) {
    System.out.println("Creating a new stack.");
    Stack stack = new MyStack();
    System.out.print("A new stack is empty [true]: ");
    System.out.println(stack.empty() + "");
    System.out.println("Pushing 'one'.");
    stack.push("one");
    System.out.println("Pushing 'two'.");
    stack.push("two");
    System.out.println("Pushing 'three'.");
    stack.push("three");
    System.out.println("Printing the list (assuming a working toString())");
    System.out.println("[TOP> three, two, one]: "); 
    System.out.println(stack.toString());

    System.out.print("Popping. [three]: ");
    System.out.println(stack.pop());
    System.out.print("Top (peeking). [two]: ");
    System.out.println(stack.top() + "");    
    System.out.print("Popping. [two]: ");
    System.out.println(stack.pop());
    System.out.print("Stack is empty? [false]: ");
    System.out.println(stack.empty() + "");
    System.out.println("Clearing stack.");
    while (!stack.empty()) {
      stack.pop();
    }
    
    try{    
      System.out.print("Peeking/top at empty stack [EmptyStackException?]: ");
      System.out.println("" + stack.top());
    }catch (EmptyStackException ese) {
      System.out.println("EmptyStackException");
    }
    try{    
      System.out.print("Popping empty stack [EmptyStackException?]: ");
      System.out.println("" + stack.pop());
    }catch (EmptyStackException ese) {
      System.out.println("EmptyStackException");
    }
  }

}
