Ejemplo n.º 1
0
        public void TestFindSumNotInSum()
        {
            int desiredSum = 20;
            var input      = new List <int>()
            {
                1, 2, 3, 4
            };

            List <int> numbers = ExpepenseReport.FindSum(input, desiredSum);

            Assert.AreEqual(numbers.Count(), 0);
        }
Ejemplo n.º 2
0
        public void TestFindSumAnswer()
        {
            int desiredSum = 2020;

            // Find the answer to day 1 challange 1
            var        input   = ExpepenseReport.GetInputData();
            List <int> numbers = ExpepenseReport.FindSum(input, desiredSum);

            Assert.AreEqual(numbers.Sum(), desiredSum);
            int answer = numbers.Aggregate((x, y) => x * y);

            Console.Write(answer);
        }
Ejemplo n.º 3
0
        public static List <int> FindTrippleSum(List <int> numbers, int desiredSum)
        {
            var sum = new List <int>();

            foreach (int num1 in numbers)
            {
                sum = ExpepenseReport.FindSum(numbers, desiredSum - num1);
                if (num1 + sum.Sum() == desiredSum)
                {
                    sum.Add(num1);
                    return(sum);
                }
            }
            return(new List <int>());
        }
Ejemplo n.º 4
0
        public void TestFindSum()
        {
            int desiredSum = 5;
            var input      = new List <int>()
            {
                1, 2, 3, 4
            };

            List <int> numbers = ExpepenseReport.FindSum(input, desiredSum);

            Assert.AreEqual(numbers.Count(), 2);
            Assert.AreEqual(numbers.Sum(), desiredSum);
            Assert.Contains(numbers[0], input);
            Assert.Contains(numbers[1], input);
        }