public void TestRemoveNode5() { DLList list = new DLList(); DLLNode node1 = new DLLNode(5); //tail DLLNode node2 = new DLLNode(4); DLLNode node3 = new DLLNode(3); DLLNode node4 = new DLLNode(2); DLLNode node5 = new DLLNode(7); //head list.addToHead(node1); list.addToHead(node2); list.addToHead(node3); list.addToHead(node4); list.addToHead(node5); list.removeNode(node1); // there should only be 4 nodes left // value of 5 should not be present // head should be node 2 Assert.AreEqual(list.total(), 4); Assert.IsNull(list.search(5)); Assert.AreEqual(list.tail, node2); }
public void TestAddToHead2() { DLList myDLL = new DLList(); DLLNode p = new DLLNode(1); myDLL.addToHead(p); DLLNode q = new DLLNode(2); myDLL.addToHead(q); Assert.AreEqual(q, myDLL.head); //check that head node is q }
public void TestMethodAddToHead2() { DLLNode p = new DLLNode("1"); DLList dll = new DLList(); dll.addToHead(p); p = new DLLNode("2"); dll.addToHead(p); p = new DLLNode("3"); dll.addToHead(p); //Should be: Head = 3, head.next.str = 2, head.next.next.str = 1 Assert.AreEqual(true, (dll.head.str == "3" && dll.head.next.str == "2" && dll.head.next.next.str == "1")); }//End of TestMethodAddToHead2
public void TestMethodSearch3() { DLLNode p = new DLLNode("3"); DLList dll = new DLList(); dll.addToHead(p); p = new DLLNode("2"); dll.addToHead(p); p = new DLLNode("1"); dll.addToHead(p); //DLL order == 1,2,3 Assert.AreEqual(true, (dll.search("3") == dll.tail)); }//End of TestMethodSearch3
public void TestMethodAddToHead3() { DLLNode p = new DLLNode("1"); DLList dll = new DLList(); dll.addToHead(p); p = new DLLNode("2"); dll.addToHead(p); p = new DLLNode("3"); dll.addToHead(p); //Should be: Tail = 1, tail.previous.str = 2, tail.previous.previous.str = 3 Assert.AreEqual(true, (dll.tail.str == "1" && dll.tail.previous.str == "2" && dll.tail.previous.previous.str == "3")); }//End of TestMethodAddToHead3
public void testSearch1() { DLList list = new DLList(); DLLNode node1 = new DLLNode(5); DLLNode node2 = new DLLNode(7); DLLNode node3 = new DLLNode(20); list.addToHead(node1); list.addToHead(node2); list.addToHead(node3); Assert.AreEqual(list.search(5), node1); }
public void TestMethodAddToHead1() { DLLNode p = new DLLNode("1"); DLList dll = new DLList(); dll.addToHead(p); p = new DLLNode("2"); dll.addToHead(p); p = new DLLNode("3"); dll.addToHead(p); //Head should be 3, Tail should be 1, and tail.next and head.previous should be null Assert.AreEqual(true, (dll.head.str == "3" && dll.tail.str == "1")); Assert.AreEqual(true, (dll.head.previous == null && dll.tail.next == null)); }//End of TestMethodAddToHead1
public void TestMethodSearch4() { DLLNode p = new DLLNode("3"); DLList dll = new DLList(); dll.addToHead(p); p = new DLLNode("2"); dll.addToHead(p); p = new DLLNode("1"); dll.addToHead(p); //DLL order == 1,2,3 //"4" should not be found, and should return null Assert.AreEqual(true, (dll.search("4") == null)); }//End of TestMethodSearch4
public void TestMethodRemovHead2() { DLLNode p = new DLLNode("1"); DLList dll = new DLList(); dll.addToHead(p); p = new DLLNode("2"); dll.addToHead(p); p = new DLLNode("3"); dll.addToHead(p); dll.removHead(); //Before removal, order should be 3,2,1 //After, should be null -> 2 -> 1 -> null Assert.AreEqual(true, (dll.head.previous == null && dll.head.str == "2" && dll.head.next.str == "1" && dll.head.next.next == null)); }//End of TestMethodRemovHead2
public void TestMethodRemoveTail3() { DLLNode p = new DLLNode("1"); DLList dll = new DLList(); dll.addToHead(p); p = new DLLNode("2"); dll.addToHead(p); p = new DLLNode("3"); dll.addToHead(p); dll.removeTail(); //Before removal, order should be 3,2,1 //After, should be null <- 3 <- 2 <- null Assert.AreEqual(true, (dll.tail.next == null && dll.tail.str == "1" && dll.tail.previous.str == "2" && dll.tail.previous.previous == null)); }//End of TestMethodRemoveTail3
public void TestMethodRemovTail1() { DLLNode p = new DLLNode("1"); DLList dll = new DLList(); dll.addToHead(p); p = new DLLNode("2"); dll.addToHead(p); p = new DLLNode("3"); dll.addToHead(p); dll.removeTail(); //Before removal, order should be 3,2,1 //After, should be 3,2, with head.previous null, and tail.next null Assert.AreEqual(true, (dll.head.str == "3" && dll.tail.str == "2")); Assert.AreEqual(true, (dll.head.previous == null && dll.tail.next == null)); }//End of TestMethodRemovTail1
public void testRemoveNode4() { DLList list = new DLList(); DLLNode node1 = new DLLNode(12); DLLNode node2 = new DLLNode(5); DLLNode node3 = new DLLNode(7); list.addToHead(node1); list.addToHead(node2); list.addToHead(node3); list.removeNode(node3); Assert.AreEqual(list.total(), 2); Assert.AreEqual(list.head, node2); }
public void testSearch2() { DLList list = new DLList(); DLLNode node1 = new DLLNode(5); DLLNode node2 = new DLLNode(7); DLLNode node3 = new DLLNode(1); DLLNode node4 = new DLLNode(16); list.addToHead(node1); list.addToHead(node2); list.addToHead(node3); list.addToHead(node4); Assert.IsNull(list.search(20)); }
public void Testremovetail() { string[] str = new string[30]; int i = 0; FileStream f = new FileStream("C:/Users/edgu1/Desktop/222525.txt", FileMode.Open, FileAccess.Read); DLList pDLL = new DLList(); string line; try { StreamReader m_streamReader = new StreamReader(f); //StreamReader read txt m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin); //read from head to tail by lines while ((line = m_streamReader.ReadLine()) != null) { DLLNode d = new DLLNode(line); pDLL.addToHead(d); str[i] = line; i++; } m_streamReader.Close(); } catch (FileNotFoundException e) { Console.WriteLine("errors" + e.ToString()); } pDLL.removeTail(); //////////////////////// string[] str2 = new string[20]; int j = 0; DLLNode head = pDLL.head; while (head.next != null) { str2[j] = head.str; j++; head = head.next; } Console.WriteLine(head.str); str2[j] = head.str; /// ///////////////////////////////////// bool match1 = false; for (int k = 1; k < i; k++) { if (str[k] == str2[j]) { match1 = true; j--; } else { match1 = false; break; } } Assert.AreEqual(true, match1); }
public void TestAddToHead1() { DLList myDLL = new DLList(); DLLNode p = new DLLNode(1); myDLL.addToHead(p); Assert.AreEqual(myDLL.total(), 1); }
public void TestMethodRemoveNode4() { DLLNode p = new DLLNode("3"); DLList dll = new DLList(); dll.addToHead(p); p = new DLLNode("2"); dll.addToHead(p); p = new DLLNode("1"); dll.addToHead(p); //DLL order == 1,2,3 dll.removeNode(dll.head.next.next); //"4" should not be found, and should return null Assert.AreEqual(true, (dll.head.str == "1" && dll.tail.str == "3")); Assert.AreEqual(true, (dll.head.next.str == "2" && dll.head.next.next.str == "3" && dll.tail.previous.str == "2" && dll.tail.previous.previous.str == "1")); Assert.AreEqual(true, (dll.head.previous == null && dll.tail.next == null)); } //End of TestMethodRemoveNode4
public void testAddToHead1() { DLList list = new DLList(); DLLNode node1 = new DLLNode(12); list.addToHead(node1); Assert.AreEqual(list.total(), 1); }
public void testAddToHead2() { DLList list = new DLList(); DLLNode node1 = new DLLNode(12); DLLNode node2 = new DLLNode(5); DLLNode node3 = new DLLNode(6); DLLNode node4 = new DLLNode(8); DLLNode node5 = new DLLNode(1); list.addToHead(node1); list.addToHead(node2); list.addToHead(node3); list.addToHead(node4); list.addToHead(node5); Assert.AreEqual(list.total(), 5); Assert.AreEqual(node5, list.head); }
public void TestRemoveTail2() { DLList myDLL = new DLList(); DLLNode p = new DLLNode(1); myDLL.addToHead(p); DLLNode q = new DLLNode(2); myDLL.addToHead(q); DLLNode r = new DLLNode(3); myDLL.addToHead(r); myDLL.removeTail(); // When removing tail (1) from DLL (3,2,1) new head should be 2 Assert.AreEqual(myDLL.tail.num, 2); }
public void TestSearch1() { DLList list = new DLList(); DLLNode node1 = new DLLNode(5); DLLNode node2 = new DLLNode(4); DLLNode node3 = new DLLNode(3); DLLNode node4 = new DLLNode(2); DLLNode node5 = new DLLNode(7); list.addToHead(node1); list.addToHead(node2); list.addToHead(node3); list.addToHead(node4); list.addToHead(node5); //Searching value 7 should == pointer to node5 Assert.AreEqual(list.search(7), node5); }
public void TestSearch3() { DLList list = new DLList(); DLLNode node1 = new DLLNode(5); DLLNode node2 = new DLLNode(4); DLLNode node3 = new DLLNode(3); DLLNode node4 = new DLLNode(2); DLLNode node5 = new DLLNode(7); list.addToHead(node1); list.addToHead(node2); list.addToHead(node3); list.addToHead(node4); list.addToHead(node5); Assert.IsNull(list.search(1)); }
public void TestMethodAddToHead4() { DLLNode p = new DLLNode("1"); DLList dll = new DLList(); dll.addToHead(p); //Should be: Head and Tail = 1, and both .next.str and .previous.str are null; Assert.AreEqual(true, (dll.head.str == "1" && dll.tail.str == "1")); Assert.AreEqual(true, (dll.head.next == null && dll.head.previous == null)); Assert.AreEqual(true, (dll.tail.next == null && dll.tail.previous == null)); }//End of TestMethodAddToHead4
public void testRemoveNode1() { DLList list = new DLList(); DLLNode node = new DLLNode(12); list.addToHead(node); list.removeNode(node); Assert.AreEqual(list.total(), 0); Assert.IsNull(list.head); }
public void TestMethodRemoveTail4() { DLLNode p = new DLLNode("1"); DLList dll = new DLList(); dll.addToHead(p); dll.removeTail(); //Before removal, list should be 1 //After, head and tail should point to null Assert.AreEqual(true, (dll.head == null && dll.tail == null)); }//End of TestMethodRemoveTail4
public void TestRemoveTail3() { DLList myDLL = new DLList(); DLLNode p = new DLLNode(1); myDLL.addToHead(p); myDLL.removeTail(); // When removing tail (1) from DLL (1) new head & tail should be null Assert.AreEqual(myDLL.head, null); Assert.AreEqual(myDLL.tail, null); }
public void TestRemoveNode2() { DLList list = new DLList(); DLLNode node1 = new DLLNode(5); list.addToHead(node1); list.removeNode(node1); Assert.AreEqual(list.total(), 0); Assert.IsNull(list.search(5)); }
public void TestRemoveNode1() { DLList list = new DLList(); DLLNode node1 = new DLLNode(5); DLLNode node2 = new DLLNode(4); DLLNode node3 = new DLLNode(3); DLLNode node4 = new DLLNode(2); DLLNode node5 = new DLLNode(7); list.addToHead(node1); list.addToHead(node2); list.addToHead(node3); list.addToHead(node4); list.addToHead(node5); list.removeNode(node3); // there should only be 4 nodes left and value // of 7 should not be present Assert.AreEqual(list.total(), 4); Assert.IsNull(list.search(3)); }