public void FibonacciTests_ResultTest()
        {
            BigInteger[]             expected = new BigInteger[] { 0, 1, 1, 2, 3, 5, 8 };
            IEnumerable <BigInteger> actual   = FibonacciGenerator.GetFibonacciArray(7);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            FibonacciGenerator fg  = new FibonacciGenerator();
            BigInteger         num = fg.NextLargeNumber();
            BigInteger         result;
            int index = 4;

            while (true)
            {
                index++;
                result = num = fg.NextLargeNumber();

                bool outOfEdge = true;
                for (int i = 0; i < 999; i++)
                {
                    num = num / 10;
                    if (num == 0)
                    {
                        outOfEdge = false;
                        break;
                    }
                }
                if (outOfEdge)
                {
                    break;
                }
            }
            Console.WriteLine(result.ToString() + " index of " + index);
        }
        public void FibonacciTests_BiggerResultTest()
        {
            BigInteger[]             expected = new BigInteger[] { 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711 };
            IEnumerable <BigInteger> actual   = FibonacciGenerator.GetFibonacciArray(23);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.WriteLine("Fibonacci numers 1-15:");

            for (int i = 0; i < 15; i++)
            {
                Console.WriteLine($"{i+1}: {FibonacciNumber(i)}");
            }

            var generator = new FibonacciGenerator();

            foreach (var digit in generator.Generate(15))
            {
                Console.WriteLine(digit);
            }

            // Test the multiple folder
            List <IPet> pets = new List <IPet>
            {
                new Dog(),
                new Cat()
            };

            foreach (var pet in pets)
            {
                Console.WriteLine(pet.TalkToOwner());
            }
        }
Ejemplo n.º 5
0
        public int NextValue([PexAssumeUnderTest] FibonacciGenerator target)
        {
            int result = target.NextValue();

            return(result);
            // TODO: add assertions to method FibonacciGeneratorTest.NextValue(FibonacciGenerator)
        }
Ejemplo n.º 6
0
 public void GenerateFibonacciSequenceTests_OverflowException(int count, IEnumerable <int> expected)
 {
     // Arrange
     // Act
     // Assert
     Assert.ThrowsException <OverflowException>(() => FibonacciGenerator.GenerateFibonacciSequence(count).ToArray());
 }
Ejemplo n.º 7
0
        public void FibonacciGenerator_IsCorrect()
        {
            int quantity = 6;
            List <List <BigInteger> > expectedSequences = new List <List <BigInteger> > {
                new List <BigInteger> {
                    0
                },
                new List <BigInteger> {
                    0, 1
                }, new List <BigInteger> {
                    0, 1, 1
                }, new List <BigInteger> {
                    0, 1, 1, 2
                },
                new List <BigInteger> {
                    0, 1, 1, 2, 3
                }, new List <BigInteger> {
                    0, 1, 1, 2, 3, 5
                }
            };

            IEnumerable <BigInteger> actual;

            for (int i = 1; i <= quantity; i++)
            {
                actual = FibonacciGenerator.GenerateSequence(i);
                CollectionAssert.AreEqual(expectedSequences[i - 1], actual);
            }
        }
Ejemplo n.º 8
0
 static void LinqGeneratorExamples()
 {
     foreach (var number in FibonacciGenerator.Generate(10))
     {
         Console.WriteLine(number);
     }
 }
Ejemplo n.º 9
0
        public void PrintFizzBuzz()
        {
            var fSeries = new FibonacciGenerator();

            for (var i = 0; i < 10; i++)
            {
                var result = fSeries.GetNumber(i);
                if (result % 3 == 0 && result % 5 == 0)
                {
                    Console.WriteLine("FizzBuzz");
                }
                else if (result % 3 == 0)
                {
                    Console.WriteLine("Fizz");
                }
                else if (result % 5 == 0)
                {
                    Console.WriteLine("Buzz");
                }
                else
                {
                    Console.WriteLine(result);
                }
            }
        }
Ejemplo n.º 10
0
        public void GetNumber_When_0_Return_0()
        {
            var fSeries = new FibonacciGenerator();

            var result = fSeries.GetNumber(0);

            Assert.IsTrue(result == 0);
        }
