public static void TestInsertAfter() { var testList = new LinkedList2(); testList.InsertAfter(null, new Node(1)); Assert.AreEqual(1, testList.Count(), "Test TestInsertAfter failed. List count have to be equal 1"); testList.AddInTail(new Node(3)); testList.AddInTail(new Node(5)); testList.InsertAfter(new Node(3), new Node(4)); Assert.AreEqual(4, testList.Count(), "Test TestInsertAfter failed. List count have to be equal 4"); testList.InsertAfter(new Node(1), new Node(2)); Assert.AreEqual(5, testList.Count(), "Test TestInsertAfter failed. List count have to be equal 5"); testList.InsertAfter(new Node(5), new Node(6)); Assert.AreEqual(6, testList.Count(), "Test TestInsertAfter failed. List count have to be equal 6"); testList.InsertAfter(null, new Node(0)); Assert.AreEqual(7, testList.Count(), "Test TestInsertAfter failed. List count have to be equal 7"); Assert.AreEqual(0, testList.head.value, "Test TestInsertAfter failed. List head.value have to be equal 0"); Assert.AreEqual(6, testList.tail.value, "Test TestInsertAfter failed. List tail.value have to be equal 6"); Assert.IsNull(testList.tail.next, "Test TestInsertAfter failed. List tail.next have to be equal NULL"); Assert.IsNull(testList.head.prev, "Test TestInsertAfter failed. List head.prev have to be equal NULL"); Assert.IsNotNull(testList.tail.prev, "Test TestInsertAfter failed. List tail.prev have to be equal NOT NULL"); Assert.IsNotNull(testList.head.next, "Test TestInsertAfter failed. List head.next have to be equal NOT NULL"); int counter = -1; Node node = testList.head; while (node != null) { counter += 1; Assert.AreEqual(counter, node.value, "Test TestInsertAfter failed. List sequence is not correct"); node = node.next; } }
public void Test_RemoveAll_WhenManyFoundItemsInMiddle() { var list = new LinkedList2(); var deletedValue = 2; var node1 = new Node(1); var node2 = new Node(deletedValue); var node3 = new Node(deletedValue); var node4 = new Node(3); list.AddInTail(node1); list.AddInTail(node2); list.AddInTail(node3); list.AddInTail(node4); var head = list.head; var tail = list.tail; list.RemoveAll(deletedValue); var expected = "[1, 3]"; var reverseExpected = "[3, 1]"; Assert.AreEqual(expected, list.ToString()); Assert.AreEqual(reverseExpected, list.ReverseToString()); Assert.AreEqual(head, list.head); Assert.AreEqual(tail, list.tail); }
public void Test_Remove_WhenFoundItemInTailTwoTimes() { var list = new LinkedList2(); var deletedValue = 3; var node1 = new Node(1); var node2 = new Node(2); var node3 = new Node(deletedValue); var node4 = new Node(deletedValue); list.AddInTail(node1); list.AddInTail(node2); list.AddInTail(node3); list.AddInTail(node4); var head = list.head; list.Remove(deletedValue); list.Remove(deletedValue); var expected = "[1, 2]"; var reverseExpected = "[2, 1]"; Assert.AreEqual(expected, list.ToString()); Assert.AreEqual(reverseExpected, list.ReverseToString()); Assert.AreEqual(head, list.head); Assert.AreEqual(node2, list.tail); }
public void FindInFilledList() { LinkedList2 list = new LinkedList2(); Node testNode = new Node(12); list.AddInTail(new Node(10)); list.AddInTail(new Node(11)); list.AddInTail(testNode); Assert.IsTrue(list.Find(13) == null && list.Find(12) == testNode); }
public void TestMethod1() { LinkedList2 list = new LinkedList2(); list.AddInTail(new Node(10)); list.AddInTail(new Node(11)); list.AddInTail(new Node(12)); list.Clear(); Assert.IsTrue(list.head == null && list.tail == null); }
public void Test_AddInTail_TwoTimes() { var list = new LinkedList2(); var node1 = new Node(1); var node2 = new Node(1); list.AddInTail(node1); list.AddInTail(node2); Assert.AreEqual(node1, list.head); Assert.AreEqual(node2, list.tail); }
public void Test_Find_WhenOneFoundItem() { var list = new LinkedList2(); var node1 = new Node(1); var node2 = new Node(2); list.AddInTail(node1); list.AddInTail(node2); var foundNode = list.Find(node2.value); Assert.AreEqual(node2, foundNode); }
public void FindAllInFilledList() { LinkedList2 list = new LinkedList2(); list.AddInTail(new Node(10)); list.AddInTail(new Node(20)); list.AddInTail(new Node(10)); list.AddInTail(new Node(30)); list.AddInTail(new Node(10)); List <Node> nodeList = list.FindAll(10); Assert.IsTrue(nodeList.Count == 3); }
public static void TestAddInTail() { var testList = new LinkedList2(); Assert.AreEqual(0, testList.Count(), "Test TestAddInTail failed. Initial list count have to be equal 0"); testList.AddInTail(new Node(1)); Assert.AreEqual(1, testList.Count(), "Test TestAddInTail failed. List count have to be equal 1"); testList.AddInTail(new Node(2)); Assert.AreEqual(2, testList.Count(), "Test TestAddInTail failed. List count have to be equal 2"); testList.AddInTail(new Node(3)); Assert.AreEqual(3, testList.Count(), "Test TestAddInTail failed. List count have to be equal 3"); Assert.IsNull(testList.tail.next, "Test TestAddInTail failed. List tail.next not equal NULL"); }
public void Remove_from_Tail() { LinkedList2 testList = new LinkedList2(); testList.AddInTail(new Node(0)); testList.AddInTail(new Node(1)); testList.AddInTail(new Node(2)); testList.AddInTail(new Node(3)); int expected = 3; testList.Remove(3); int actual = testList.Count(); Assert.AreEqual(expected, actual); Assert.IsNull(testList.Find(3)); }
public void RemoveLastNode() { LinkedList2 list = new LinkedList2(); list.AddInTail(new Node(10)); list.AddInTail(new Node(11)); list.AddInTail(new Node(12)); if (list.Remove(12) == true) { Assert.IsTrue(list.tail.value == 11); } else { Assert.Fail(); } }
public static void TestFind() { var testList = new LinkedList2(); testList.AddInTail(new Node(1)); testList.AddInTail(new Node(2)); testList.AddInTail(new Node(3)); testList.AddInTail(new Node(4)); testList.AddInTail(new Node(5)); var found = testList.Find(2); Assert.AreSame(testList.head.next, found, "Test TestFind failed. List head.next not equal found"); Assert.AreEqual(2, found.value, "Test TestFind failed. List found not equal 2"); Assert.AreEqual(3, found.next.value, "Test TestFind failed. List found.next not equal 3"); Assert.AreEqual(1, found.prev.value, "Test TestFind failed. List found.prev not equal 1"); }
public void Test_RemoveAll_WhenListContainsOneElement() { var list = new LinkedList2(); var deletedValue = 2; var node1 = new Node(deletedValue); var node2 = new Node(deletedValue); list.AddInTail(node1); list.AddInTail(node2); list.RemoveAll(deletedValue); var expected = "[]"; Assert.AreEqual(expected, list.ReverseToString()); Assert.AreEqual(null, list.head); Assert.AreEqual(null, list.tail); }
public void AddInHead_in_NotEmptyList() { LinkedList2 testList = new LinkedList2(); testList.AddInTail(new Node(1)); testList.AddInTail(new Node(2)); testList.AddInTail(new Node(3)); testList.AddInTail(new Node(4)); testList.AddInTail(new Node(5)); int expected = 6; testList.AddInHead(new Node(19)); int actual = testList.Count(); Assert.AreEqual(expected, actual); Assert.IsNotNull(testList.Find(19)); }
public void AddNode_in_Tail() { LinkedList2 testList = new LinkedList2(); testList.AddInTail(new Node(1)); testList.AddInTail(new Node(2)); testList.AddInTail(new Node(3)); testList.AddInTail(new Node(4)); testList.AddInTail(new Node(5)); int expected = 6; testList.InsertAfter(new Node(5), new Node(21)); int actual = testList.Count(); Assert.AreEqual(expected, actual); Assert.IsTrue(testList.Find(21).value == 21); }
public void AddNode_if_Target_non_Exists() { LinkedList2 testList = new LinkedList2(); testList.AddInTail(new Node(1)); testList.AddInTail(new Node(2)); testList.AddInTail(new Node(3)); testList.AddInTail(new Node(4)); testList.AddInTail(new Node(5)); int expected = 5; testList.InsertAfter(new Node(13), new Node(21)); int actual = testList.Count(); Assert.AreEqual(expected, actual); Assert.IsNull(testList.Find(21)); }
public void Test_Find_WhenManyFoundItems() { var list = new LinkedList2(); var sameValue = 2; var node1 = new Node(1); var node2 = new Node(sameValue); var node3 = new Node(4); var node4 = new Node(sameValue); list.AddInTail(node1); list.AddInTail(node2); list.AddInTail(node3); list.AddInTail(node4); var foundNode = list.Find(sameValue); Assert.AreEqual(node2, foundNode); }
public void Test_FindAll_WhenNoFoundItems() { var list = new LinkedList2(); var sameValue = 2; var node1 = new Node(1); var node2 = new Node(sameValue); var node3 = new Node(4); var node4 = new Node(sameValue); var expected = new List <Node>(); list.AddInTail(node1); list.AddInTail(node2); list.AddInTail(node3); list.AddInTail(node4); var foundNodes = list.FindAll(0); CollectionAssert.AreEqual(expected, foundNodes); }
public static void TestRemoveAll() { var testList = new LinkedList2(); testList.AddInTail(new Node(1)); testList.AddInTail(new Node(2)); testList.AddInTail(new Node(1)); testList.AddInTail(new Node(3)); testList.AddInTail(new Node(1)); testList.RemoveAll(1); Assert.AreEqual(2, testList.Count(), "Test TestRemoveAll failed. List count have to be equal 2"); Assert.AreEqual(2, testList.head.value, "Test TestRemoveAll failed. List head not equal 2"); Assert.AreEqual(3, testList.tail.value, "Test TestRemoveAll failed. List tail not equal 3"); Assert.IsNull(testList.tail.next, "Test TestRemoveAll failed. List tail.next not equal NULL"); Assert.IsNull(testList.head.prev, "Test TestRemoveAll failed. List head.prev not equal NULL"); Assert.IsNotNull(testList.head.next, "Test TestRemoveAll failed. List head.next not equal NOT NULL"); Assert.IsNotNull(testList.tail.prev, "Test TestRemoveAll failed. List tail.prev not equal NOT NULL"); }
public static void TestRemove() { var testList = new LinkedList2(); testList.AddInTail(new Node(1)); testList.AddInTail(new Node(2)); testList.AddInTail(new Node(3)); testList.Remove(1); Assert.AreEqual(2, testList.Count(), "Test TestRemove failed. List count have to be equal 2"); testList.Remove(3); Assert.AreEqual(1, testList.Count(), "Test TestRemove failed. List count have to be equal 1"); Assert.AreSame(testList.head, testList.tail, "Test TestRemove failed. List head not equal tail"); Assert.IsNull(testList.tail.next, "Test TestRemove failed. List tail.next not equal NULL"); testList.Remove(2); Assert.AreEqual(0, testList.Count(), "Test TestRemove failed. List count have to be equal 0"); Assert.IsNull(testList.head, "Test TestRemove failed. List not empty"); Assert.IsNull(testList.tail, "Test TestRemove failed. List not empty"); }
public void Test_AddInTail_Once() { var list = new LinkedList2(); var node1 = new Node(1); list.AddInTail(node1); Assert.AreEqual(list.tail, list.head); Assert.AreEqual(node1, list.head); }
public void InsertInFilledOneListWithoutNodeAfter() { LinkedList2 list = new LinkedList2(); Node node = new Node(10); Node node2 = new Node(20); list.AddInTail(node2); list.InsertAfter(null, node); Assert.IsTrue(list.head == node && list.tail == node2); }
public void Test_Count_WhenNonEmpty() { var list = new LinkedList2(); var node = new Node(1); list.AddInTail(node); var count = list.Count(); Assert.AreEqual(1, count); }
public void TestFindAll() { var testBigValue = 1000; var list = new LinkedList2(); list.AddInTail(new Node(testBigValue)); Program.GenerateLinkedListElements(list, ElementsCount); list.AddInTail(new Node(testBigValue)); Program.GenerateLinkedListElements(list, ElementsCount); list.AddInTail(new Node(testBigValue)); var resultList = list.FindAll(testBigValue); Assert.AreEqual(3, resultList.Count); foreach (var e in resultList) { Assert.AreEqual(testBigValue, e.value); } }
public void Test_InsertAfter_WhenNodeIsHead() { var list = new LinkedList2(); var node1 = new Node(1); var node3 = new Node(3); var insertedNode = new Node(0); list.AddInTail(node1); list.AddInTail(node3); var head = list.head; var tail = list.tail; list.InsertAfter(node1, insertedNode); var expected = "[1, 0, 3]"; var reverseExpected = "[3, 0, 1]"; Assert.AreEqual(expected, list.ToString()); Assert.AreEqual(reverseExpected, list.ReverseToString()); Assert.AreEqual(head, list.head); Assert.AreEqual(tail, list.tail); }
public void Test_InsertAfter_WhenNodeIsInMiddle() { var list = new LinkedList2(); var node1 = new Node(1); var node2 = new Node(2); var node3 = new Node(3); var insertedNode = new Node(0); list.AddInTail(node1); list.AddInTail(node2); list.AddInTail(node3); var head = list.head; var tail = list.tail; list.InsertAfter(node1, insertedNode); var expected = "[1, 0, 2, 3]"; Assert.AreEqual(expected, list.ToString()); Assert.AreEqual(head, list.head); Assert.AreEqual(tail, list.tail); }
static void TestFindElement() { Console.WriteLine("find element test"); var list = new LinkedList2(); list.AddInTail(new Node(20)); list.AddInTail(new Node(24)); list.AddInTail(new Node(10)); list.AddInTail(new Node(15)); list.AddInTail(new Node(77)); list.AddInTail(new Node(24)); Console.WriteLine("find 20"); var result = list.Find(20); Console.WriteLine("result " + result.value); Console.WriteLine("find 10"); result = list.Find(10); Console.WriteLine("result " + result.value); Console.WriteLine("find 24"); result = list.Find(24); Console.WriteLine("result " + result.value); Console.WriteLine(new string('=', 30)); }
static void TestFindElements() { Console.WriteLine("find elements test"); var list = new LinkedList2(); list.AddInTail(new Node(20)); list.AddInTail(new Node(24)); list.AddInTail(new Node(10)); list.AddInTail(new Node(15)); list.AddInTail(new Node(77)); list.AddInTail(new Node(24)); Console.WriteLine("find 20"); var result = list.FindAll(20); foreach (var item in result) { Console.WriteLine(item.value); } Console.WriteLine("find 24"); result = list.FindAll(24); foreach (var item in result) { Console.WriteLine(item.value); } Console.WriteLine(new string('=', 30)); }
public void Test_Clear_WhenNonEmpty() { var list = new LinkedList2(); var node1 = new Node(1); list.AddInTail(node1); list.Clear(); var count = list.Count(); Assert.AreEqual(null, list.head); Assert.AreEqual(null, list.tail); Assert.AreEqual(0, count); }
public void Test_RemoveAll_WhenFoundItemInHead() { var list = new LinkedList2(); var deletedValue = 1; var node1 = new Node(deletedValue); var node2 = new Node(2); var node3 = new Node(3); list.AddInTail(node1); list.AddInTail(node2); list.AddInTail(node3); var tail = list.tail; list.RemoveAll(deletedValue); var expected = "[2, 3]"; var reverseExpected = "[3, 2]"; Assert.AreEqual(expected, list.ToString()); Assert.AreEqual(reverseExpected, list.ReverseToString()); Assert.AreEqual(node2, list.head); Assert.AreEqual(tail, list.tail); }