#include #include "ListT.h" using namespace std; const int MAX_ITEMS {10000}; void BasicTest(); void StressInsertTest(); void PrintList(ListT & list); bool CheckList(ListT & list); int main() { srand(static_cast(time(nullptr))); BasicTest(); cout << endl; cout << "Beginning stress test" << endl; StressInsertTest(); cout << "Ending stress test" << endl; return 0; } void StressInsertTest() { int i; int data; ListT list; for(i =0; i < MAX_ITEMS; i++) { data = rand() % 1000; list.Insert(data); if (list.Size() != i+1) { cout << "Array size incorrect at step " << i << endl; cout << "The size is " << list.Size() << " but should be " << i+1 << endl; PrintList(list); } if (not CheckList(list)) { PrintList(list); } if (not list.IsPresent(data) ) { cout << data << " was just inserted but is not found." << endl; PrintList(list); } } } void BasicTest() { ListT list; PrintList(list); list.Insert(1); PrintList(list); list.Delete(1); PrintList(list); list.Insert(2); list.Insert(1); list.Insert(3); PrintList(list); list.Delete(2); PrintList(list); list.Delete(3); PrintList(list); list.Insert(2); list.Insert(3); PrintList(list); list.Delete(1); PrintList(list); list.Delete(99); PrintList(list); } bool CheckList(ListT & list){ bool good = true; int last; int now; if (list.Size() > 1) { list.Home(); last = list.Current(); list.Next(); while(good and not list.IsLast()) { now = list.Current(); if (now < last) { good = false; } else { list.Next(); last = now; } } } return good; } void PrintList(ListT & list){ cout << endl; cout << "************************" << endl; cout << "The list has " << list.Size() << " elements." << endl; if (not CheckList(list)) { cout << "The order of the list is bad" << endl; } list.Home(); while(not list.IsLast()) { cout << list.Current() << " " ; list.Next(); } cout << endl; return; }