public void TestCalculateFactorial(int n, int expectedFactorial)
        {
            var factorialCalculator = new FactorialCalculator();
            var actualFactorial     = factorialCalculator.Factorial(n);

            Assert.AreEqual(expectedFactorial, actualFactorial);
        }
예제 #2
0
        public void FactorialTest()
        {
            var fac = new FactorialCalculator();
            // var result1 = fac.Factorial(3);
            // Console.WriteLine(result1);

            var result2 = fac.Factorial(10);

            Console.WriteLine(result2);
        }
예제 #3
0
        private static double GetNumberOfCombinations(int objectsCount, int objectsCountInCombination)
        {
            var diff = objectsCount - objectsCountInCombination;

            if (diff == 0)
            {
                return(1);
            }

            var divident = FactorialCalculator.Factorial(objectsCount);
            var divisor  = FactorialCalculator.Factorial(objectsCountInCombination) * FactorialCalculator.Factorial(diff);

            var numberOfCombinations = divident / divisor;

            return(numberOfCombinations);
        }
예제 #4
0
        public void TestFactorial()
        {
            var calculator = new FactorialCalculator();

            var expected = Enumerable.Range(1, 10).Select(i => new { i, r = calculator.Factorial(i) }).ToDictionary(key => key.i, value => value.r);

            foreach (var pair in expected)
            {
                Assert.AreEqual(pair.Value, calculator.Calculate(pair.Key).Match(x => x, x => x.Value));
            }

            foreach (var pair in expected)
            {
                Assert.AreEqual(pair.Value, calculator.Calculate(pair.Key).Match(x => x, x => x.Value));
            }
        }
예제 #5
0
        public void Returns_Factorial(int value, int expectedFactorial)
        {
            var calculatedFactorial = _calculator.Factorial(value);

            Assert.AreEqual(expectedFactorial, calculatedFactorial);
        }