Ejemplo n.º 11
0
        public void GetNumber_When_8_Return_21()
        {
            var fSeries = new FibonacciGenerator();

            var result = fSeries.GetNumber(8);

            Assert.AreEqual(21, result);
        }
Ejemplo n.º 12
0
        public void GetNumber_When_4_Return_3()
        {
            var fSeries = new FibonacciGenerator();

            var result = fSeries.GetNumber(4);

            Assert.AreEqual(3, result);
        }
Ejemplo n.º 13
0
        public void GetSequenceTest()
        {
            var fib = new FibonacciGenerator(new SystemRuntimeCacher());

            for (var i = 0; i < 20; i++)
            {
                _output.WriteLine($"{fib.Next}");
            }
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            var firstTerm = FibonacciGenerator.Generate(repeatingOnes: true)
                            .TakeWhile(t => t.ToString().Length < 1000)
                            .Count();

            Console.WriteLine(firstTerm + 1);
            Console.ReadKey();
        }
Ejemplo n.º 15
0
    public void GenerateReturnsSequence()
    {
        List <int> expectedList = new List <int> {
            0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377
        };
        IEnumerable <int> generatedList = new FibonacciGenerator().Generate(15);

        Assert.Equal(expectedList, generatedList);
    }
Ejemplo n.º 16
0
        public void Generate_CorrectData_CorrectResult(int count, int[] expected)
        {
            int i = 0;

            foreach (var actual in FibonacciGenerator.Generate(count))
            {
                Assert.AreEqual((BigInteger)expected[i++], actual);
            }
        }
Ejemplo n.º 17
0
        public static void Main(string[] args)
        {
            var generator = new FibonacciGenerator();

            foreach (var digit in generator.Generate(15))
            {
                Console.WriteLine(digit);
            }
        }
Ejemplo n.º 18
0
        public void GenerateFibonacciSequenceTests(int count, IEnumerable <int> expected)
        {
            // Arrange
            // Act
            var result = FibonacciGenerator.GenerateFibonacciSequence(count);

            // Assert
            CollectionAssert.AreEqual(expected.ToArray(), result.ToArray());
        }
Ejemplo n.º 19
0
    public void TestPrivateFibViaRelfection(Fib fibData)
    {
        FibonacciGenerator fibonacciGenerator = new FibonacciGenerator();
        MethodInfo         methodInfo         = typeof(FibonacciGenerator).GetMethod("Fib", BindingFlags.NonPublic | BindingFlags.Instance);

        object[] parameters = { fibData.InitialValue };
        int      retVal     = (int)methodInfo.Invoke(fibonacciGenerator, parameters);

        Assert.Equal(fibData.ExpectedValue, retVal);
    }
        public void NextValue317()
        {
            FibonacciGenerator fibonacciGenerator;
            int i;

            fibonacciGenerator = new FibonacciGenerator();
            i = this.NextValue(fibonacciGenerator);
            Assert.AreEqual <int>(2, i);
            Assert.IsNotNull((object)fibonacciGenerator);
        }
Ejemplo n.º 21
0
        public void GetSequenceTest()
        {
            var fib = new FibonacciGenerator(
                new RedisRemoteCacher(_configuration["redis:endpoint"],
                                      _configuration["redis:password"]));

            for (var i = 0; i < 20; i++)
            {
                _output.WriteLine($"{fib.Next}");
            }
        }
Ejemplo n.º 22
0
        static void Main(string[] args)
        {
            var answer = FibonacciGenerator.Generate()
                         .TakeWhile((value) => value <= 4000000)
                         .Where(v => v % 2 == 0)
                         .Select(v => (int)v)
                         .Sum();

            Console.WriteLine(answer);
            Console.ReadKey();
        }
Ejemplo n.º 23
0
        public static void PrintFibonacciUntilIndexYield(uint index)
        {
            FibonacciGenerator fibonacciGenerator = new FibonacciGenerator();
            int counter = 0;

            foreach (int number in fibonacciGenerator)
            {
                Console.Write(number + " ");
                fibonacciGenerator.generate = ++counter < index;
            }
            Console.WriteLine();
        }
