Пример #1
0
        public void Should_Return_CorrectResult_When_nthTerm_Is_100()
        {
            const int  nthTerm        = 100;
            BigInteger expectedResult = BigInteger.Parse("354224848179261915075");

            BigInteger result = Fibonacci.CalculateFibonacci(nthTerm);

            Assert.AreEqual(expectedResult, result);
        }
Пример #2
0
        public void Should_Return_CorrectResult_When_nthTerm_Is_10()
        {
            const int  nthTerm        = 10;
            BigInteger expectedResult = 55;

            BigInteger result = Fibonacci.CalculateFibonacci(nthTerm);

            Assert.AreEqual(expectedResult, result);
        }
Пример #3
0
        static void FibonacciMemoryCacheTest()
        {
            Console.WriteLine("Fibonacci MemoryCache test");
            var fibonacci = new Fibonacci(new MemoryCache <int>(fibonacciPrefix));

            for (var i = 1; i < 20; i++)
            {
                Console.WriteLine(fibonacci.CalculateFibonacci(i));
            }
        }
Пример #4
0
        static void FibonacciRedisCache()
        {
            Console.WriteLine("Fibonacci Redis test");

            var fibonacci = new Fibonacci(new RedisCache <int>("localhost", fibonacciPrefix));

            for (var i = 1; i < 20; i++)
            {
                Console.WriteLine(fibonacci.CalculateFibonacci(i));
            }
        }
Пример #5
0
        public void CalculateFibonacci_Postion_Negative_Should_Return_0()
        {
            //assemble
            int       postion       = -3;
            int       expectedValue = 0;
            Fibonacci fibonacci     = new Fibonacci();

            //act
            int actualValue = fibonacci.CalculateFibonacci(postion);

            //assert
            Assert.AreEqual(expectedValue, actualValue);
        }
Пример #6
0
        public void CalculateFibonacci_Postion_40_Should_Return_102334155()
        {
            //assemble
            int       postion       = 40;
            int       expectedValue = 102334155;
            Fibonacci fibonacci     = new Fibonacci();

            //act
            int actualValue = fibonacci.CalculateFibonacci(postion);

            //assert
            Assert.AreEqual(expectedValue, actualValue);
        }
        private static void RunFibonacci()
        {
            Console.WriteLine("Please enter a value for \"n\".");
            int n;

            if (!int.TryParse(Console.ReadLine(), out n))
            {
                throw new ArgumentException("Invalid input for n. It should be an Integer number.");
            }

            Fibonacci f = new Fibonacci();

            Console.WriteLine($"The nth term is: {f.CalculateFibonacci(n)}");
        }
Пример #8
0
 public void Should_Throw_Exception_When_nthTerm_Is_LessThan_0()
 {
     const int  nthTerm = -1;
     BigInteger result  = Fibonacci.CalculateFibonacci(nthTerm);
 }
        public void Input14()
        {
            Fibonacci f = new Fibonacci();

            Assert.Equal(377, f.CalculateFibonacci(14));
        }
        public void Input10()
        {
            Fibonacci f = new Fibonacci();

            Assert.Equal(55, f.CalculateFibonacci(10));
        }
        public void Input2()
        {
            Fibonacci f = new Fibonacci();

            Assert.Equal(1, f.CalculateFibonacci(2));
        }
        public void Input0()
        {
            Fibonacci f = new Fibonacci();

            Assert.Equal(0, f.CalculateFibonacci(0));
        }