コード例 #1
0
        public static void MultiplesOf3And5TestsTest()
        {
            var expected = 233168;
            var actual   = MultiplesOf3And5.Evaluate();

            Assert.AreEqual(expected, actual);
        }
コード例 #2
0
        public void Sum_Of_Multiples_TestMethod(int exclusiveUpper, int expectedSum)
        {
            // value from function
            var actual = new MultiplesOf3And5();
            int sum    = actual.Sum_Of_Multiples(exclusiveUpper);

            Assert.AreEqual(sum, expectedSum, "The Sum function returned a different value");
        }
コード例 #3
0
        public void Problem1Solution_1000_233168()
        {
            //Act
            int result = MultiplesOf3And5.Calculate(1000);

            //Assert
            Assert.Equal(233168, result);
        }
コード例 #4
0
        public void FindNaturalNumbersBelow_Given10_ShouldReturnArrayOf1Thru9()
        {
            var m = new MultiplesOf3And5();
            var expected = new int[9] {1, 2, 3, 4, 5, 6, 7, 8, 9};

            var actual = m.FindNaturalNumbersBelow(10);

            CollectionAssert.AreEqual(expected, actual);
        }
コード例 #5
0
        public void Filter_GivenIntArray_ShouldReturnArrayOfIntsMeetingGivenCondition()
        {
            var m = new MultiplesOf3And5();
            var intArray = new int[9] {1, 2, 3, 4, 5, 6, 7, 8, 9};
            var expected = new int[4] {1, 2, 3, 4};

            var actual = m.Filter(intArray, x => x < 5);

            CollectionAssert.AreEqual(expected, actual);
        }
コード例 #6
0
        public void Filter_GivenIntArray_ReturnMultiplesOf3Or5()
        {
            var m = new MultiplesOf3And5();
            var intArray = new int[9] {1, 2, 3, 4, 5, 6, 7, 8, 9};
            var expected = new int[4] {3, 5, 6, 9};

            var actual = m.Filter(intArray, x => x % 3 == 0 || x % 5 == 0);

            CollectionAssert.AreEqual(expected, actual);
        }
コード例 #7
0
        public void Sum_GivenTwoNumbersInArray_ShouldReturnCorrectSum()
        {
            var a = 5;
            var b = 10;
            var numbers = new int[2] {a, b};
            var m = new MultiplesOf3And5();

            var sum = m.Sum(numbers);

            Assert.AreEqual(a + b, sum);
        }
コード例 #8
0
        public void GivenAnExclusiveUpperNumber_ReturnsCorrectSum(int exclusiveUpper, int expectedSum)
        {
            // arrange
            var multiplesOf3And5 = new MultiplesOf3And5();

            // act
            var sum = multiplesOf3And5.Sum(exclusiveUpper);

            // assert
            Assert.Equal(expectedSum, sum);
        }
コード例 #9
0
        public void Calculate_Limit10_23()
        {
            //Arrange
            int limit = 10;

            //Act
            int result = MultiplesOf3And5.Calculate(limit);

            //Assert
            Assert.Equal(23, result);
        }
        public void GetAllMultiplesBelowEdge(int edge, int expected)
        {
            //Arrange
            MultiplesOf3And5 multiplesOf3And5 = new MultiplesOf3And5();

            //Act
            int actual = multiplesOf3And5.GetSumBelow(edge);

            //Assert
            Assert.Equal(expected, actual);
        }
コード例 #11
0
        public void TestMethod2()
        {
            //Arrange
            int n        = 1000;
            int expected = 233168;

            //Act
            var res = MultiplesOf3And5.Solve(n);

            //Assert
            Assert.AreEqual(expected, res);
        }
コード例 #12
0
ファイル: UnitTest1.cs プロジェクト: Bubbhas/C---vningar
 public void MultiplesofThreeAndFive()
 {
     Assert.AreEqual(23, MultiplesOf3And5.MultiplesOfThreeAndFive(10));
 }
コード例 #13
0
        static void Main(string[] args)
        {
            StringBuilder description = new StringBuilder("Project Euler");

            description.AppendLine("Project Euler provides a large collection of challenges in the domain of computer science and mathematics.");
            description.AppendLine("The challenges typically involve writing a small program to figure out the solution");
            description.AppendLine("to a clever mathematical formula or equation, such as finding the sum of digits");
            description.AppendLine("of all numbers preceding each number in a series.\n");
            description.AppendLine("Bellow is a list of the problems to pick from to get a solution for\n");
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write(description);

            int id = -1;

            foreach (var value in Enum.GetValues(typeof(EulerProblems)))
            {
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.Write((int)value + ": " + value + "\n");
                id = (int)value;
            }

            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("\nType in a number to get Problems answers.\n");
            var input = Console.ReadKey();

            Console.WriteLine();

            // stops wrong inputs
            int number = 0;

            while (!Int32.TryParse(input.KeyChar.ToString(), out number) || (number > id || number == 0))
            {
                Console.Write("\nPick a number from the list of problems.\n");
                input = Console.ReadKey();
            }


            // Get a enum value to check agaisnt list
            if (Enum.IsDefined(typeof(EulerProblems), number))
            {
                var problem = (EulerProblems)number;
                Console.Clear();

                switch (problem)
                {
                case EulerProblems.MultiplesOf3And5:
                    MultiplesOf3And5.SolveMultiples();
                    break;

                case EulerProblems.EvenFibonacciNumbers:
                    EvenFibonacciNumbers.SolveEvenFibonacci();
                    break;

                case EulerProblems.LargestPrimeFactor:
                    LargestPrimeFactor.ComputeLargestPrime();
                    break;

                case EulerProblems.LargestPalindromeProduct:
                    LargestPalindromeProduct.GetLargestPalindrome();
                    break;
                }
            }

            // pause at the end
            Console.Read();
        }