public void TestRemoveNotInList() { // This shoudln't throw any exceptions VisitableLinkedList <int> list = GetTestCustomLinkedList(); list.Remove(999); }
public void TestInsertAfter() { VisitableLinkedList <int> list = GetTestCustomLinkedList(); LinkedListNode <int> currentElement = list.First; LinkedListNode <int> secondElement = currentElement.Next; list.AddAfter(secondElement, 23); // Verify the list items and their contents for (int i = 0; i < 6; i++) { if (i < 2) { Assert.AreEqual(currentElement.Value, i * 3); } else if (i == 2) { Assert.AreEqual(currentElement.Value, 23); } else { Assert.AreEqual(currentElement.Value, (i - 1) * 3); } currentElement = currentElement.Next; } }
public void TestSuccesfulInit() { VisitableLinkedList <int> list = new VisitableLinkedList <int>(); Assert.AreEqual(list.First, null); Assert.AreEqual(list.Last, null); }
public void TestInsertBeforeFirst() { VisitableLinkedList <int> list = GetTestCustomLinkedList(); LinkedListNode <int> currentElement = list.First; list.AddBefore(currentElement, 657); Assert.AreEqual(list.First.Value, 657); currentElement = list.First; // Verify the list items and their contents for (int i = 0; i < 6; i++) { if (i == 0) { Assert.AreEqual(currentElement.Value, 657); } else { Assert.AreEqual(currentElement.Value, (i - 1) * 3); } currentElement = currentElement.Next; } }
public void TestAddLastFullList() { VisitableLinkedList <int> testList = GetTestCustomLinkedList(); testList.AddLast(15); Assert.AreEqual(testList.Last.Value, 15); Assert.AreEqual(testList.Last.Next, null); }
public void TestIsFull() { VisitableLinkedList <int> list = new VisitableLinkedList <int>(); Assert.AreEqual(list.IsFull, false); list.AddLast(5); Assert.AreEqual(list.IsFull, false); }
public void TestVisitor() { VisitableLinkedList <int> l = GetTestCustomLinkedList(); SumVisitor visitor = new SumVisitor(); l.Accept(visitor); Assert.AreEqual(visitor.Sum, 0 + 3 + 6 + 9 + 12); }
public void TestClear() { VisitableLinkedList <int> list = GetTestCustomLinkedList(); list.Clear(); Assert.AreEqual(list.First, null); Assert.AreEqual(list.Last, null); Assert.AreEqual(list.IsEmpty, true); }
private VisitableLinkedList <int> GetTestCustomLinkedList() { VisitableLinkedList <int> list = new VisitableLinkedList <int>(); for (int i = 0; i < 5; i++) { list.AddLast(i * 3); } return(list); }
public void TestFixedSize() { VisitableLinkedList <int> l = new VisitableLinkedList <int>(); Assert.AreEqual(l.IsFixedSize, false); l = new VisitableLinkedList <int>(); l.AddFirst(4); Assert.AreEqual(l.IsFixedSize, false); }
public void TestAddLastEmptyList() { VisitableLinkedList <int> testList = new VisitableLinkedList <int>(); testList.AddLast(16); Assert.AreNotEqual(testList.First, null); Assert.AreEqual(testList.First.Value, 16); Assert.AreNotEqual(testList.Last, null); Assert.AreEqual(testList.Last.Value, 16); Assert.AreEqual(testList.First.Next, null); }
public void TestInsertBefore1Item() { VisitableLinkedList <int> list = new VisitableLinkedList <int>(); list.AddLast(5); list.AddBefore(list.First, 6); Assert.AreEqual(list.First.Value, 6); Assert.AreEqual(list.First.Next.Value, 5); Assert.AreEqual(list.Last.Value, 5); }
public void TestInsertItems() { VisitableLinkedList <int> list = GetTestCustomLinkedList(); LinkedListNode <int> currentElement = list.First; // Verify the list items and their contents for (int i = 0; i < 5; i++) { Assert.AreEqual(currentElement.Value, i * 3); currentElement = currentElement.Next; } }
public void TestStoppingVisitor() { VisitableLinkedList <int> l = GetTestCustomLinkedList(); ComparableFindingVisitor <int> visitor = new ComparableFindingVisitor <int>(6); l.Accept(visitor); Assert.AreEqual(visitor.Found, true); visitor = new ComparableFindingVisitor <int>(99); l.Accept(visitor); Assert.AreEqual(visitor.Found, false); }
public void TestCompareTo() { VisitableLinkedList <int> l1 = new VisitableLinkedList <int>(); l1.AddFirst(5); VisitableLinkedList <int> l2 = new VisitableLinkedList <int>(); l2.AddFirst(3); l2.AddFirst(4); Assert.AreEqual(l1.CompareTo(l2), -1); Assert.AreEqual(l2.CompareTo(l1), 1); Assert.AreEqual(l1.CompareTo(l1), 0); object o = new object(); Assert.AreEqual(l1.CompareTo(o), -1); }
public void TestRemove() { VisitableLinkedList <int> list = GetTestCustomLinkedList(); LinkedListNode <int> currentElement = list.First; list.Remove(9); // Verify the list items and their contents for (int i = 0; i < 5; i++) { if (i == 3) { continue; } else { Assert.AreEqual(currentElement.Value, i * 3); currentElement = currentElement.Next; } } }
public void TestNullVisitor() { VisitableLinkedList <int> l = new VisitableLinkedList <int>(); l.Accept(null); }
public void TestLastListEmpty() { VisitableLinkedList <int> list = new VisitableLinkedList <int>(); Assert.AreEqual(list.Last, null); }
public void TestLast() { VisitableLinkedList <int> testList = GetTestCustomLinkedList(); Assert.AreEqual(testList.Last.Value, 12); }
public void TestInvalidCompareTo() { VisitableLinkedList <string> l = new VisitableLinkedList <string>(); l.CompareTo(null); }