void testRemove(ostream & os){ printSubheader("REMOVE",os); LinkedList<string> ll; ll.Insert("Muh!",NULL); ll.Insert("Buh!",NULL); ll.Insert("Juh!",NULL); LLNode<string>* node = ll.Find("Muh!",NULL); ll.Remove(node); node = ll.GetFirst(); TESTM(node->GetValue() == "Juh!","Expected: Juh!\nActual: " + node->GetValue()); TESTM(node->GetNext()->GetValue() == "Buh!","Expected: Buh!\nActual: " + node->GetNext()->GetValue()); }
void testFind(ostream & os){ printSubheader("FIND",os); LinkedList<string> ll; ll.Insert("Muh!",NULL); ll.Insert("Buh!",NULL); ll.Insert("Juh!",NULL); ll.Insert("Buh!",NULL); LLNode<string>* node; node = ll.Find("Buh!",NULL); TESTM(node->GetPrevious() == NULL,"Expected: NULL\nActual: " + node->GetPrevious()->GetValue()); TESTM(node->GetNext()->GetValue() == "Juh!","Expected: Juh!\nActual: " + node->GetNext()->GetValue()); TESTM(node->GetValue() == "Buh!","Expected: Buh!\nActual: " + node->GetValue()); LLNode<string>* node2 = ll.Find("Buh!",ll.GetFirst()); if(node2 == NULL) TESTM(node2->GetPrevious()->GetValue() == "Juh!","Expected: Juh!\nActual: " + node2->GetPrevious()->GetValue()); TESTM(node2->GetNext()->GetValue() == "Muh!","Expected: Muh!\nActual: " + node2->GetNext()->GetValue()); TESTM(node2->GetValue() == "Buh!","Expected: Buh!\nActual: " + node2->GetValue()); }
void testAddAll(ostream & os){ printSubheader("ADDALL",os); LinkedList<string> ll1; ll1.Insert("Muh!",NULL); ll1.Insert("Buh!",NULL); LinkedList<string> ll2; ll2.Insert("Juh!",NULL); ll2.Insert("Kuh!",NULL); ll1.addAll(&ll2); LLNode<string>* node = ll1.GetFirst(); TESTM(node->GetValue() == "Juh!","Expected: Juh!\nActual: " + node->GetValue()); node = node->GetNext(); TESTM(node->GetValue() == "Kuh!","Expected: Kuh!\nActual: " + node->GetValue()); node = node->GetNext(); TESTM(node->GetValue() == "Buh!","Expected: Buh!\nActual: " + node->GetValue()); node = node->GetNext(); TESTM(node->GetValue() == "Muh!","Expected: Muh!\nActual: " + node->GetValue()); node = node->GetNext(); TESTM(node == NULL,"Expected: NULL\nActual: " + node->GetValue()); }
void testConstructors(ostream & os){ printSubheader("CONSTRUCTORS",os); stringstream sizeStr; LinkedList<string> ll; ll.Insert("Muh!",NULL); ll.Insert("Buh!",NULL); ll.Insert("Juh!",NULL); //test copy constructor LinkedList<string> ll2(ll); LLNode<string>* node = ll2.GetFirst(); sizeStr << ll2.GetSize(); TESTM(ll2.GetSize() == 3,"Expected: 3\nActual: sizeStr\n"); TESTM(node->GetValue() == "Juh!","Expected: Juh!\nActual: " + node->GetValue()); node = node->GetNext(); TESTM(node->GetValue() == "Buh!","Expected: Buh!\nActual: " + node->GetValue()); node = node->GetNext(); TESTM(node->GetValue() == "Muh!","Expected: Muh!\nActual: " + node->GetValue()); node = node->GetNext(); TESTM(node == NULL,"Expected: NULL\nActual: " + node->GetValue()); //test operator= LinkedList<string> ll3 = ll2; node = ll3.GetFirst(); sizeStr << ll3.GetSize(); TESTM(ll3.GetSize() == 3,"Expected: 3\nActual: sizeStr\n"); TESTM(node->GetValue() == "Juh!","Expected: Juh!\nActual: " + node->GetValue()); node = node->GetNext(); TESTM(node->GetValue() == "Buh!","Expected: Buh!\nActual: " + node->GetValue()); node = node->GetNext(); TESTM(node->GetValue() == "Muh!","Expected: Muh!\nActual: " + node->GetValue()); node = node->GetNext(); TESTM(node == NULL,"Expected: NULL\nActual: " + node->GetValue()); }