#include #include "arraylist.h" using namespace std; // --------------------------------------------------------- void test01() { ArrayList a; cout << endl << endl; cout << " ***************** " << endl; cout << " * TEST SET #1 * " << endl; cout << " ***************** " << endl; cout << "List a is empty" << endl; cout << a << endl; cout << "Size of a = " << a.size() << endl; //TEST : Inserting 10 numbers to a cout << endl << "TEST : Inserting 10 numbers to a" << endl; for (unsigned int k=0; k<10; k++){ a.insert_back(k+1); } cout << a << endl; cout << "Size of a = " << a.size() << endl; //TEST : Inserting elements in the middle cout << endl << "TEST : Inserting elements in the middle" << endl; for (unsigned int k=5; k<12; k++){ a.insert(k+10, k); } cout << a << endl; cout << "Size of a = " << a.size() << endl; // TEST : Acessing individual elements; cout << endl << "TEST : Acessing individual elements" << endl; cout << "a.first() = " << a.first() << endl; cout << "a[5] = " << a[5] << endl; cout << "a[10] = " << a[10] << endl; cout << "a[13] = " << a[13] << endl; // TEST : Changing elements cout << endl << "TEST : Changing elements" << endl; for (unsigned int k=0; k a; ArrayList b; cout << endl << endl; cout << " ***************** " << endl; cout << " * TEST SET #3 * " << endl; cout << " ***************** " << endl; cout << "List a is empty" << endl; cout << a << endl; cout << "Size of a = " << a.size() << endl; //TEST : Inserting 10 elements to a cout << endl << "TEST : Inserting 10 elements to a" << endl; for (unsigned int k=0; k<10; k++){ a.insert_back(static_cast(k+97)); } cout << a << endl; cout << "Size of a = " << a.size() << endl; //TEST : Operator = cout << endl << "TEST : Operator =" << endl; cout << "Before Copy" << endl; cout << "a = " << a << endl; cout << "b = " << b << endl; b = a; cout << "After Copy" << endl; cout << "a = " << a << endl; cout << "b = " << b << endl; cout << "changing elements of b (making sure its a deep copy)" << endl; b[0] += 10; b[1] += 10; b[2] += 10; b[3] += 10; cout << "a = " << a << endl; cout << "b = " << b << endl; //TEST : Copy Constructor cout << endl << "TEST : Copy Constructor" << endl; ArrayList c (b); cout << "b = " << b << endl; cout << "c = " << c << endl; cout << "changing elements of c (making sure its a deep copy)" << endl; c[0] += 10; c[1] += 10; c[2] += 10; c[3] += 10; cout << "b = " << b << endl; cout << "c = " << c << endl; } // --------------------------------------------------------- void test04() { ArrayList a; ArrayList b; cout << endl << endl; cout << " ***************** " << endl; cout << " * TEST SET #4 * " << endl; cout << " ***************** " << endl; for (unsigned int k=0; k<10; k++){ a.insert_back(static_cast(k+97)); } //TEST : Swap cout << endl << "TEST : Swap (reversing some elements)" << endl; cout << a << endl; for (unsigned int k=0; k< a.size()/2; k++){ a.swap(k,a.size()-1-k); } cout << a << endl; //TEST : append cout << endl << "TEST : append" << endl; for (unsigned int k=0; k<10; k++){ b.insert_back(static_cast(k+100)); } cout << "Before Append" << endl; cout << "a = " << a << endl; cout << "b = " << b << endl; a.append(b); cout << "After Append" << endl; cout << "a = " << a << endl; cout << "b = " << b << endl; //TEST : Purge cout << endl << "TEST : Purge" << endl; cout << "Before Purge" << endl; cout << "a = " << a << endl; a.purge(); cout << "After Purge" << endl; cout << "a = " << a << endl; } // --------------------------------------------------------- void test05() { ArrayList a; ArrayList b; cout << endl << endl; cout << " ***************** " << endl; cout << " * TEST SET #5 * " << endl; cout << " ***************** " << endl; cout << endl; for (unsigned int k=0; k<10; k++){ a.insert_back(3.14 * k); } cout << "a = " << a << endl; cout << "b = " << b << endl; //TEST : Graceful PANIC cout << endl << "TEST : checking for graceful error handling" << endl; cout << "b.first() : " << endl; b.first(); cout << "a[5] = " << a[5] << endl; cout << "a[50] = " << a[50] << endl; cout << "a = " << a << endl; cout << "b = " << b << endl; //TEST : More Graceful PANIC cout << endl << "TEST : More checking for graceful error handling" << endl; cout << "a.insert(9.9, 20) : " << endl; a.insert(9.9, 20); cout << "a.remove(555) :" << endl; a.remove(555); cout << "a.swap(1,100) :" << endl; a.swap(1,100); cout << "a.swap(40,41) :" << endl; a.swap(40,41); cout << "a = " << a << endl; } int main () { cout << "Hello World!!, This is the LARGE Tester" << endl; test01(); test02(); test03(); test04(); test05(); cin.clear (); cout << "Press Any Key to Continue" << endl; cin.get(); return 0; }