//**************************************************************
//
//  CS 240B   : Winter 2003 Ohio University Travis Dillon
//  Project 5 : linked list
//  file      : prog5b.cc
//  started   : 03-06-03
//
//**************************************************************

#include "list.h"
#include "node.h"
#include "prog5b.h"

void test();
void hand_in();

int main()
{
   cout <<"\n\nLinked List Demo\n\n";
   test();
   hand_in();
   return EXIT_SUCCESS;
}

void test()
{   
   ofstream fout;
   fout.open("tester.txt");
   fout <<"\n\nTest Nodes and Lists\n\n";
   //test everything you can think of here.
   int x[100];
   int y[200];
   int z[300];
   
   for(int i(0); i < 100; ++i) x[i] = rand() % 399;
   for(int i(0); i < 200; ++i) y[i] = rand() % 699;
   for(int i(0); i < 300; ++i) z[i] = rand() % 999;
   
   List alist(x,100);
   List blist(y,200);
   List clist(z,300);
   List empty_list;
   List merge_list;
   
   empty_list.tell_all(fout, "empty_list");
   
   fout <<"\nlist \"alist\" unsorted" << alist;
   fout <<"\nlist \"blist\" unsorted" << blist;
   fout <<"\nlist \"clist\" unsorted" << clist;   
      
   //testing the selection sort
   alist.selection_sort();
   blist.selection_sort();
   clist.selection_sort();
   
   if(alist.is_sorted() && blist.is_sorted() && clist.is_sorted())
   fout << "\nMy selection sort works! :)\n";
   else
   fout << "\nMy selection sort is junk! :(\n";
   
   fout <<"\nlist \"alist\" sorted" << alist;
   fout <<"\nlist \"blist\" sorted" << blist;
   fout <<"\nlist \"clist\" sorted" << clist;
      
   //checking different lenghts of list to merge
   sorted_merge(merge_list, alist, blist);
   fout <<"\n\"alist\" merged with \"blist\"" << endl << merge_list;
   
   sorted_merge(merge_list, alist, clist);
   fout <<"\n\"alist\" merged with \"clist\"" << endl << merge_list;
   
   sorted_merge(merge_list, blist, clist);
   fout <<"\n\"blist\" merged with \"clist\"" << endl << merge_list;
   
   sorted_merge(merge_list, alist, empty_list);
   fout <<"\n\"alist\" merged with \"empty_list\"" << endl << merge_list;
   
   sorted_merge(merge_list, empty_list, alist);
   fout <<"\n\"empty_list\" merged with \"alist\"" << endl << merge_list;
   
   sorted_merge(merge_list, alist, alist);
   fout <<"\n\"alist\" merged with \"alist\"" << endl << merge_list;
   
   //below is for finding the speed of the two sort functions
   //this works on windows, but not unix
   int w[20000];
   for(int i(0); i < 20000; ++i) w[i] = rand();
   List gs_list(w, 20000);
   List ss_list = gs_list;
   
   //clock_t ss_time;
   ss_list.selection_sort();
   //ss_time = clock();
   
   //clock_t gs_time;
   gs_list.generic_sort();
   //gs_time = clock();
   
   //fout << endl << "generic sort = " << gs_time - ss_time<<" milliseconds";
   //fout << endl << "selection sort time = " << ss_time <<" milliseconds";
   //selection sort is definately faster.
   
   fout.close();
}

void hand_in()
{
   cout << "\n\nProg5b function hand_in()\n\n";
   
   ofstream fout;
   fout.open("hand_in.txt");
   
   fout <<"CS 240b  OU EECS Winter 2003  Travis Dillon\n" << endl;
   
   fout << "\n\nsorted merge\n\n";
   
   List bb0, bb1, bb2;
   for(int i(0); i < 22; ++i)
   {
      bb1.push_in_order(rand() % 44 +1);
      bb2.push_in_order(rand() % 33 + 15);
   }
   bb2.push_in_order(99);
   bb2.push_in_order(0);
   sorted_merge(bb0, bb1, bb2);
   fout << "\n\nList 1:\n" << bb1;
   fout << "\n\nList 2:\n" << bb2;
   fout << "\n\nmerged lists:\n" << bb0;
      
   fout.close();
}