Пример #1
0
        public void TestGetInputData()
        {
            List <int> numbers = ExpepenseReport.GetInputData();

            Assert.IsNotNull(numbers);
            Assert.Contains(1918, numbers);
        }
Пример #2
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);
        }
Пример #3
0
        public void TestFindTrippleSumAnwser()
        {
            int desiredSum = 2020;

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

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

            Console.Write(answer);
        }
Пример #4
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>());
        }
Пример #5
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);
        }