// CONCATENATE TWO EMPTY LISTS
TEST_F(LListIntTest, ConcatenationEmptyNominal){
	LListInt newList;
	LListInt finalList;
	list.clear();
	finalList = list + newList;

	EXPECT_EQ(finalList.size(), 0);
}
// ASSIGNMENT OPERATOR (COPY) WITH EMPTY LIST ONTO UNINITIALIZED LIST
TEST_F(LListIntTest, AssignmentEmptyNominal){
	LListInt newList;
	list.clear();

	newList = list;

	EXPECT_EQ(newList.size(), 0);

}
Beispiel #3
0
 /**
  * Copy constructor (deep copy)
  */
 LListInt::LListInt(const LListInt& other){
   head_ = NULL;
   tail_ = NULL;
   size_ = 0;
   int s = other.size();
   for (int i = 0; i < s; ++i){
     this->insert(i,other.get(i));
   }
 }
// ASSIGNMENT OPERATOR (COPY) WITH NONEMPTY LIST ONTO UNINITIALIZED LIST
TEST_F(LListIntTest, AssignmentNominal){
	LListInt newList;

	newList = list;

	EXPECT_EQ(newList.size(), list.size());

	for(int i=0; i<newList.size(); i++)
		EXPECT_EQ(newList[i], list[i]);
}
/**
* Concatenation Operator (other should be appended to the end of this)
*/
LListInt LListInt::operator+(const LListInt& other) const{

	LListInt temp = *this; // new temporary LinkedList that will be returned

	for(int i = 0; i < other.size(); i++){
		
		temp.insert(i + this->size(), other.get(i)); // inserting to the end of the object on the left hand side
	}

	return temp;
}
/**
* Copy constructor (deep copy)
*/
LListInt::LListInt(const LListInt& other){

	head_ = NULL;
	tail_ = NULL; // constructing the object that is copying
	
	size_ = 0;

	for(int i = 0; i < other.size(); i++){
		this->insert(i, other.get(i));
	}

}
TEST_F(llisttest, addNominal) {

	LListInt add;

	for(int i = 5; i < 10; i++){
		add.insert(i-5, i);
	}

	list = list + add;

	for (int i = 0 ; i < 10; i++) {
		EXPECT_EQ(list.get(i), i);
	}
}
Beispiel #8
0
 /**
  * Concatenation Operator (other should be appended to the end of this)
  */
 LListInt LListInt::operator+(const LListInt& other) const{
   LListInt sum(*this);
   for(int i = 0; i < other.size_; ++i){
     sum.insert(sum.size_, other.get(i));
   }
   return sum;
 }
TEST_F(llisttest, assignNominal) {

	LListInt assign;

	for(int i = 0; i < 5; i++){
		assign.insert(i, i+1);
	}

	for(int i = 0; i < 5; i++){
		EXPECT_EQ(assign.get(i), i+1);
	}

	assign = list;

	for (int i = 0 ; i < 5; i++) {
		EXPECT_EQ(assign.get(i), i);
	}
}
// CONCATENATE TWO NONEMPTY LISTS
TEST_F(LListIntTest, ConcatenationENominal){
	LListInt newList;
	LListInt finalList;
	newList.insert(0, 3);
	newList.insert(1, 4);
	newList.insert(2, 5);
	finalList = list + newList;

	EXPECT_EQ(finalList.size(), list.size() + newList.size());

	for(int i=0; i<list.size(); i++)
		EXPECT_EQ(finalList[i], list[i]);

	for(int i=0; i<newList.size(); i++)
		EXPECT_EQ(finalList[i+list.size()], newList[i]);
}
Beispiel #11
0
/**
 * Copy constructor (deep copy)
 */
LListInt::LListInt(const LListInt& other)
{
    head_ = NULL; //set base values for each
    tail_ = NULL;
    size_ = 0;
    
    if(!other.empty()) //if other is not a null list
    {
        if(other.size_ == 1) //other is size 1
        {
            Item* temp = new Item;
            temp->val = other.head_->val;
            temp->prev = NULL, temp->next = NULL;
            head_ = temp; tail_ = temp;
            size_++;
        }
        
        else
        {
            head_ = new Item;
            head_->next = NULL; head_->prev = NULL;
            head_->val = other.head_->val; //new head is equal to other head
            size_++;
        
            Item *pItem = head_; //previous THIS item
            Item *tItem = head_->next; //tItem is THIS item
            Item *oItem = other.head_->next; //oItem is next item in other
            while(oItem != NULL) //runs until last item in other
            {
                tItem = new Item; //creates a new THIS Item
                tItem->next = NULL; tItem->prev = pItem; pItem->next = tItem;
                tItem->val = oItem->val;
                pItem = tItem;
                tItem = tItem->next;
                oItem = oItem->next;
                size_++;
            }
            tail_ = pItem; //tail sets to last val in this
        }
    }
}
Beispiel #12
0
/**
 * Concatenation Operator (other should be appended to the end of this)
 */
