public void InvalidInputsTest() { // Null input TestHelpers.AssertExceptionThrown(() => { Question2_2.FindKthToLast <int>(null, 0); }, typeof(ArgumentNullException)); // K invalid var list = ListHelpers.CreateLinkedList(1, 2, 3); TestHelpers.AssertExceptionThrown(() => { Question2_2.FindKthToLast(list, -1); }, typeof(ArgumentOutOfRangeException)); list = ListHelpers.CreateLinkedList(1, 2, 3); TestHelpers.AssertExceptionThrown(() => { Question2_2.FindKthToLast(list, 4); }, typeof(ArgumentOutOfRangeException)); }
public void BasicTest() { const int NumElements = 5; var list = ListHelpers.CreateLinkedList(Enumerable.Range(0, NumElements).Reverse().ToArray()); for (int i = 0; i < NumElements; i++) { var input = ListHelpers.CloneList(list); var result = Question2_2.FindKthToLast(input, i); Assert.AreEqual(i, result.Data); } }