/*
 * This file: list_test.cpp
 * This file contains the implementation of a test program 
 * for the linked list class container.
 */

#include <iostream>
#include <string>
#include "Name.h"
#include "BinarySearchTree.h"

using namespace std;
using namespace uprm_icom4035;


void empty_test(const BinarySearchTree<Name,string>& L);
void find_test(const BinarySearchTree<Name,string>& L,
	       const Name& name);

int main(){
  BinarySearchTree<Name,string> L;
  Name name;
  
  empty_test(L);

  name = Name("Bob", "Smith");
  cout << "Adding name: " << name << endl;
  L.insert(name);
  cout << "Tree height: " << L.height() << endl;

  name = Name("Kelly", "Zim");
  cout << "Adding name: " << name << endl;
  L.insert(name);
  cout << "Tree height: " << L.height() << endl;
  
  name = Name("Tim", "Newport");
  cout << "Adding name: " << name << endl;
  L.insert(name);
  cout << "Tree height: " << L.height() << endl;

  name = Name("Carlos", "Garcia");
  cout << "Adding name: " << name << endl;
  L.insert(name);
  cout << "Tree height: " << L.height() << endl;

  name = Name("Pedro", "Rossello");
  cout << "Adding name: " << name << endl;
  L.insert(name);
  cout << "Tree height: " << L.height() << endl;

  name = Name("Antonio", "Rivas");
  cout << "Adding name: " << name << endl;
  L.insert(name);

  name = Name("Anibal", "Acevedo");
  cout << "Adding name: " << name << endl;
  L.insert(name);
  
  cout << "Tree height: ";
  cout << L.height() << endl;

  cout << "Printing tree: " << endl;
  L.print_tree(cout);
    
  name = Name("Bob", "Bellis");
  find_test(L, name);
  
  name = Name("Carlos", "Garcia");
  find_test(L, name);

  name = Name("Kelly", "Zim");
  if (L.erase(name.get_key())){
    cout << "Name: " << name << " was erased" << endl;
  }
  else {
    cout << "Name: " << name << " was not found" << endl;
  }

  name = Name("Tim", "Newport");
  if (L.erase(name.get_key())){
    cout << "Name: " << name << " was erased" << endl;
  }
  else {
    cout << "Name: " << name << " was not found" << endl;
  }
  
  name = Name("Jose", "Mendez");
  L.insert(name);


  name = Name("Carlos", "Garcia");
  find_test(L, name);

  cout << "Printing tree: " << endl;
  L.print_tree(cout);
  
  cout << endl;
  empty_test(L);
  cout << endl;

  cout << "Printing tree: " << endl;
  L.print_tree(cout);

  cout << endl;
  
  L.make_empty();
  empty_test(L);
  cout << "Done!" << endl;
}

void empty_test(const BinarySearchTree<Name,string>& L){
  if (L.is_empty()){
    cout << "No elements in the tree." << endl;
  }
  else {
    cout << "Some data on the tree" << endl;
  }
}

void find_test(const BinarySearchTree<Name,string>& L,
	       const Name& name){
  cout << "Finding name: " << name << endl;
  BST_preorder_iterator<Name,string> iter = L.find(name.get_key());
  if (iter.has_data()){
    cout << "Name: " << name << " was found." << endl;
  }
  else {
    cout << "Name: " << name << " was not found." << endl;
  }  
}
