public void GetIndicesForTwoNumbersWhichAddToTarget(int[] numbers, int target, int[] expectedIndices)
    {
        TwoSum twoSum = new TwoSum();

        int[] actualIndices = twoSum.GetIndicesForTwoNumbersWhichAddToTarget(numbers, target);
        Assert.IsTrue(actualIndices.StructuralEquals(expectedIndices), $"Expected '{expectedIndices}' but received '{actualIndices}'");
    }
        public void Given_an_array_when_can_not_find_indices_then_should_throw(int[] nums, int target)
        {
            var solution  = new TwoSum();
            var exception = Assert.Throws <ArgumentException>(() => solution.Sum(nums, target));

            Assert.Equal(InvalidArgumentMessage, exception.Message);
        }
        public void TwoSum_Tests()
        {
            TwoSum obj = new TwoSum();


            obj.Add(3);
            obj.Add(1);
            obj.Add(2);

            var x = obj.Find(3); //t

            x = obj.Find(6);     //f



            obj = new TwoSum();


            obj.Add(0);
            obj.Add(-1);
            obj.Add(-1);
            obj.Add(0);
            x = obj.Find(-2); //t
            x = obj.Find(0);  //t
            x = obj.Find(-1); //t
            x = obj.Find(1);  //f
        }
Example #4
0
        public void SumExistsInCheckExistsTen()
        {
            int[] a = { 1, 5, 3, 7, 10, 10, 9 };
            int   X = 20;

            Assert.True(TwoSum.CheckExists(a, X));
        }
Example #5
0
        public void SumDoesNotExistInCheckExistsTen()
        {
            int[] a = { 1, 5, 3, 7, 10, 9 };
            int   X = 20;

            Assert.False(TwoSum.CheckExists(a, X));
        }
Example #6
0
        public void Soltion3Test(int[] nums, int target, int[] expected)
        {
            var result = TwoSum.Solution3(nums, target);

            Assert.Equal(expected[0], result[0]);
            Assert.Equal(expected[1], result[1]);
        }
Example #7
0
        public void TestSum()
        {
            TwoSum sum   = new TwoSum();
            var    resul = sum.GetIndicesForSumOptimized(new int[] { 2, 2, 2, 7 }, 9);

            CollectionAssert.AreEqual(new int[] { 1, 2 }, resul);
        }
 public void twoSumTest()
 {
     foreach (TwoSumTestData testData in TestDataList)
     {
         CollectionAssert.AreEqual(TwoSum.twoSum(testData.InputArrayInt, testData.InputInt), testData.OutputArrayInt);
     }
 }
Example #9
0
        public void SumDoesNotExistInCheckExistsHashed()
        {
            int[] a = { 1, 5, 3, 7, 12, 9 };
            int   X = 20;

            Assert.False(TwoSum.CheckExistsHashed(a, X));
        }
Example #10
0
        public void SumExistsInCheckExistsHashed()
        {
            int[] a = { 1, 5, 3, 7, 12, 8 };
            int   X = 20;

            Assert.True(TwoSum.CheckExistsHashed(a, X));
        }
        public void LargestIsland(int[] input, int target, int[] expected)
        {
            var sut    = new TwoSum();
            var actual = sut.Calculate(input, target);

            Assert.AreEqual(expected, actual);
        }
Example #12
0
        public void Given_an_array_when_sum_succeed_then_return_indices_can_added_up_to_target(
            int[] nums, int target, int[] expected)
        {
            var solution = new TwoSum();
            var actual   = solution.Sum(nums, target);

            Assert.Equal(expected, actual);
        }
Example #13
0
        public void twoSumTest2_4()
        {
            TwoSum twoSum = new TwoSum();

            int[] res = twoSum.twoSum2(new int[] { 5, 25, 75 }, 100);
            Assert.IsTrue(res[0] == 2);
            Assert.IsTrue(res[1] == 3);
        }
Example #14
0
        public void TwoSum()
        {
            var array = new int[] { 1, 2, 4, 5, 7, 11, 15 };

            var ret = new TwoSum().Find(array, 15);

            Assert.AreEqual(new Tuple<int, int>(4, 11), ret);
        }
Example #15
0
        public void twoSumTest8()
        {
            TwoSum twoSum = new TwoSum();

            int[] res = twoSum.twoSum(new int[] { 0, 4, 3, 0 }, 0);
            Assert.IsTrue(res[0] == 0);
            Assert.IsTrue(res[1] == 3);
        }
Example #16
0
        public void twoSumTestD()
        {
            TwoSum twoSum = new TwoSum();

            int[] res = twoSum.twoSum(new int[] { 11, 15, 7, 5, 4, 3 }, 9);
            Assert.IsTrue(res[0] == 3);
            Assert.IsTrue(res[1] == 4);
        }
Example #17
0
        public void twoSumTest6()
        {
            TwoSum twoSum = new TwoSum();

            int[] res = twoSum.twoSum(new int[] { -3, 4, 3, 90 }, 0);
            Assert.IsTrue(res[0] == 0);
            Assert.IsTrue(res[1] == 2);
        }
