public void CountTest() { var list = new SinglyLinkedList <string>(); Assert.AreEqual(0, list.Count); list.AddBack("Alpha"); Assert.AreEqual(1, list.Count); list.AddBack("Beta"); Assert.AreEqual(2, list.Count); }
public void AddBackTest() { var list = new SinglyLinkedList <string>(); list.AddBack("Alpha"); list.AddBack("Beta"); list.AddBack("Charlie"); Assert.AreEqual(3, list.Count); Assert.AreEqual("Alpha", list.GetAt(0)); Assert.AreEqual("Beta", list.GetAt(1)); Assert.AreEqual("Charlie", list.GetAt(2)); }
public void IndexOfTest() { var list = new SinglyLinkedList <string>(); list.AddBack("Alpha"); list.AddBack("Beta"); list.AddBack("Charlie"); Assert.AreEqual(0, list.IndexOf("Alpha")); Assert.AreEqual(1, list.IndexOf("Beta")); Assert.AreEqual(2, list.IndexOf("Charlie")); Assert.AreEqual(-1, list.IndexOf("Delta")); }
public void ClearTest() { var list = new SinglyLinkedList <string>(); list.AddBack("Alpha"); list.AddBack("Beta"); list.AddBack("Charlie"); Assert.AreEqual(3, list.Count); list.Clear(); Assert.AreEqual(0, list.Count); }
public void RemoveMiddleTest() { var list = new SinglyLinkedList <string>(); list.AddBack("Alpha"); list.AddBack("Beta"); list.AddBack("Charlie"); list.RemoveAt(1); Assert.AreEqual(2, list.Count); Assert.AreEqual("Alpha", list.GetAt(0)); Assert.AreEqual("Charlie", list.GetAt(1)); }
public void ContainsTest() { var list = new SinglyLinkedList <string>(); list.AddBack("Alpha"); list.AddBack("Beta"); list.AddBack("Charlie"); Assert.AreEqual(3, list.Count); Assert.AreEqual(true, list.Contains("Alpha")); Assert.AreEqual(true, list.Contains("Beta")); Assert.AreEqual(true, list.Contains("Charlie")); Assert.AreEqual(false, list.Contains("Delta")); }
public void GetBackTest() { var list = new SinglyLinkedList <string>(); list.AddBack("Alpha"); list.AddBack("Beta"); list.AddBack("Charlie"); Assert.AreEqual("Charlie", list.GetBack()); list.RemoveBack(); Assert.AreEqual("Beta", list.GetBack()); list.RemoveBack(); Assert.AreEqual("Alpha", list.GetBack()); list.RemoveBack(); Assert.AreEqual(0, list.Count); }
public void AddMiddleTest() { var list = new SinglyLinkedList <string>(); list.AddBack("Alpha"); list.AddBack("Beta"); list.AddBack("Delta"); list.AddBack("Echo"); list.AddAt(2, "Charlie"); Assert.AreEqual(5, list.Count); Assert.AreEqual("Alpha", list.GetAt(0)); Assert.AreEqual("Beta", list.GetAt(1)); Assert.AreEqual("Charlie", list.GetAt(2)); Assert.AreEqual("Delta", list.GetAt(3)); Assert.AreEqual("Echo", list.GetAt(4)); }
public void RemoveBackTest() { var list = new SinglyLinkedList <string>(); list.AddBack("Alpha"); list.AddBack("Beta"); list.AddBack("Charlie"); string shouldBeCharlie = list.RemoveBack(); Assert.AreEqual(2, list.Count); Assert.AreEqual("Charlie", shouldBeCharlie); string shouldBeBeta = list.RemoveBack(); Assert.AreEqual(1, list.Count); Assert.AreEqual("Beta", shouldBeBeta); }
public static SinglyLinkedList Copy(this SinglyLinkedList linkedlist) { SinglyLinkedList CopiedList = new SinglyLinkedList(); Node Current = linkedlist.Head; while (Current != null) { CopiedList.AddBack(Current.Value); Current = Current.Next; } return(CopiedList); }