daily pastebin goal
3%
SHARE
TWEET

Untitled

a guest Apr 20th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifndef __LINKEDLISTTEST_CPP__
  2. #define __LINKEDLISTTEST_CPP__
  3. #include <iostream>
  4. #include "LinkedList.h"
  5. template <typename T>
  6. int main ()
  7. {
  8.     LinkedList<Datatype> list1; // use default constructor to create and empty LinkedList
  9.     LinkedList<Datatype> emptyList(list1); // Use copy constructor to create a copy of an empty LinkedList
  10.     LinkedList<Datatype> list2; // create linked list with one element
  11.     list2.insert(10);
  12.     LinkedList<Datatype> list3; // create a linked list with more than one element
  13.     list3.insert(20);
  14.     list3.insert(30);
  15.     list3.insert(40);
  16.     LinkedList <Datatype> list2_copy(list2);
  17.     LinkedList <Datatype> list3_copy(list3);
  18.     LinkedList <Datatype> list4 = list2;
  19.     LinkedList <Datatype> list5 = list3;
  20.     list5 = list2;
  21.     list4 = list3;
  22.     list1.isEmpty();
  23.    
  24.     // This section contains the tests to check if the list is empty or not
  25.    
  26.     if (list1.isEmpty() == true) // check if an empty list is empty
  27.     {
  28.         cout << "This List is Empty bro" << endl;
  29.     }
  30.     else if (list1.isEmpty() == false)
  31.     cout << "This List is not Empty bro" << endl;
  32.     list3.isEmpty();
  33.     if (list3.isEmpty() == true) // check if with a full list that is empty
  34.     {
  35.         cout << "This List is Empty bro" << endl;
  36.     }
  37.     else if (list3.isEmpty() == false)
  38.     cout << "This List is not Empty bro" << endl;
  39.     list4.removeAll();
  40.     list4.isEmpty();
  41.     if (list4.isEmpty() == true) // check if list4 that had an element was removed and see if the list is empty
  42.     {
  43.         cout << "This List is Empty bro" << endl;
  44.     }
  45.     else if (list4.isEmpty() == false)
  46.     cout << "This List is not Empty bro" << endl;
  47.    
  48.     // count tests
  49.  
  50.     list1.getCount();
  51.     cout <<list1.getCount() << endl; // with no elements
  52.     list2.getCount();
  53.     cout << list2.getCount() << endl; // with one element
  54.     list3.getCount();
  55.     cout <<  list3.getCount() << endl; // with more then one element
  56.     list3.removeAll(); // with more then one element erased then counted
  57.     list3.getCount();
  58.     cout << list3.getCount() << endl;
  59.    
  60.  
  61.     // contain tests
  62.     list1.contains(1);
  63.     if (list1.contains(1) == true)
  64.         cout << "The list does not contains an element" << endl;
  65.     else if (list1.contains(1) == false)
  66.         cout << "The list does not contain an element" << endl;
  67.     list2.contains(10);
  68.     if (list2.contains(10) == true)
  69.         cout <<"This list does contain this element"<< endl;
  70.     else if (list2.contains(10) == false)
  71.         cout << "This list does not contain this element" << endl;
  72.  
  73.  // Tests for head, tail neither its head nor tail elements
  74.     list3.insert(20);  // reinserting values back into list3 after removing them in previous test
  75.     list3.insert(30);
  76.     list3.insert(40);
  77.    
  78.     list3.contains(20);
  79.     if (list3.contains(20) == true)
  80.         cout << "List3 contains its head element" << endl;
  81.     else if (list3.contains(20) == false)
  82.         cout << "List3 does not contain its head element" << endl;
  83.     list3.contains(40);
  84.     if (list3.contains(40) == true)
  85.             cout <<"List3 contains its tail element" << endl;
  86.     else if (list3.contains(40) == false)
  87.             cout <<"List3 does not contain its tail element" << endl;
  88.     list3.contains(30);
  89.     if (list3.contains(30) == true)
  90.             cout << "List3 contains an element that is neither head nor tail " << endl;
  91.     else if (list3.contains(30) == false)
  92.             cout << "List3 does not contains an element that is neither head nor tail "  << endl;
  93.  
  94.     // find tests done in list 3 and list1
  95.  
  96.     list1.find(1);
  97.         cout << list1.find(1) << endl;
  98.     list3.find(10);
  99.         cout << list3.find(10) << endl;
  100.     list3.find(20);
  101.         cout << list3.find(20) << endl;
  102.     list3.find(40);
  103.         cout << list3.find(40) << endl;
  104.     list3.find(30);
  105.         cout << list3.find(30) << endl;
  106.  
  107.         // be aware that the value of NOT_IN_LIST = 4294967295
  108.  
  109.     // testing the remove function with list3 and list2
  110.  
  111.         list2.removeByIndex(0);
  112.         list2.isEmpty();
  113.         if (list2.isEmpty() == true)
  114.         cout <<"list2 was successfully removed and is now empty" << endl; // checks if it was successfully removed
  115.         else if (list2.isEmpty() == false)
  116.         cout <<"list2 was not successfully removed and still contains an element" << endl;
  117.         list3.removeByIndex(0);
  118.         list3.find(30);
  119.         cout << list3.find(30) << endl; // successfully set 30 to the head when head was removed
  120.         // now 30 is head and 40 is the tail
  121.         // test to see remove 40 (tail) and find 40
  122.         list3.removeByIndex(1);
  123.         list3.find(40);
  124.         cout << list3.find(40) << endl; // sucessful list3.find(40) returned NOT_IN_LIST!
  125.         // now removing the last element 30
  126.         list3.removeByIndex(0);
  127.         list3.isEmpty(); // checking now if list3 is empty
  128.         if (list3.isEmpty() == true)
  129.         cout <<"List3 is empty " << endl;
  130.         else if (list3.isEmpty() == false)
  131.         cout <<"List3 is not empty" << endl;
  132.     list3.insert(20);  // reinserting values back into list3 after removing them in previous test
  133.     list3.insert(30);
  134.     list3.insert(40);
  135.     list1.~LinkedList();
  136.     list2.~LinkedList();
  137.     list3.~LinkedList();
  138.     if (list3.isEmpty() == true)
  139.         cout <<"List3 is empty " << endl;
  140.         else if (list3.isEmpty() == false) // checking if the destructor properly emptied list3
  141.         cout <<"List3 is not empty" << endl;
  142.  
  143.  
  144.     return 0;
  145.  
  146. }
  147. #endif
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top