public void Question_2_1_BasicCases() { // No duplicates var l1 = ListHelpers.CreateLinkedList(1, 2, 3); var expected = ListHelpers.CloneList(l1); this.ValidateResult(expected, l1); // Several (3x) duplicates var l2 = ListHelpers.CreateLinkedList(1, 1, 1); expected = ListHelpers.CreateLinkedList(1); this.ValidateResult(expected, l2); // two sets of duplicates, one next to each other one separated var l3 = ListHelpers.CreateLinkedList(1, 2, 2, 1); expected = ListHelpers.CreateLinkedList(1, 2); this.ValidateResult(expected, l3); // 3x duplicate case split up var l4 = ListHelpers.CreateLinkedList(1, 2, 2, 3, 2); expected = ListHelpers.CreateLinkedList(1, 2, 3); this.ValidateResult(expected, l4); // Several duplicates in the list var l5 = ListHelpers.CreateLinkedList(1, 2, 2, 1, 3, 4, 7, 5, 6, 2, 3, 4, 5, 6); expected = ListHelpers.CreateLinkedList(1, 2, 3, 4, 7, 5, 6); this.ValidateResult(expected, l5); }
private void ValidateResult <T>(Node <T> expected, Node <T> input, int k) where T : IEquatable <T> { var inputCopy = ListHelpers.CloneList(input); var inputCopy2 = ListHelpers.CloneList(input); Assert.AreEqual(expected, Question_2_2.ReturnKthToLast(inputCopy, k)); }
private void ValidateResult <T>(Node <T> expected, Node <T> input) where T : IEquatable <T> { var inputCopy = ListHelpers.CloneList(input); var inputCopy2 = ListHelpers.CloneList(input); Question_2_1.RemoveDuplicates(inputCopy); ListHelpers.ValidateLinkedListContent(expected, inputCopy); Question_2_1.RemoveDuplicatesNoSpace(input); ListHelpers.ValidateLinkedListContent(expected, input); Question_2_1.RemoveDuplicatesNoSpace2(inputCopy2); ListHelpers.ValidateLinkedListContent(expected, input); }
public void Question_2_2_BasicCases() { // Cover all case for K for a list of length 6. const int NumberElements = 6; var list = ListHelpers.CreateLinkedList(Enumerable.Range(0, NumberElements).Reverse().ToArray()); for (var i = 0; i < NumberElements; i++) { var listCopy = ListHelpers.CloneList(list); var result = Question_2_2.ReturnKthToLast(listCopy, i); Assert.AreEqual(i, result); } }
public void Question_2_1_EdgeCases() { // 1 => 1 - Only one element. var l1 = ListHelpers.CreateLinkedList(1); var expected = ListHelpers.CloneList(l1); this.ValidateResult(expected, l1); // 1, 1 => 1 - Only duplicate elements var l2 = ListHelpers.CreateLinkedList(1, 1); expected = ListHelpers.CreateLinkedList(1); this.ValidateResult(expected, l2); // 1, 2, 2 => 1, 2 - Last element duplicated var l3 = ListHelpers.CreateLinkedList(1, 2, 2); expected = ListHelpers.CreateLinkedList(1, 2); this.ValidateResult(expected, l3); }