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 testNodes(ostream & os){ printSubheader("NODES",os); LinkedList<string> ll; TESTM(ll.GetFirst()==NULL,"ll first should be null"); TESTM(ll.GetLast()==NULL,"ll last should be null"); ll.Insert("Buh!",NULL); TESTM(ll.GetFirst()->GetValue().compare("Buh!")==0,"Expected: Buh!\nActual: " + ll.GetFirst()->GetValue()); TESTM(ll.GetLast()->GetValue().compare("Buh!")==0,"Expected: Buh!\nActual: " + ll.GetLast()->GetValue()); ll.Insert("Muh!",NULL); TESTM(ll.GetLast()->GetValue().compare("Buh!")==0,"Expected: Buh!\nActual: " + ll.GetLast()->GetValue()); TESTM(ll.GetFirst()->GetValue().compare("Muh!")==0,"Expected: Muh!\nActual: " + ll.GetFirst()->GetValue()); LLNode<string>* buh = ll.GetLast(); TESTM(buh->GetNext() == NULL,"Expected: NULL\nActual: " + buh->GetNext()->GetValue()); TESTM(buh->GetPrevious()->GetValue() == "Muh!","Expected: Muh!\nActual: " + buh->GetPrevious()->GetValue()); LLNode<string>* muh = ll.GetFirst(); TESTM(muh->GetNext()->GetValue() == "Buh!","Expected: Buh!\nActual: " + muh->GetNext()->GetValue()); TESTM(muh->GetPrevious() == NULL,"Expected: NULL\nActual: " + muh->GetPrevious()->GetValue()); //node comparisons LLNode<string>* node1 = ll.GetFirst();//Muh! LLNode<string>* node2 = ll.GetLast();//Buh! TESTM(node1->compare(*node2) > 0, "tested: " + node1->GetValue() + ".compare(" + node2->GetValue() + ")\nExpected positive\n"); TESTM(node2->compare(*node1) < 0, "tested: " + node2->GetValue() + ".compare(" + node1->GetValue() + ")\nExpected negative\n"); TESTM(node1->compare(*node1) == 0, "tested: " + node1->GetValue() + ".compare(" + node1->GetValue() + ")\nExpected zero\n"); }