LListInt LListInt::operator+(const LListInt& other) const
{
    LListInt *newLL = new LListInt; //create new LL
    bool tEmpty = empty(), oEmpty = other.empty();
    
    if(tEmpty && oEmpty) //both are empty LL
        return *newLL;
    
    else if (!tEmpty && oEmpty) //other is empty LL
        *newLL = LListInt(*this);
    
    else if(tEmpty && !oEmpty) //this is empty LL
        *newLL = LListInt(other);
    
    else //neither are empty LL
    {
        *newLL = LListInt(*this); //first copy this into newLL
        
        newLL->size_ += other.size_;
        Item *pItem = newLL->tail_; //Previous item
        Item *tItem = newLL->tail_->next; //Last item in this
        Item *oItem = other.head_; //first item in other
        while(oItem != NULL) //loops until last item in other
        {
            tItem = new Item; //creates a new Item in this
            tItem->next = NULL; tItem->prev = pItem; pItem->next = tItem;
            tItem->val = oItem->val;
            pItem = tItem;
            tItem = tItem->next;
            oItem = oItem->next;
            ++newLL->size_;
        }
    }
    
    return *newLL;
}
Beispiel #13
0
int main() {
  LListInt * list = new LListInt();

  // Check if the list is initially empty.
  if (list->empty()) {
    cout << "SUCCESS: List is empty initially." << endl;
  } else {
    cout << "FAIL: List is not empty initially when it should be." << endl;
  }

  // Calls to insert function
  list->insert(0, 88);
  
  list->insert(1, 3);
  
  list->insert(2, 14);
  
  list->insert(1, 5);
  list->insert(4, 28);
  list->insert(-3, 31);
  //current list is: 88 5 3 14 28


  // Check if the list is still empty.
  if (!list->empty()) {
    cout << "SUCCESS: List is not empty after 5 insertions." << endl;
  } else {
    cout << "FAIL: List is empty after 5 insertions." << endl;
  }
  // Check if there are 5 items in the list.
  if (list->size() == 5) {
    cout << "SUCCESS: List has size 5 after the insertions." << endl;
  } else {
    cout << "FAIL: List has size " << list->size() << " after 5 insertions." << endl;
  }

  // Check if the value is correct.
  if (list->get(0) == 88) {
    cout << "SUCCESS: 88 is at the 1st index of the list." << endl;
  } else {
    cout << "FAIL: 88 is not at the 1st index of the list, " << list->get(1) << " is instead." << endl;
  }

  list->remove(2);
  // Check if the value is correct.
  if (list->get(2) == 14) {
    cout << "SUCCESS: 14 is at the 2nd index of the list, remove function worked" << endl;
  } else {
    cout << "FAIL: 14 is not at the 2nd index of the list, " << list->get(2) << " is instead." << endl;
  }


  // Clean up memory.
  delete list;
}
Beispiel #14
0
int main() {
	LListInt * list = new LListInt();
 	list->insert(0, 3);
  	//insert an item to the empty list. 

  	if (list->size() == 1) {
    	cout << "SUCCESS: List has size 1 after one insertion." << endl;
  	} 
  	else {
    	cout << "FAIL: List has size " << list->size() << " after one insertion.";
    	cout << endl;
  	}

	if (list->get(0) == 3) {
    	cout << "SUCCESS: 3 is at the 0th index of the list." << endl;
  	} 
  	else {
    	cout << "FAIL: 3 is not at the 0th index of the list, " << list->get(0);
    	cout << " is instead." << endl;
  	}

  	list->insert(1,4);
  	//insert an item at the valid location SIZE
  	//the tail will be changed and the size would be changed to 2
  	if (list->size() == 2) {
    	cout << "SUCCESS: List has size 2 after one insertion." << endl;
  	} 
  	else {
    	cout << "FAIL: List has size " << list->size() << " after one insertion.";
    	cout << endl;
  	}
  	//the second item will have the value 2;
  	if (list->get(1) == 4) {
    	cout << "SUCCESS: 4 is at the 1st index of the list." << endl;
  	} 
  	else {
    	cout << "FAIL: 4 is not at the 1st index of the list, " << list->get(1);
    	cout << " is instead." << endl;
  	}

  	list->insert(1,5);
  	//add one item at the location between 0 to Size-1
  	if(list->size() == 3){
  		cout << "SUCCESS: List has size 3 after one insertion." << endl;
  	} 
  	else {
    	cout << "FAIL: List has size " << list->size() << " after one insertion.";
    	cout << endl;
  	}

  	if (list->get(1) == 5) {
    	cout << "SUCCESS: 5 is at the 1st index of the list." << endl;
  	} 
  	else {
    	cout << "FAIL: 5 is not at the 1st index of the list, " << list->get(1);
    	cout << " is instead." << endl;
  	}
  	//5 should be the new value of the 1st index
  	if (list->get(2) == 4) {
    	cout << "SUCCESS: 4 is at the 2nd index of the list." << endl;
  	} 
  	else {
    	cout << "FAIL: 4 is not at the 2nd index of the list, " << list->get(2);
    	cout << " is instead." << endl;
  	}
  	//4 would be pushed to the next position at the 2nd.
	//the substitution is successful.

	list->insert(5,4);
	list->insert(-2,4);
	//insert an item to the array at the location out of valid range
	if(list->size() == 3){
  		cout << "SUCCESS: List has size 3 after two insertion." << endl;
  	} 
  	else {
    	cout << "FAIL: List has size " << list->size() << " after one insertion.";
    	cout << endl;
  	}

	list->remove(1);
	//delete the item in location 1 in the valid range
	if(list->size() == 2){
  		cout << "SUCCESS: List has size 2 after one remove." << endl;
  	} 
  	else {
    	cout << "FAIL: List has size " << list->size() << " after one insertion.";
    	cout << endl;
  	}
  	//the size should be 2 now.

	if (list->get(1) == 4) {
    	cout << "SUCCESS: 4 is at the 1st index of the list." << endl;
  	} 
  	else {
    	cout << "FAIL: 4 is not at the 1st index of the list, " << list->get(1);
    	cout << " is instead." << endl;
  	}
  	//the item with value 4 will substitute the value at location 1 before

  	list->remove(4);
  	list->remove(-2);
  	//delete the item at the location out of the valid range
  	if(list->size() == 2){
  		cout << "SUCCESS: List has size 2 after one remove." << endl;
  	} 
  	else {
    	cout << "FAIL: List has size " << list->size() << " after one insertion.";
    	cout << endl;
  	}
  	//the size should keep 2 now.

  	list->insert(2,5);
  	//insert item with value 5 to the list.
  	list->remove(2);
  	//remove the last item(boundary)
  	if(list->size() == 2){
  		cout << "SUCCESS: List has size 2 after one remove." << endl;
  	} 
  	else {
    	cout << "FAIL: List has size " << list->size() << " after one insertion.";
    	cout << endl;
  	}
  	//the last item is removed and the size will become 2
  	if (list->get(1) == 4) {
    	cout << "SUCCESS: 4 is at the 1st index of the list." << endl;
  	} 
  	else {
    	cout << "FAIL: 4 is not at the 1st index of the list, " << list->get(1);
    	cout << " is instead." << endl;
  	}

  	list->insert(2,5);
  	list->remove(0);
  	//remove the first boundary item
  	//the rest items should move left by one spot
  	if(list->size() == 2){
  		cout << "SUCCESS: List has size 2 after one remove." << endl;
  	} 
  	else {
    	cout << "FAIL: List has size " << list->size() << " after one insertion.";
    	cout << endl;
  	}
  	//the first item is removed and the size will become 2
  	if (list->get(1) == 5) {
    	cout << "SUCCESS: 5 is at the 1st index of the list." << endl;
  	} 
  	else {
    	cout << "FAIL: 5 is not at the 1st index of the list, " << list->get(1);
    	cout << " is instead." << endl;
  	}
  	list->clear();
  	if(list->size() == 0){
  		cout << "SUCCESS: List has size 0 after one clear." << endl;
  	} 
  	else {
    	cout << "FAIL: List has size " << list->size() << " after one insertion.";
    	cout << endl;
  	}
  	list->remove(0);
  	if(list->size() == 0){
  		cout << "SUCCESS: List has size 0 after one clear." << endl;
  	} 
  	else {
    	cout << "FAIL: List has size " << list->size() << " after one insertion.";
    	cout << endl;
  	}
  	delete list;
  	return 0;
}
int main(){
	LListInt* list = new LListInt();

	cout << "BEGINNING 15 TEST CASES..." << endl;

	// We can assume that the following will work if and only if get(), size() and empty() work
	// get() and set() will throw a core dump if given bad location

	// NOMINAL
	// 1. Check if the list is initially empty.
	if (list->empty()) cout << "SUCCESS: (1) List is empty initially." << endl;
	else cout << "FAIL: (1) List is not empty initially when it should be." << endl;

	// OFFNOMINAL
	// 2. Check: insert into empty list with bad location
	list->insert(1, 5);
	if(list->empty()) cout << "SUCCESS: (2) List is still empty." << endl;
	else cout << "FAIL: (2) List now has " << list->size() << " element(s)" << endl;

	// NOMINAL
	// 3. Check: insert into empty list with loc = 0
	list->insert(0,5); // 5
	if(list->size()==1){
		if(list->get(0)==5) cout << "SUCCESS";
		else cout << "FAIL";
		string temp = printlist(list);
		cout << ": (3) list is " << temp << endl;

	}
	else cout << "FAIL: (3) list has size " << list->size() << " instead of 1" << endl;

	// BOUNDARY
	// 4. Check: insert element to end of list. (loc == size)
	list->insert(1,8); // 5, 8
	if(list->size()==2){
		if(list->get(0)==5 && list->get(1)==8) cout << "SUCCESS";
		else cout << "FAIL";
		string temp = printlist(list);
		cout << ": (4) list is " << temp << endl;
	}
	else cout << "FAIL: (4) list has size " << list->size() << " instead of 2" << endl;

	// BOUNDARY
	// 5. Check: insert element to front of list
	list->insert(0,2); // 2, 5, 8
	if(list->size()==3){
		if(list->get(0)==2 && list->get(1)==5 && list->get(2)==8) cout << "SUCCESS";
		else cout << "FAIL";
		string temp = printlist(list);
		cout << ": (5) list is " << temp << endl;
	}
	else cout << "FAIL: (5) list has size " << list->size() << " instead of 3" << endl;

	// NOMINAL
	// 6. Check: insert element to middle of list
	list->insert(2,3); // 2, 5, 3, 8
	if(list->size()==4){
		if(list->get(0)==2 && list->get(1)==5 && list->get(2)==3 && list->get(3)==8)
			cout << "SUCCESS";
		else cout << "FAIL";
		string temp = printlist(list);
		cout << ": (6) list is " << temp << endl;
	}
	else cout << "FAIL: (6) list has size " << list->size() << " instead of 4" << endl;

	// OFFNOMINAL
	// 7. Check: insert element in bad location
	list->insert(5,0); // 2, 5, 3, 8
	if(list->size()==4){
		if(list->get(0)==2 && list->get(1)==5 && list->get(2)==3 && list->get(3)==8)
			cout << "SUCCESS";
		else cout << "FAIL";
		string temp = printlist(list);
		cout << ": (7) list is " << temp << endl;
	}
	else if(list->size()==5) 
		cout << "FAIL: (7) the 5th element " << list->get(5) << " was incorrectly inserted" << endl;
	else cout << "FAIL: (7) list has size " << list->size() << " instead of 4" << endl;

	// OFFNOMINAL
	// 8. Check: remove element from loc == size (bad location)
	list->remove(4);
	if(list->size()==4){
		if(list->get(0)==2 && list->get(1)==5 && list->get(2)==3 && list->get(3)==8)
			cout << "SUCCESS";
		else cout << "FAIL";
		string temp = printlist(list);
		cout << ": (8) list is " << temp << endl;
	}
	else cout << "FAIL: (8) list has size " << list->size() << " instead of 4" << endl;

	// OFFNOMINAL
	// 9. Check: remove element from loc > size (bad location)
	list->remove(5);
	if(list->size()==4){
		if(list->get(0)==2 && list->get(1)==5 && list->get(2)==3 && list->get(3)==8)
			cout << "SUCCESS";
		else cout << "FAIL";
		string temp = printlist(list);
		cout << ": (9) list is " << temp << endl;
	}
	else cout << "FAIL: (9) list has size " << list->size() << " instead of 4" << endl;

	// BOUNDARY
	// 10. Check: remove element from end of list
	list->remove(3); // 2, 5, 3
	if(list->size()==3){
		if(list->get(0)==2 && list->get(1)==5 && list->get(2)==3)
			cout << "SUCCESS";
		else cout << "FAIL";
		string temp = printlist(list);
		cout << ": (10) list is " << temp << endl;
	}
	else cout << "FAIL: (10) list has size " << list->size() << " instead of 3" << endl;

	// BOUNDARY
	// 11. Check: removing from beginning of list
	list->remove(0); // 5, 3
	if(list->size()==2){
		if(list->get(0)==5 && list->get(1)==3)
			cout << "SUCCESS";
		else cout << "FAIL";
		string temp = printlist(list);
		cout << ": (11) list is " << temp << endl;
	}
	else cout << "FAIL: (11) list has size " << list->size() << " instead of 2" << endl;

	// NOMINAL
	// 12. Check: removing from middle of list
	list->insert(1,9); // 5, 9, 3
	list->remove(1); // 5, 3
	if(list->size()==2){
		if(list->get(0)==5 && list->get(1)==3)
			cout << "SUCCESS";
		else cout << "FAIL";
		string temp = printlist(list);
		cout << ": (12) list is " << temp << endl;
	}
	else cout << "FAIL: (12) list has size " << list->size() << " instead of 2" << endl;

	// 13. Check: setting
	list->set(0, 3); // 3, 3
	list->set(1, 5); // 3, 5
	if(list->size()==2){
		if(list->get(1)==5 && list->get(0)==3)
			cout << "SUCCESS";
		else cout << "FAIL";
		string temp = printlist(list);
		cout << ": (13) list is " << temp << endl;
	}
	else cout << "FAIL: (13) list has size " << list->size() << " instead of 2" << endl;

	// NOMINAL
	// 14. Check: clear
	list->clear();
	string temp = printlist(list);
	if (list->empty()) cout << "SUCCESS: (14) List is emptied." << endl;
	else cout << "FAIL: (14) List is not empty: " << temp << endl;

	//OFFNOMINAL
	// 15. Check: remove
	list->remove(0);
	temp = printlist(list);
	if (list->empty()) cout << "SUCCESS: (15) List is empty and ok." << endl;
	else cout << "FAIL: (15) List is not empty: " << temp << endl;

	cout << "ALL TESTS ARE COMPLETE. NOW DELETING LIST." << endl;

	delete list;

	return 0;

}
int main() {
  LListInt * list = new LListInt();

  // Check if the list is initially empty.
  if (list->empty()) {
    cout << "SUCCESS: List is empty initially." << endl;
  } else {
    cout << "FAIL: List is not empty initially when it should be." << endl;
  }

  // Remove an item from an empty list
  //list->remove(0);

  // Insert an item from invalid location
  //list->insert(-1, 1);
  //list->insert(3, 3);

  // Insert an item at the head.
  list->insert(0, 3);

  // Check if the list is still empty.
  if (!list->empty()) {
    cout << "SUCCESS: List is not empty after one insertion." << endl;
  } else {
    cout << "FAIL: List is empty after one insertion." << endl;
  }

  if (list->size() == 1) {
    cout << "SUCCESS: List has size 1 after one insertion." << endl;
  } else {
    cout << "FAIL: List has size " << list->size() << " after one insertion.";
    cout << endl;
  }


  // Insert an item from invalid location
  //list->insert(3, 3);

  // Insert an item to the end of an existing list
  list->insert(1, 2);
  list->insert(2, 1);

  if (list->size() == 3) {
    cout << "SUCCESS: List has size 3 after three insertion." << endl;
  } else {
    cout << "FAIL: List has size " << list->size() << " after three insertion.";
    cout << endl;
  }

  // Check if the value is correct.
  if (list->get(0) == 3) {
    cout << "SUCCESS: 3 is at the 0th index of the list." << endl;
  } else {
    cout << "FAIL: 3 is not at the 0th index of the list, " << list->get(0);
    cout << " is instead." << endl;
  }

  // Check if the value is correct.
  if (list->get(1) == 2) {
    cout << "SUCCESS: 2 is at the 1st index of the list." << endl;
  } else {
    cout << "FAIL: 2 is not at the 1st index of the list, " << list->get(2);
    cout << " is instead." << endl;
  }

  // Check if the value is correct.
  if (list->get(2) == 1) {
    cout << "SUCCESS: 1 is at the 2nd index of the list." << endl;
  } else {
    cout << "FAIL: 1 is not at the 2nd index of the list, " << list->get(2);
    cout << " is instead." << endl;
  }

  // Insert an item into middle of an existing list
  list->insert(1, 3);
  list->insert(0, 10);

  if (list->size() == 5) {
    cout << "SUCCESS: List has size 5 after five insertion." << endl;
  } else {
    cout << "FAIL: List has size " << list->size() << " after five insertion.";
    cout << endl;
  }

  // Check if the value is correct.
  if (list->get(0) == 10) {
    cout << "SUCCESS: 10 is at the 0th index of the list." << endl;
  } else {
    cout << "FAIL: 10 is not at the 0th index of the list, " << list->get(0);
    cout << " is instead." << endl;
  }

  // Check if the value is correct.
  if (list->get(1) == 3) {
    cout << "SUCCESS: 3 is at the 1st index of the list." << endl;
  } else {
    cout << "FAIL: 3 is not at the 1st index of the list, " << list->get(1);
    cout << " is instead." << endl;
  }

  // Check if the value is correct.
  if (list->get(2) == 3) {
    cout << "SUCCESS: 3 is at the 2nd index of the list." << endl;
  } else {
    cout << "FAIL: 3 is not at the 2nd index of the list, " << list->get(2);
    cout << " is instead." << endl;
  }


  // Remove item from invalid location
  //list->remove(-1);
  //list->remove(6);

  // Remove item from ends of the list
  list->remove(0);
  list->remove(3);

  if (list->size() == 3) {
    cout << "SUCCESS: List has size 3 after two removals." << endl;
  } else {
    cout << "FAIL: List has size " << list->size() << " after two removals.";
    cout << endl;
  }

  // Check if the value is correct.
  if (list->get(0) == 3) {
    cout << "SUCCESS: 3 is at the 0th index of the list." << endl;
  } else {
    cout << "FAIL: 3 is not at the 0th index of the list, " << list->get(0);
    cout << " is instead." << endl;
  }

  // Check if the value is correct.
  if (list->get(2) == 2) {
    cout << "SUCCESS: 2 is at the 3rd index of the list." << endl;
  } else {
    cout << "FAIL: 2 is not at the 3rd index of the list, " << list->get(2);
    cout << " is instead." << endl;
  }

  // Remove item from middle of an array
  list->remove(1); 

  if (list->size() == 2) {
    cout << "SUCCESS: List has size 2 after three removals." << endl;
  } else {
    cout << "FAIL: List has size " << list->size() << " after three removals.";
    cout << endl;
  }

  // Check if the value is correct.
  if (list->get(1) == 2) {
    cout << "SUCCESS: 2 is at the 1st index of the list." << endl;
  } else {
    cout << "FAIL: 2 is not at the 1st index of the list, " << list->get(1);
    cout << " is instead." << endl;
  }  

  // Clean list
  list->clear();

  if (list->empty()) {
    cout << "SUCCESS: List is empty after clear()." << endl;
  } else {
    cout << "FAIL: List is not empty after clear() when it should be." << endl;
  }


  // Clean up memory.
  delete list;
}
int main() {
  LListInt * list = new LListInt();

  // Check if the list is initially empty.
  if (list->empty()) {
    cout << "SUCCESS: List is empty initially." << endl;
  } else {
    cout << "FAIL: List is not empty initially when it should be." << endl;
  }

  // Test -> Insert an item at the head
  list->insert(0, 3);

  // Check if the list is still empty
  if (!list->empty()) {
    cout << "SUCCESS: List is not empty after one insertion." << endl;
  } else {
    cout << "FAIL: List is empty after one insertion." << endl;
  }

  // Check if the size
  if (list->size() == 1) {
    cout << "SUCCESS: List has size 1 after one insertion." << endl;
  } else {
    cout << "FAIL: List has size " << list->size() << " after one insertion.";
    cout << endl;
  }

  // Check if the value is correct.
  if (list->get(0) == 3) {
    cout << "SUCCESS: 3 is at the 0th index of the list." << endl;
  } else {
    cout << "FAIL: 3 is not at the 0th index of the list, " << list->get(0);
    cout << " is instead." << endl;
  }

  // Test -> Insert an item at the beginning
  list->insert(0, 2);

  if (list->get(0) == 2) {
    cout << "SUCCESS: 2 is at the 0th index of the list." << endl;
  } else {
    cout << "FAIL: 2 is not at the 0th index of the list, " << list->get(0);
    cout << " is instead." << endl;
  }

  // Test -> Insert an item at the end
  list->insert(2, 5);

  if (list->get(2) == 5) {
    cout << "SUCCESS: 5 is at the 2th index of the list." << endl;
  } else {
    cout << "FAIL: 5 is not at the 2th index of the list, " << list->get(0);
    cout << " is instead." << endl;
  }

  // Test -> Insert item in the middle 
  list->insert(2, 4);

  if (list->get(2) == 4) {
    cout << "SUCCESS: 4 is at the 2th index of the list." << endl;
  } else {
    cout << "FAIL: 4 is not at the 2th index of the list, " << list->get(0);
    cout << " is instead." << endl;
  }

  // Test -> inserting at a wrong location
  list->insert(5, 0);

  // Clean up memory.
  delete list;
}
int main() {

  LListInt * list = new LListInt();

  if (list->empty()) {
    cout << "SUCCESS: List is empty initially." << endl;
  } else {
    cout << "FAIL: List is not empty initially when it should be." << endl;
  }
  
  // Testing insert function
  cout << "\nTesting insert function\n";
  list->insert(0,1);
  list->insert(1,5);
  list->insert(2,7);


  if (list->get(0) == 1 && list->get(1) == 5 && list->get(2) == 7) {
    cout << "SUCCESS: Elements 1, 5, 7 are successfully inserted to the list." << endl;
  } else {
    cout << "FAIL: Insertion failed." << endl;
  }

  cout << "DISPLAYING: List after insertion \n";
  for (int i=-0; i < list->size(); i++) {
    cout << list->get(i) << " ";
  }
  cout << endl << endl;
  
  //Inserting head
  list->insert(0,0);
  if (list->get(0) == 0) {
    cout << "SUCCESS: Inserting element from the front of the list" << endl;
  } else {
    cout << "FAIL: Failed to insert element from the front of the list." << endl;
  }

  cout << "DISPLAYING: List after inserting from the front of the list \n";
  for (int i=-0; i < list->size(); i++) {
    cout << list->get(i) << " ";
  }

  cout << endl << endl;

  //Inserting tail
  list->insert(list->size(),8);
  if (list->get(list->size()-1) == 8) {
  cout << "SUCCESS: Inserting element from the back of the list" << endl;
  } else {
    cout << "FAIL: Failed to insert element from the back of the list." << endl;
  }

  cout << "DISPLAYING: List after inserting from the back of the list\n";
  for (int i=-0; i < list->size(); i++) {
    cout << list->get(i) << " ";
  }
  cout << endl << endl;

  //Inserting elements in certain positions" << endl;
  
  list->insert(2,2);
  if (list->get(2) == 2) {
  cout << "SUCCESS: Inserting element on position 2 in the list" << endl;
  } else {
    cout << "FAIL: Failed to insert element on postion 2 in the list." << endl;
  }

  cout << "DISPLAYING: List after inserting element on position 2 in the list\n";
  for (int i=-0; i < list->size(); i++) {
    cout << list->get(i) << " ";
  }
  cout << endl << endl;

  //0 1 2 4 5 7 8

  list->insert(3,4);
  if (list->get(3) == 4) {
  cout << "SUCCESS: Inserting element on position 3 in the list" << endl;
  } else {
    cout << "FAIL: Failed to insert element on postion 3 in the list." << endl;
  }

  cout << "DISPLAYING: List after inserting element on position 3 in the list\n";
  for (int i=-0; i < list->size(); i++) {
    cout << list->get(i) << " ";
  }
  cout << endl<< endl;

  //0 1 2 4 5 6 7 8

  list->insert(5,6);
  if (list->get(5) == 6) {
  cout << "SUCCESS: Inserting element on position 5 in the list" << endl;
  } else {
    cout << "FAIL: Failed to insert element on postion 5 in the list." << endl;
  }

  cout << "DISPLAYING: List after inserting element on position 5 in the list\n";
  for (int i=-0; i < list->size(); i++) {
    cout << list->get(i) << " ";
  }
  cout << endl << endl;

  //0 1 2 3 4 5 6 7 8
  list->insert(3,3);
  if (list->get(3) == 3) {
  cout << "SUCCESS: Inserting element on position 3 in the list" << endl;
  } else {
    cout << "FAIL: Failed to insert element on postion 3 in the list." << endl;
  }

  cout << "DISPLAYING: List after inserting element on position 3 in the list\n";
  for (int i=-0; i < list->size(); i++) {
    cout << list->get(i) << " ";
  }
  cout << endl << endl;
  int x = list->size();

  //Testing invalid location insertion
  list->insert(-1,5);
  list->insert(10,9);

  if (list->size() == x) {
  cout << "SUCCESS: Invalid insertion did not alter the list." << endl;
  } else {
    cout << "FAIL: Invalid insertion altered the list." << endl;
  }

   cout << "DISPLAYING: List after attempting to insert in invalid position of the list\n";
  for (int i=-0; i < list->size(); i++) {
    cout << list->get(i) << " ";
  }

  cout << "\n\nTesting remove function \n";

  //"Removing head\n";
  list->remove(0);
  if (list->get(0) == 1) {
    cout << "SUCCESS: Removing element from the front of the list" << endl;
  } else {
    cout << "FAIL: Failed to remove element from the front of the list." << endl;
  }

  cout << "DISPLAYING: List after removing element from the front of the list \n";
  for (int i=-0; i < list->size(); i++) {
    cout << list->get(i) << " ";
  }
  cout << endl << endl;

  //Removing tail
  list->remove(list->size() - 1);
  if (list->get(list->size()-1) == 7) {
    cout << "SUCCESS: Removing element from the back of the list" << endl;
  } else {
    cout << "FAIL: Failed to remove element from the back of the list." << endl;
  }

  cout << "DISPLAYING: List after removing element from the back of the list \n";
  for (int i=-0; i < list->size(); i++) {
    cout << list->get(i) << " ";
  }
  cout << endl << endl;

  //1 2 3 4 5 6 7
  //Removing elements in certain positions\n";
  list->remove(2); //remove 3
  if(list->get(2) == 3) {
  cout << "SUCCESS: Removing element on position 2 in the list" << endl;
  } else {
    cout << "FAIL: Failed to remove element on postion 2 in the list." << endl;
  }

  cout << "DISPLAYING: List after removing element on position 2 in the list\n";
  for (int i=-0; i < list->size(); i++) {
    cout << list->get(i) << " ";
  }
  cout << endl << endl;

  // 1 2 4 5 6 7
  list->remove(4); //remove 6
  if(list->get(4) == 7) {
  cout << "SUCCESS: Removing element on position 4 in the list" << endl;
  } else {
    cout << "FAIL: Failed to remove element on postion 4 in the list." << endl;
  }

  cout << "DISPLAYING: List after removing element on position 4 in the list\n";
  for (int i=-0; i < list->size(); i++) {
    cout << list->get(i) << " ";
  }
  cout << endl << endl;

  //1 2 4 5 7
  list->remove(1); //remove 2
  if (list->get(1) == 4) {
  cout << "SUCCESS: Removing element on position 1 in the list" << endl;
  } else {
    cout << "FAIL: Failed to remove element on postion 1 in the list." << endl;
  }

  cout << "DISPLAYING: List after removing element on position 1 in the list\n";
  for (int i=-0; i < list->size(); i++) {
    cout << list->get(i) << " ";
  }
  cout << endl << endl;

  // 1 4 5 7
  //Testing invalid location for removal
  list->remove(-1);
  list->remove(4);

  x = list->size();

  if (list->size() == x) {
  cout << "SUCCESS: Invalid removal did not alter the list." << endl;
  } else {
    cout << "FAIL: Invalid removal altered the list." << endl;
  }

  cout << "DISPLAYING: List after attempting to remove element in invalid position of the list\n";
  for (int i=-0; i < list->size(); i++) {
    cout << list->get(i) << " ";
  }
  cout << endl << endl;

  //Removing the rest of the element in the list

  for (int i=0; i<x; i++) {
    list->remove(0);
  }

  if (list->size() == 0) {
  cout << "SUCCESS: Removing the rest of the elements from the list" << endl;
  } else {
    cout << "FAIL: The list is not empty" << endl;
  }

  cout << "DISPLAYING: The list after removing \n";
  for (int i=0; i < list->size(); i++) {
    cout << list->get(i) << " ";
  }
  cout << endl;

  if (list->empty()) {
    cout << "SUCCESS: List is now empty." << endl;
  } else {
    cout << "FAIL: List is not empty." << endl;
  }

  // Clean up memory.
  delete list;
  list = NULL;

}