public static int Run(int from, int to, IConsole console)
        {
            if (from < 0 || to < 0)
            {
                console.Error.WriteLine($"Error: { nameof(from) } and { nameof(to) } must be at least 0");
                return(1);
            }

            // Display result
            console.Out.Write($"Result: ");
            int result;

            if (from < to)
            {
                while (from <= to)
                {
                    // Execute
                    result = NthFibonacci.FibonacciIterative(from);

                    // Display result
                    console.Out.Write($"{ result } ");

                    from++;
                }
            }
            else
            {
                while (from >= to)
                {
                    result = NthFibonacci.FibonacciIterative(from);
                    console.Out.Write($"{ result } ");

                    from--;
                }
            }

            console.Out.WriteLine();

            return(0);
        }
Exemplo n.º 2
0
        public void FibonacciIterative_WhenNLessThanZero_ThrowsArgumentException()
        {
            Action actual = () => NthFibonacci.FibonacciIterative(-1);

            Assert.Throws <ArgumentException>(actual);
        }
Exemplo n.º 3
0
        public void FibonacciIterative_WhenNGreaterThanZero_ReturnsValidResult(int n, int expected)
        {
            var actual = NthFibonacci.FibonacciIterative(n);

            Assert.Equal(expected, actual);
        }