Exemple #1
0
        public void FibonacciSumTest()
        {
            var actual   = FibonacciHelper.FibonacciSum(6);
            var expected = 12;

            Assert.AreEqual(expected, actual);
        }
        public void FibonacciValeurDix()
        {
            FibonacciHelper test   = new FibonacciHelper();
            int             valeur = test.Fibonacci(10);

            Assert.AreEqual(valeur, 55);
        }
Exemple #3
0
        public void when_input_3_should_return_2()
        {
            var actual   = new FibonacciHelper().GetSum(3);
            var expected = 2;

            Assert.AreEqual(expected, actual);
        }
Exemple #4
0
        public void when_input_12_should_return_144()
        {
            var actual   = new FibonacciHelper().GetSum(12);
            var expected = 144;

            Assert.AreEqual(expected, actual);
        }
        public void ReturnTheNthNumber(int number, int expectedValue)
        {
            var sut    = new FibonacciHelper();
            var result = sut.GetNumber(number);

            Assert.Equal(expectedValue, result);
        }
        public void FibonacciValeurUn()
        {
            FibonacciHelper test   = new FibonacciHelper();
            int             valeur = test.Fibonacci(1);

            Assert.AreEqual(valeur, 1);
        }
        public void FibonacciValeurZero()
        {
            FibonacciHelper test   = new FibonacciHelper();
            int             valeur = test.Fibonacci(0);

            Assert.AreEqual(valeur, -1);
        }
        public void ReturnTheSequence(int number, int[] expectedSequence)
        {
            var sut    = new FibonacciHelper();
            var result = sut.GetSequenceUpTo(number);

            Assert.NotNull(result);
            Assert.Equal(expectedSequence, result);
        }
        public void RatePerSecond_BasicVerification()
        {
            var counter = new RatePerSecond();

            foreach (var item in FibonacciHelper.ComputeTo(47).Skip(7).Take(7))
            {
                counter.Increment(item);
            }
            Assert.AreEqual(589, counter.Value);
        }
Exemple #10
0
        static void Main(string[] args)
        {
            var option = 9;

            switch (option)
            {
            case 1:
                UniqueChecker.Run();
                break;

            case 2:
                Permutation.Run();
                break;

            case 3:
                StringCompression.Run();
                break;

            case 4:
                StringChecker.Run();
                break;

            case 5:
                MatrixModifier.Run();
                break;

            case 6:
                ImageRotation.Run();
                break;

            case 7:
                LinkedListDeduplicator.Run();
                break;

            case 8:
                BitManipulationHelper.Run();
                break;

            case 9:
                FibonacciHelper.Run();
                break;

            default:
                Console.WriteLine("No option selected.");
                break;
            }

            Console.WriteLine("Press any key to close this app.");
            Console.ReadKey();
        }
        public void Problem25()
        {
            long maxIndex = 1000;
            bool stop     = false;
            Dictionary <long, BigInteger> fibonacci = new Dictionary <long, BigInteger>();

            while (!stop)
            {
                fibonacci = FibonacciHelper.ConstructFibonacciSequenceUptoIndex(maxIndex);
                stop      = fibonacci.Values.Max().ToString().Length >= 1000;
                maxIndex += maxIndex;
            }

            Assert.Equal(4782, fibonacci.First(x => x.Value.ToString().Length == 1000).Key);
        }
        public void MeanAverage_BasicVerification()
        {
            var counter             = new MeanAverage();
            var expectedCount       = 0L;
            var expectedTotalCounts = 0L;

            foreach (var count in FibonacciHelper.ComputeTo(47))
            {
                counter.Increment(count);
                (counter.Denominator as ISupportsIncrement <long>)?.Increment();
                expectedCount       += count;
                expectedTotalCounts += 1;
                Assert.AreEqual(expectedCount / expectedTotalCounts, counter.Value);
            }
        }
        public void Problem2()
        {
            long maxValue = 4000000;
            long maxIndex = 100;
            bool stop     = false;
            Dictionary <long, BigInteger> fibonacci = new Dictionary <long, BigInteger>();

            while (!stop)
            {
                fibonacci = FibonacciHelper.ConstructFibonacciSequenceUptoIndex(maxIndex);
                stop      = fibonacci.Values.Max() >= maxValue;
                maxIndex += maxIndex;
            }

            Assert.Equal(4613732, fibonacci.Values.Where(x => x < maxValue && x % 2 == 0).Aggregate(BigInteger.Add));
        }
Exemple #14
0
        protected override string Solve()
        {
            long result = 0;

            IEnumerable <long> sequence = FibonacciHelper.GetSequenceFromMax(4000000);

            foreach (long number in sequence)
            {
                if (number % 2 == 0)
                {
                    result += number;
                }
            }

            return(result.ToString("0"));
        }
        public void MovingAverage_BasicVerification()
        {
            var seriesLength  = byte.MaxValue;
            var counter       = new MovingAverage(seriesLength);
            var series        = new Queue <long>();
            var approximation = 0L;

            foreach (var count in FibonacciHelper.ComputeTo(47))
            {
                counter.Increment(count);
                series.Enqueue(count);
                approximation += count;
                if (series.Count > seriesLength)
                {
                    approximation -= series.Dequeue();
                }
                Assert.AreEqual(approximation / seriesLength, counter.Value);
            }
        }
Exemple #16
0
        public void MedianAverage_BasicVerification()
        {
            var counter = new MedianAverage();

            // verify 'tween' result
            // with initial series: 1,1,2,3,5,8,13,21,34,55,89 !,! 144,233,377,610,987,1597,2584,4181,6765,10946,17711
            foreach (var count in FibonacciHelper.ComputeTo(21))
            {
                counter.Increment(count);
            }
            Assert.AreEqual(72, counter.Value);

            // verify 'non-tween' result
            // with additional series: 34,55,89,144,233,377, !610! ,987,1597,2584,4181,6765,10946,17711
            foreach (var count in FibonacciHelper.ComputeTo(27).Skip(8))
            {
                counter.Increment(count);
            }
            Assert.AreEqual(377, counter.Value);

            // verify performant enough not to timeout test tool
            var fib = FibonacciHelper.ComputeTo(127).ToArray();

            for (int i = 0; i < ushort.MaxValue; i++)
            {
                counter.Increment(fib[i++ % fib.Length]);
            }
            Assert.AreEqual(4807526976, counter.Value);

            // confirm outlier does not pull average
            counter.Reset();
            counter.Increment(1);
            counter.Increment(1);
            counter.Increment(1);
            counter.Increment(int.MaxValue);
            Assert.AreEqual(1, counter.Value);
        }
Exemple #17
0
 public void FibonacciSumExceptionTest()
 {
     FibonacciHelper.FibonacciSum(0);
 }
 public IHttpActionResult Get(int number)
 {
     return(Ok <bool>(FibonacciHelper.IsFibonacciNumber(number)));
 }