public void TestDeleteNode() { var headNode = new SingleLinkedListNode<int>(1); var linkedList = new SingleLinkedList<int>(headNode); var midNode = new SingleLinkedListNode<int>(2); var childNode = new SingleLinkedListNode<int>(3); linkedList.AddToTail(midNode); Assert.AreEqual(2, linkedList.Count); linkedList.AddToTail(childNode); IEnumerable<int> nodeData = linkedList.GetAllNodeValues().ToList(); Assert.AreEqual(1, nodeData.First()); Assert.AreEqual(2, nodeData.Skip(1).First()); Assert.AreEqual(3, nodeData.Last()); SingleLinkedListNode<int> currentLinkedList = linkedList.DeleteNode(2); nodeData = linkedList.GetAllNodeValues().ToList(); Assert.AreEqual(2,nodeData.Count()); Assert.AreEqual(1, nodeData.First()); Assert.AreEqual(3, nodeData.Last()); }
public void TestAddNodeToTail() { var headNode = new SingleLinkedListNode<int>(1); var linkedList = new SingleLinkedList<int>(headNode); var midNode = new SingleLinkedListNode<int>(2); var childNode = new SingleLinkedListNode<int>(3); Assert.AreEqual(1, linkedList.Count); linkedList.AddToTail(midNode); Assert.AreEqual(2, linkedList.Count); linkedList.AddToTail(childNode); Assert.AreEqual(3, linkedList.Count); IEnumerable<int> nodeData = linkedList.GetAllNodeValues().ToList(); Assert.AreEqual(1,nodeData.First()); Assert.AreEqual(2, nodeData.Skip(1).First()); Assert.AreEqual(3, nodeData.Last()); Console.WriteLine(string.Join(",",nodeData.ToArray())); }