예제 #1
0
        public void ShouldReturnTheFactorialWebServiceResult()
        {
            _factorialWebService.Stub(s => s.GetFactorialFor(
                                          "https://murmuring-ravine-8545.herokuapp.com/?n=1000"))
            .Return("very big number");

            var actualResult = _factorialCalculator.Calculate(1000);

            Assert.AreEqual("very big number", actualResult);
        }
예제 #2
0
        private void FactorialOf(int number, int shouldBe)
        {
            var actualFactorial   = _factorialCalculator.Calculate(number);
            var expectedFactorial = shouldBe;

            Assert.AreEqual(expectedFactorial, actualFactorial);
        }
예제 #3
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));
            }
        }
예제 #4
0
        public void TestFactorialOutsideLimit()
        {
            FactorialCalculator facCal = new FactorialCalculator();

            var exception = Assert.Throws <System.NotSupportedException>(() => facCal.Calculate(11));

            Assert.That(exception.Message, Is.EqualTo("n > 10 is not supported"));
        }
예제 #5
0
        static void Main(string[] args)
        {
            var random     = new System.Random();
            var calculator = new FactorialCalculator();

            while (true)
            {
                var value = random.Next(1, 10);

                var result = calculator.Calculate(value);

                Console.WriteLine($"Faktoriál hodnoty {value} je {result}!");
            }
        }
예제 #6
0
        static void Main(string[] args)
        {
            string line       = null;
            var    calculator = new FactorialCalculator();

            do
            {
                if (Int32.TryParse(line, out var value))
                {
                    var result = calculator.Calculate(value);

                    Console.WriteLine($"Faktoriál hodnoty {value} je {result}!");
                }

                Console.WriteLine($"Zadejte hodnotu pro výpočet faktoriálu:");
                line = Console.ReadLine();
            } while (line.ToLower() != "y");
        }
예제 #7
0
 public IActionResult GetFactorial(int n) => Ok(new CalculationResponse(_factorialCalculator.Calculate(n)));
예제 #8
0
        public void Test_less_than_10(int input, int output)
        {
            int result = factorialCalculator.Calculate(input);

            Assert.AreEqual(output, result);
        }
예제 #9
0
        public int TestFactorialInLimit(int number)
        {
            FactorialCalculator facCal = new FactorialCalculator();

            return(facCal.Calculate(number));
        }