public void ThreeSumTests(int[] nums, int target, int expectedClosestSum) { // arrange // act int foundClosestSum = ThreeSumClosest.Find(nums, target); // assert Assert.AreEqual(expectedClosestSum, foundClosestSum); }
private static void ThreeSumClosestTest() { Console.WriteLine("\n3 Sum Closest question:"); ThreeSumClosest threeSumClosest = new ThreeSumClosest(); IList <Tuple <int[], int> > testNumberArrays = new List <Tuple <int[], int> > { Tuple.Create(new int[] { -1, 2, 1, -4 }, 1), Tuple.Create(new int[] { 1, 2, 4, 8, 16, 32, 64, 128 }, 82), Tuple.Create(new int[] { 1, 1, -1, -1, 3 }, -1), Tuple.Create(new int[] { -1, 2, 1, -4 }, 1) }; foreach (Tuple <int[], int> pair in testNumberArrays) { Console.WriteLine("[{0}] -> {1}", string.Join(", ", pair.Item1), threeSumClosest.ThreeSumClosestOne(pair.Item1, pair.Item2)); } }
public void When_0_0_0_Then_0() { var nums = new int[] { 0, 0, 0 }; Assert.AreEqual(0, ThreeSumClosest.ThreeSumClosestFunc(nums, 1)); }
public void When_result_not_have_start_and_end_Then_82() { var nums = new int[] { 1, 2, 4, 8, 16, 32, 64, 128 }; Assert.AreEqual(82, ThreeSumClosest.ThreeSumClosestFunc(nums, 82)); }
public void When_1_1_1_0_Then_3() { var nums = new int[] { 1, 1, 1, 0 }; Assert.AreEqual(3, ThreeSumClosest.ThreeSumClosestFunc(nums, 100)); }
public void When_many_input_Then_4() { var nums = new int[] { -5, -4, -1, 1, 2, 2, 3, 7, 9 }; Assert.AreEqual(4, ThreeSumClosest.ThreeSumClosestFunc(nums, 4)); }
public void When_four_input_Then_2() { var nums = new int[] { -1, 2, 1, -4 }; Assert.AreEqual(2, ThreeSumClosest.ThreeSumClosestFunc(nums, 1)); }
public void Test3SumClosest() { var r = ThreeSumClosest.S1(new int[] { -1, 2, 1, -4 }, 1); Assert.AreEqual(r, 2); }
public void BeforeEach() { ThreeSumClosest = new ThreeSumClosest(); }