public void TestRemoveLinkedListElements() { var list = MyLinkList.BuildListNodeFromArray(new[] { 9, 1, 2, 9, 9, 3, 9, 4, 5, 6, 7, 8, 9 }); var r = RemoveLinkedListElements.Remove(list, 9); Assert.AreEqual(r.Length(), 8); }
public void RemoveLinkedListTestCase1() { var list = CommonHelpers.GetLinkedListFromArray(new[] { 1, 2, 6, 3, 4, 5, 6 }); var output = RemoveLinkedListElements.RemoveElements(list, 6).ValuesToFlatList(); output.SequenceEqual(new[] { 1, 2, 3, 4, 5 }).Should().BeTrue(); }
public void RemoveElements_MiddleConsequitive_ReturnExpected() { var helper = new RemoveLinkedListElements(); //1->2->6->3->4->5->6, val = 6 var head = new ListNode(1) { next = new ListNode(2) { next = new ListNode(2) { next = new ListNode(1) } } }; var expected = new ListNode(1) { next = new ListNode(1) }; var result = helper.RemoveElements(head, 2); Assert.That(result, Is.EqualTo(expected)); }
public void TestMethod1(int[] head, int val, int[] expected) { // Arrange RemoveLinkedListElements question = new RemoveLinkedListElements(); ListNode headNode = null; if (head != null && head.Length > 0) { headNode = new ListNode(head[0]); ListNode node = headNode; for (int i = 1; i < head.Length; i++) { node.next = new ListNode(head[i]); node = node.next; } } // Act ListNode actual = question.RemoveElements(headNode, val); List <int> actualList = null; if (actual != null) { actualList = new List <int>(); while (actual != null) { actualList.Add(actual.val); actual = actual.next; } } // Assert CollectionAssert.AreEqual(expected, actualList?.ToArray()); }
public void RemoveElementsTests() { RemoveLinkedListElements obj = new RemoveLinkedListElements(); //// Input: 1->2->6->3->4->5->6, val = 6 ////Output: 1->2->3->4->5 var input = new ListNode(1) { next = new ListNode(2) { next = new ListNode(6) { next = new ListNode(3) { next = new ListNode(4) { next = new ListNode(5) { next = new ListNode(6) } } } } } }; var x = obj.RemoveElements(input, 6); }
public void RemoveElementsTest() { // 删除中间结点 ListNode headA = new ListNode(1); ListNode node2 = new ListNode(2); ListNode node3 = new ListNode(3); ListNode node4 = new ListNode(4); ListNode node5 = new ListNode(5); ListNode node6 = new ListNode(6); headA.next = node2; node2.next = node3; node3.next = node4; node4.next = node5; node5.next = node6; ListNode headB = new ListNode(1); ListNode nodeB2 = new ListNode(2); ListNode nodeB3 = new ListNode(3); ListNode nodeB4 = new ListNode(4); ListNode nodeB6 = new ListNode(6); headB.next = nodeB2; nodeB2.next = nodeB3; nodeB3.next = nodeB4; nodeB4.next = nodeB6; headA = new RemoveLinkedListElements().RemoveElements(headA, 5); Assert.IsTrue(headA.IsEqual(headB)); }
public void RemoveLinkedListTestCase3() { var list = CommonHelpers.GetLinkedListFromArray(new[] { 1, 2, 2, 1 }); RemoveLinkedListElements.RemoveElements(list, 2).ValuesToFlatList().Should().BeEquivalentTo(new List <int> { 1, 1 }); }
public void RemoveElements_WhenMiddleAndEnd_ReturnExpected() { var helper = new RemoveLinkedListElements(); //1->2->6->3->4->5->6, val = 6 var head = new ListNode(1) { next = new ListNode(2) { next = new ListNode(6) { next = new ListNode(3) { next = new ListNode(4) { next = new ListNode(5) { next = new ListNode(6) } } } } } }; var expected = new ListNode(1) { next = new ListNode(2) { next = new ListNode(3) { next = new ListNode(4) { next = new ListNode(5) } } } }; var result = helper.RemoveElements(head, 6); Assert.That(result, Is.EqualTo(expected)); }