//for testing #include "javert.h" bool Javert::AddStuff (todoList &curr) const { curr.addTask("Get up"); curr.addTask("Wash face"); curr.addTask("Dress"); curr.addTask("Gather books"); curr.addTask("Leave for class"); curr.addTask("Have lunch"); curr.addTask("Do homework"); curr.addTask("Sleep"); return true; } bool Javert::Print(std::ostream& Out, const todoList &curr) const { if (curr.nTasks == 0) { curr.Display(std::cout); return false; } else { unsigned int Offset = 0; while ( Offset < curr.nTasks ) { Out << std::setw(3) << Offset << " "; Out << "(loc: " << &curr.List[(curr.doNext + Offset) % curr.Capacity] << ") "; Out << curr.List[(curr.doNext + Offset) % curr.Capacity]; Out << std::endl; Offset++; } return true; } return false; } bool Javert::Compare(std::ostream& Out, todoList list, todoList list2) const { std::string status_template; status_template = "Comparison for two lists: "; if (list.putNext != list2.putNext) { Status (Out, status_template + "different putNext"); return false; } if (list.doNext != list2.doNext) { Status (Out, status_template + "different doNext"); return false; } if (list.Capacity != list2.Capacity) { Status (Out, status_template + "different Capacity"); return false; } if (list.nTasks != list2.nTasks) { Status (Out, status_template + "different nTasks"); return false; } //check data similarity for (unsigned int loop = 0; loop < list.Capacity; loop++) { if (list.List[loop] != list2.List[loop]) { Status (Out, status_template + "different data"); return false; } } Status (Out, status_template + "same"); return true; } void Javert::Status(std::ostream& Out, const std::string &msg) const { Out << std::endl << "*** " << msg << std::endl; } bool Javert::RunTest() const { Status(std::cout, "Initializing..."); Status(std::cout, "todoList test written by Dobby Kolev"); std::string disclaimer; disclaimer = "This software comes without stated, written or implied warranty\n"; disclaimer += "You are using it at your own risk\n"; disclaimer += "You agree that it may not catch all bugs in your modules"; Status(std::cout, disclaimer); Status(std::cout, "Press a key to continue..."); getchar(); //begin testing todoList source; todoList copy_byoperator; //test and print the copy by operator Status(std::cout, "Testing copying of an empty list"); copy_byoperator = source; Print(std::cout, copy_byoperator); //print empty list Status(std::cout, "Print initial values of source list"); Print(std::cout, source); //add stuff to list Status(std::cout, "Add stuff to the source list"); AddStuff(source); //print list Status(std::cout, "Print the list again"); Print(std::cout, source); Status(std::cout, "Press a key to continue (test = operator)..."); getchar(); //test and print the copy by operator Status(std::cout, "Copy using the = operator"); copy_byoperator = source; Print(std::cout, copy_byoperator); Compare(std::cout, source, copy_byoperator); Status(std::cout, "Press a key to continue (test copy contructor)..."); getchar(); //test and print the copy by contructor Status(std::cout, "Copy using the copy contructor"); todoList copy_bycontructor(source); Print(std::cout, copy_bycontructor); Compare(std::cout, source, copy_bycontructor); Status(std::cout, "Press a key to continue (test a list onto itself)..."); getchar(); Status(std::cout, "Copy onto itself"); source = source; Print(std::cout, source); //Compare(std::cout, source, copy_bycontructor); Status(std::cout, "Press a key to continue (run misc test)..."); getchar(); Status(std::cout, "Make a new huge list, add stuff to is and copy to an existing"); todoList hugelist(100); AddStuff(hugelist); AddStuff(hugelist); copy_byoperator = hugelist; Print(std::cout, copy_byoperator); Compare(std::cout, hugelist, copy_byoperator); Status(std::cout, "DONE...the program didn't blow up."); Status(std::cout, "Look at your output window for memory leak information."); Status(std::cout, "If no leak info listed, you are all set and can submit."); getchar(); return true; }