Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef __LINKEDLISTTEST_CPP__
- #define __LINKEDLISTTEST_CPP__
- #include <iostream>
- #include "LinkedList.h"
- template <typename T>
- int main ()
- {
- LinkedList<Datatype> list1; // use default constructor to create and empty LinkedList
- LinkedList<Datatype> emptyList(list1); // Use copy constructor to create a copy of an empty LinkedList
- LinkedList<Datatype> list2; // create linked list with one element
- list2.insert(10);
- LinkedList<Datatype> list3; // create a linked list with more than one element
- list3.insert(20);
- list3.insert(30);
- list3.insert(40);
- LinkedList <Datatype> list2_copy(list2);
- LinkedList <Datatype> list3_copy(list3);
- LinkedList <Datatype> list4 = list2;
- LinkedList <Datatype> list5 = list3;
- list5 = list2;
- list4 = list3;
- list1.isEmpty();
- // This section contains the tests to check if the list is empty or not
- if (list1.isEmpty() == true) // check if an empty list is empty
- {
- cout << "This List is Empty bro" << endl;
- }
- else if (list1.isEmpty() == false)
- cout << "This List is not Empty bro" << endl;
- list3.isEmpty();
- if (list3.isEmpty() == true) // check if with a full list that is empty
- {
- cout << "This List is Empty bro" << endl;
- }
- else if (list3.isEmpty() == false)
- cout << "This List is not Empty bro" << endl;
- list4.removeAll();
- list4.isEmpty();
- if (list4.isEmpty() == true) // check if list4 that had an element was removed and see if the list is empty
- {
- cout << "This List is Empty bro" << endl;
- }
- else if (list4.isEmpty() == false)
- cout << "This List is not Empty bro" << endl;
- // count tests
- list1.getCount();
- cout <<list1.getCount() << endl; // with no elements
- list2.getCount();
- cout << list2.getCount() << endl; // with one element
- list3.getCount();
- cout << list3.getCount() << endl; // with more then one element
- list3.removeAll(); // with more then one element erased then counted
- list3.getCount();
- cout << list3.getCount() << endl;
- // contain tests
- list1.contains(1);
- if (list1.contains(1) == true)
- cout << "The list does not contains an element" << endl;
- else if (list1.contains(1) == false)
- cout << "The list does not contain an element" << endl;
- list2.contains(10);
- if (list2.contains(10) == true)
- cout <<"This list does contain this element"<< endl;
- else if (list2.contains(10) == false)
- cout << "This list does not contain this element" << endl;
- // Tests for head, tail neither its head nor tail elements
- list3.insert(20); // reinserting values back into list3 after removing them in previous test
- list3.insert(30);
- list3.insert(40);
- list3.contains(20);
- if (list3.contains(20) == true)
- cout << "List3 contains its head element" << endl;
- else if (list3.contains(20) == false)
- cout << "List3 does not contain its head element" << endl;
- list3.contains(40);
- if (list3.contains(40) == true)
- cout <<"List3 contains its tail element" << endl;
- else if (list3.contains(40) == false)
- cout <<"List3 does not contain its tail element" << endl;
- list3.contains(30);
- if (list3.contains(30) == true)
- cout << "List3 contains an element that is neither head nor tail " << endl;
- else if (list3.contains(30) == false)
- cout << "List3 does not contains an element that is neither head nor tail " << endl;
- // find tests done in list 3 and list1
- list1.find(1);
- cout << list1.find(1) << endl;
- list3.find(10);
- cout << list3.find(10) << endl;
- list3.find(20);
- cout << list3.find(20) << endl;
- list3.find(40);
- cout << list3.find(40) << endl;
- list3.find(30);
- cout << list3.find(30) << endl;
- // be aware that the value of NOT_IN_LIST = 4294967295
- // testing the remove function with list3 and list2
- list2.removeByIndex(0);
- list2.isEmpty();
- if (list2.isEmpty() == true)
- cout <<"list2 was successfully removed and is now empty" << endl; // checks if it was successfully removed
- else if (list2.isEmpty() == false)
- cout <<"list2 was not successfully removed and still contains an element" << endl;
- list3.removeByIndex(0);
- list3.find(30);
- cout << list3.find(30) << endl; // successfully set 30 to the head when head was removed
- // now 30 is head and 40 is the tail
- // test to see remove 40 (tail) and find 40
- list3.removeByIndex(1);
- list3.find(40);
- cout << list3.find(40) << endl; // sucessful list3.find(40) returned NOT_IN_LIST!
- // now removing the last element 30
- list3.removeByIndex(0);
- list3.isEmpty(); // checking now if list3 is empty
- if (list3.isEmpty() == true)
- cout <<"List3 is empty " << endl;
- else if (list3.isEmpty() == false)
- cout <<"List3 is not empty" << endl;
- list3.insert(20); // reinserting values back into list3 after removing them in previous test
- list3.insert(30);
- list3.insert(40);
- list1.~LinkedList();
- list2.~LinkedList();
- list3.~LinkedList();
- if (list3.isEmpty() == true)
- cout <<"List3 is empty " << endl;
- else if (list3.isEmpty() == false) // checking if the destructor properly emptied list3
- cout <<"List3 is not empty" << endl;
- return 0;
- }
- #endif
Add Comment
Please, Sign In to add comment