public void TestClosestNumbers() { // https://www.hackerrank.com/challenges/closest-numbers/problem int[] o1 = ClosestNumbers.closestNumbers(new int[] { -20, -3916237, -357920, -3620601, 7374819, -7330761, 30, 6246457, -6461594, 266854 }); // -20 30 int[] o2 = ClosestNumbers.closestNumbers(new int[] { -20, -3916237, -357920, -3620601, 7374819, -7330761, 30, 6246457, -6461594, 266854, -520, -470 }); // -520 -470 -20 30 }
public void closestNumbersTest() { foreach (ClosestNumbersTestData testData in TestDataList) { Console.WriteLine("Test input: " + string.Join(",", testData.InputArray)); int[] result = ClosestNumbers.closestNumbers(testData.InputTarget, testData.InputNumbers, testData.InputArray); Console.WriteLine("Test output: " + string.Join(",", result)); CollectionAssert.AreEqual(testData.OutputArray, result); } }