#include <iostream>

using namespace std;

#include "PStack.h"
#include "PStackExceptions.h"

void testPop(ostream & out, PStack & stack);
void testGetTop(ostream & out, const PStack & stack);

int main()
{
  //Test default constructor, isEmpty, display, and overloaded<<
  PStack stack1;
  cout << "Is stack1 empty? " << boolalpha << stack1.isEmpty() << endl ;
  cout << "Size:  " << stack1.getSize() << endl << stack1 << endl;

  //Test push
  for (Element i=10; i<=100; i+=10)
  {
    stack1.push(i);
    cout << "Is stack1 empty? " << boolalpha << stack1.isEmpty() << endl;
    cout << "Size:  " << stack1.getSize() << endl << stack1 << endl;
  }

  //Test getTop, pop
  for (Element i=10; i<=100; i+=10)
  {
    cout << "Top is: " << stack1.getTop() << endl << "Now, pop top!" << endl;
    testPop(cout, stack1);
    cout << "Is stack1 empty? " << boolalpha << stack1.isEmpty() << endl;
    cout << "Size:  " << stack1.getSize() << endl << stack1 << endl;
  }
  
  testGetTop(cout, stack1);
  testPop(cout, stack1);
  
  //Test input
  PStack stack2;
  cout << "Enter contents of stack2, followed by X:  " << endl;
  cin >> stack2;
  cout << "Is stack2 empty? " << boolalpha << stack2.isEmpty() << endl;
  cout << "Size:  " << stack2.getSize() << endl << stack2 << endl;
  

  return 0;

}


void testPop(ostream & out, PStack & stack)
{
  try
  {
    stack.pop();
  }
  catch(Empty e)
  {
    out << "Invocation of " << e.getMessage() << " failed:  Stack is empty." << endl;
  }
}

void testGetTop(ostream & out, const PStack & stack)
{
  try
  {
    Element item = stack.getTop();
    out << "Last item added to stack was:  " << item << endl;
  }
  catch(Empty e)
  {
    out << "Invocation of " << e.getMessage() << " failed:  Stack is empty." << endl;
  }
}
