/* BSTtester.cpp is a program for testing class template BST.
 *
 * Written by:   Larry R. Nyhoff
 * Written for:  Lab Manual for C++: An Introduction to Data Structures
 *************************************************************************/

#include <iostream>
using namespace std;

#include "BST"

/*---- PART 3 ----
                                 // MakeCopy() is a function with a
void MakeCopy(BST<int> aBST)     // BST value parameter
{                                // to test the copy constructor
  cout << "\nNow copying the BST and adding 38999,"
          " -12312, and 55657 to the copy:\n";
  aBST.Insert(38999);
  aBST.Insert(-12312);
  aBST.Insert(55657);
  cout << "--Inorder Traversal of the copy: \n";
  aBST.Inorder(cout);
}
---- END PART 3 ----*/

int main()
{
  // Testing Constructor and Empty()
  BST<int> intBST;            // test the class constructor
  cout << "Constructing empty BST\n";
  cout << "BST " << (intBST.Empty() ? "is" : "is not") << " empty\n";

  // Testing Inorder
  cout << "Inorder Traversal of BST: \n";
  intBST.Inorder(cout);

  // Testing Insert()
  cout << "\nNow insert a bunch of integers into the BST."
          "\nTry items not in the BST and some that are in it:\n";
  int number;
  for (;;)
  {
    cout << "Item to insert (-999 to stop): ";
    cin >> number;
    if (number == -999) break;
    intBST.Insert(number);
  }
  cout << "BST " << (intBST.Empty() ? "is" : "is not") << " empty\n";
  cout << "Inorder Traversal of BST: \n";
  intBST.Inorder(cout);

  cout << endl;

  // Testing Search()
  cout << "\n\nNow testing the Search() operation."
          "\nTry both items in the BST and some not in it:\n";
  for (;;)
  {
    cout << "Item to find (-999 to stop): ";
    cin >> number;
    if (number == -999) break;
    cout << (intBST.Search(number) ? "Found" : "Not found") << endl;
  }

  // Testing Delete()
  cout << "\nNow testing the Delete() operation."
          "\nTry both items in the BST and some not in it:\n";
  for (;;)
  {
    cout << "Item to delete (-999 to stop): ";
    cin >> number;
    if (number == -999) break;
    intBST.Delete(number);
  }
  cout << "\nInorder Traversal of BST: \n";
  intBST.Inorder(cout);
  cout << endl;

/* ---- PART 1 ----
  // Testing Preorder and Postorder
  cout << "\nInorder Traversal of BST: \n";
  intBST.Inorder(cout);
  cout << "\nPreorder Traversal of BST: \n";
  intBST.Preorder(cout);
  cout << "\nPostorder Traversal of BST: \n";
  intBST.Postorder(cout);
  cout << endl;
---- END PART 1 ----*/


/* ---- PART 2 ----
  // Testing the Destructor
  cout << "\nNow testing the destructor.  Remember to add an output\n"
          "statement to your destructor to indicate when it is called.\n";
  {
    BST<int> anotherBST;
    anotherBST.Insert(6); anotherBST.Insert(9); anotherBST.Insert(5);
    anotherBST.Insert(1); anotherBST.Insert(3); anotherBST.Insert(7);
    cout << "\nInorder Traversal of another BST: \n";
    cout << "\n\nLifetime of this BST is over -- now destroy it.\n";
  }
---- END PART 2 ----*/


/* ---- PART 3 ----
  // Testing the Copy Constructor
  cout << "\nNow testing the copy constructor.\n";
  cout << "-- First with an initializing declaration: "
          "BST<int> copy = intBST;\n";
  BST<int> copy = intBST;
  cout << "-- Inorder traversal of copy:\n";
  copy.Inorder(cout);
  cout << "\n\n-- Now by passing intBST to a value parameter:\n";
  MakeCopy(intBST);
  cout << "\n--Check that original BST hasn't been changed.\n"
          "-- Inorder traversal of original:\n";
  intBST.Inorder(cout);
  cout << endl;
---- END PART 3 ----*/


/* ---- PART 4 ----
  // Testing the Assginment Operator
  cout << "\nNow testing the assignment constructor with the statement:\n"
          "        copy = anotherBST = intBST;\n";
  BST<int> anotherBST;
  copy = anotherBST = intBST;
  cout << "\n-- Inorder traversal of intBST:\n";
  intBST.Inorder(cout);
  cout << endl;
  cout << "\n-- Inorder traversal of anotherBST:\n";
  anotherBST.Inorder(cout);
  cout << endl;
  cout << "\n-- Inorder traversal of copy:\n";
  copy.Inorder(cout);
  cout << endl;
---- END PART 4 ----*/

}