Ejemplo n.º 24
0
 public ActionResult Fibonacci(FibonacciTool ft)
 {
     if (ModelState.IsValid)
     {
         var generator     = new FibonacciGenerator();
         var fibonacciList = generator.FindFibs(ft.NumberOfFibs.Value);
         ft.FibonacciList = fibonacciList;
         return(View("Fibonacci", ft));
     }
     ft.FibonacciList = new List <ulong>();
     return(View("Fibonacci", ft));
 }
Ejemplo n.º 25
0
        public void GetFibonacciSequence_RangeOfSequenceLengths_FibonacciSequence(int length,
                                                                                  long[] expectedSequence)
        {
            BigInteger[] expected = new BigInteger[length];
            for (var i = 0; i < length; i++)
            {
                expected[i] = new BigInteger(expectedSequence[i]);
            }

            var actualSequence = FibonacciGenerator.GetFibonacciSequence(length);

            Assert.AreEqual(expected, actualSequence);
        }
        public void FibonacciGenerator_ValidInput_ValidResult2()
        {
            BigInteger[] expected =
            {
                0,                1,         1,         2,         3,         5,          8,       13,       21,     34,     55, 89, 144, 233, 377, 610, 987, 1597, 2584,
                4181,          6765,     10946,     17711,     28657,     46368,      75025,   121393,   196418, 317811, 514229,
                832040,     1346269,   2178309,   3524578,   5702887,   9227465,   14930352, 24157817, 39088169,
                63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903
            };

            IEnumerable <BigInteger> actual = FibonacciGenerator.GenerateSequence(expected.Length);

            CollectionAssert.AreEqual(expected, actual);
        }
Ejemplo n.º 27
0
        static void Main(string[] args)
        {
            int count = 0;

            foreach (var i in FibonacciGenerator.GenerateWithYield())
            {
                Console.WriteLine(i);
                if (count++ == 10)
                {
                    break;
                }
            }

            Console.ReadLine();
        }
Ejemplo n.º 28
0
        public string Solve()
        {
            int i = 0;

            while (FibonacciGenerator.Generate(i).ToString().Length < 1000)
            {
                i++;
                if (i == int.MaxValue)
                {
                    throw new Exception("Index is too large to calculate");
                }
            }

            return(i.ToString());
        }
Ejemplo n.º 29
0
        static void Main(string[] args)
        {
            int runningTotal = 0;
            FibonacciGenerator generator = new FibonacciGenerator(MAX_VALUE);
            foreach(int nextInSeq in generator)
            {
                if (nextInSeq % 2 == 0)
                {
                    runningTotal += nextInSeq;
                }
            }

            Console.WriteLine(String.Format("The anwser is {0}.", runningTotal));
            Console.ReadKey();
        }
        public void FibonacciGenerator_ValidInput_ValidResult1()
        {
            BigInteger[] expected =
            {
                0,                       1,            1,            2,            3,             5,             8,          13,       21,     34,     55, 89, 144, 233, 377, 610, 987, 1597, 2584,
                4181,                 6765,        10946,        17711,        28657,         46368,         75025,      121393,   196418, 317811, 514229,
                832040,            1346269,      2178309,      3524578,      5702887,       9227465,      14930352,    24157817, 39088169,
                63245986,        102334155,    165580141,    267914296,    433494437,     701408733,    1134903170,  1836311903,
                2971215073,     4807526976,   7778742049,  12586269025,  20365011074,   32951280099,   53316291173, 86267571272,
                139583862445, 225851433717, 365435296162, 591286729879, 956722026041, 1548008755920, 2504730781961, 4052739537881
            };

            IEnumerable <BigInteger> actual = FibonacciGenerator.GenerateSequence(expected.Length);

            CollectionAssert.AreEqual(expected, actual);
        }
Ejemplo n.º 31
0
        public void GeneratorFibonacci_3_DoneArray()
        {
            List <BigInteger> actual = new List <BigInteger>();

            foreach (BigInteger el in FibonacciGenerator.GeneratorFibonacci(3))
            {
                actual.Add(el);
            }

            List <BigInteger> expected = new List <BigInteger>()
            {
                new BigInteger(1), new BigInteger(1), new BigInteger(2)
            };

            CollectionAssert.AreEqual(expected, actual);
        }
Ejemplo n.º 32
0
 public Problem2()
 {
     fibonacciGenerator = new FibonacciGenerator(0, 4000000);
     Run();
 }