Example #18
0
        public void twoSumTest7()
        {
            TwoSum twoSum = new TwoSum();

            int[] res = twoSum.twoSum(new int[] { 2, 5, 5, 11 }, 10);
            Assert.IsTrue(res[0] == 1);
            Assert.IsTrue(res[1] == 2);
        }
Example #19
0
        public void twoSumTest4()
        {
            TwoSum twoSum = new TwoSum();

            int[] res = twoSum.twoSum(new int[] { 3, 2, 3 }, 6);
            Assert.IsTrue(res[0] == 0);
            Assert.IsTrue(res[1] == 2);
        }
Example #20
0
        public void twoSumTest5()
        {
            TwoSum twoSum = new TwoSum();

            int[] res = twoSum.twoSum(new int[] { 0, 4, 3, 0 }, 7);
            Assert.IsTrue(res[0] == 1);
            Assert.IsTrue(res[1] == 2);
        }
Example #21
0
        public void twoSumTest2_3()
        {
            TwoSum twoSum = new TwoSum();

            int[] res = twoSum.twoSum2(new int[] { -1, 0 }, -1);
            Assert.IsTrue(res[0] == 1);
            Assert.IsTrue(res[1] == 2);
        }
Example #22
0
        public void Should_Work_As_We_Expect_it_to_1()
        {
            var twoSum = new TwoSum();
            var nums   = new int[] { 2, 7, 11, 15 };
            var target = 9;

            Assert.Equal(twoSum.Solution1(nums, target), new int[] { 0, 1 });
        }
Example #23
0
        public void twoSumTest()
        {
            TwoSum twoSum = new TwoSum();

            int[] res = twoSum.twoSum(new int[] { 2, 7, 11, 15 }, 9);
            Assert.IsTrue(res[0] == 0);
            Assert.IsTrue(res[1] == 1);
        }
Example #24
0
        public void twoSumTest2_2()
        {
            TwoSum twoSum = new TwoSum();

            int[] res = twoSum.twoSum2(new int[] { 2, 3, 4 }, 6);
            Assert.IsTrue(res[0] == 1);
            Assert.IsTrue(res[1] == 3);
        }
Example #25
0
        public void TestMethod3()
        {
            TwoSum s = new TwoSum();

            s.Add(0);
            s.Add(-1);
            s.Add(1);
            Assert.IsTrue(s.Find(0));
        }
Example #26
0
        public void inpur_2_7_11_15_target_is_18_shouldReturn_1_2()
        {
            var nums      = new int[] { 2, 7, 11, 15 };
            var targetNum = 18;
            var target    = new int[] { 1, 2 };
            var actual    = TwoSum.calTwoSum(nums, targetNum);

            CollectionAssert.AreEqual(target, actual);
        }
Example #27
0
        public void input_3_2_4_target_is_6_shouldReturn_1_2()
        {
            var nums      = new int[] { 3, 2, 4 };
            var targetNum = 6;
            var target    = new int[] { 1, 2 };
            var actual    = TwoSum.calTwoSum(nums, targetNum);

            CollectionAssert.AreEqual(target, actual);
        }
Example #28
0
        public void calculateTwoSum()
        {
            TwoSum calculator = new TwoSum(new int[] { 3, 2, 4 }, 6);

            // int[] output = calculator.basicMethod();
            int[] output = calculator.aBetterApproach();
            Console.WriteLine(output[0]);
            Console.WriteLine(output[1]);
        }
Example #29
0
        public void input_2_7_11_15_target_is_9_shouldReturn_0_1()
        {
            var nums      = new int[] { 2, 7, 11, 15 };
            var targetNum = 9;
            var target    = new int[] { 0, 1 };
            var actual    = TwoSum.calTwoSum(nums, targetNum);

            CollectionAssert.AreEqual(target, actual);
        }
Example #30
0
    public static void Main()
    {
        Tuple <int, int> indices = TwoSum.FindTwoSum(new List <int>()
        {
            1, 3, 5, 7, 9
        }, 12);

        Console.WriteLine(indices.Item1 + " " + indices.Item2);
    }
Example #31
0
        public void TestGetTargetSum()
        {
            int[] input = new int[] { 2, 16, 11, 7 };

            TwoSum twoSum = new TwoSum();
            var    result = twoSum.GetIndicesForSumOptimized(input, 9);

            Assert.AreEqual(new int[] { 0, 1 }, result);
        }
Example #32
0
	static void Main()
	{
		TwoSum ts = new TwoSum();
		List<Tuple<int[], int, bool>> testInputs = new List<Tuple<int[], int, bool>>();
		testInputs.Add(Tuple.Create(new int[] {2, 7, 11, 15}, 9, true));
		foreach (var input in testInputs)
		{
			if (ts.Solve(input.Item1, input.Item2) != input.Item3)
			{
				WriteLine("Tests failed for {0}!", input.Item3);
				return;
			}
		}
		WriteLine("Tests passed!");
	}