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

#include <iostream>
#include <string>
#include <cstdlib>
#include "CLList.h"

using namespace std;
using namespace uprm_icom4035;

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

int main(){
  CLList<string> L;
  string  name;
  
  empty_test(L);

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

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

  name = "Carlos Garcia";
  cout << "Adding name: " << name << endl;
  L.insert(name);
  
  cout << "Printing list forward: " << endl;
  L.print_list(cout);

  cout << "Printing list 2 forward: " << endl;
  CLList<string> L2(L);
  L.print_list(cout);
  
  name = "Bob Bellis";
  find_test(L, name);
  
  name = "Carlos Garcia";
  find_test(L, name);

  name = "Kelly Zim";
  cout << "Erase Kelly: " << L.erase(name) << endl;

  name = "Tim Newport";
  cout << "Erase Tim NewPort: " << L.erase(name) << endl;
  
  name = "Bob Dole";
  cout << "Erase Bob Dole: " << L.erase(name) << endl;
  
  name = "Jose Mendez";
  cout << "Adding name: " << name << endl;
  L.insert(name);
  
  cout << endl;
  empty_test(L);
  cout << endl;

  cout << "Printing list forward: " << endl;
  L.print_list(cout);
  
  L.make_empty();

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

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

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