예제 #1
0
        public void ThreeSumTests(int[] nums, int target, int expectedClosestSum)
        {
            // arrange
            // act
            int foundClosestSum = ThreeSumClosest.Find(nums, target);

            // assert
            Assert.AreEqual(expectedClosestSum, foundClosestSum);
        }
예제 #2
0
        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));
            }
        }
예제 #3
0
        public void When_0_0_0_Then_0()
        {
            var nums = new int[] { 0, 0, 0 };

            Assert.AreEqual(0, ThreeSumClosest.ThreeSumClosestFunc(nums, 1));
        }
예제 #4
0
        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));
        }
예제 #5
0
        public void When_1_1_1_0_Then_3()
        {
            var nums = new int[] { 1, 1, 1, 0 };

            Assert.AreEqual(3, ThreeSumClosest.ThreeSumClosestFunc(nums, 100));
        }
예제 #6
0
        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));
        }
예제 #7
0
        public void When_four_input_Then_2()
        {
            var nums = new int[] { -1, 2, 1, -4 };

            Assert.AreEqual(2, ThreeSumClosest.ThreeSumClosestFunc(nums, 1));
        }
예제 #8
0
        public void Test3SumClosest()
        {
            var r = ThreeSumClosest.S1(new int[] { -1, 2, 1, -4 }, 1);

            Assert.AreEqual(r, 2);
        }
예제 #9
0
 public void BeforeEach()
 {
     ThreeSumClosest = new ThreeSumClosest();
 }