public void Calculate_GetFibonacciNumberWhenNotInFibonacci()
        {
            var fibonacci = new FibonacciSequence();

            var result = fibonacci.Calculate(9);

            Assert.AreEqual("1 1 2 3 5 8 9", result);
        }
        public void Calculate_GetFibonacciNumber()
        {
            var fibonacci = new FibonacciSequence();

            var result = fibonacci.Calculate(5);

            Assert.AreEqual("1 1 2 3 5", result);
        }
Exemplo n.º 3
0
        public int Fibonacci(int n)
        {
            // Uncomment for the WaitingForm test
            //Thread.Sleep(2000);
            log.Info(String.Format("In : Fibonacci : n = {0}", n));
            int result = 0;

            try
            {
                result = FibonacciSequence.Calculate(n);
            }
            catch (Exception ex)
            {
                log.Error("Exception : Fibonacci : " + ex.Message);
            }
            return(result);
        }
        private async void GenerateClick(object sender, RoutedEventArgs e)
        {
            _tokenSource?.Cancel();
            _tokenSource = new CancellationTokenSource();

            // Grab values from screen
            var phi          = Phi.Value;
            var phiIncrement = PhiIncrement.Value;
            var points       = (int)Points.Value;
            var imageSize    = (int)ImageSize.Value;
            var imageCount   = (int)ImageCount.Value;
            var pointSize    = PointSize.Value;

            var tempPath = TempImagePath.Text;

            if (!Directory.Exists(tempPath))
            {
                Directory.CreateDirectory(tempPath);
            }

            var token = _tokenSource.Token;

            //ImagePanel.BeginInit();
            Status.Text = $"Creating {imageCount} images...";
            for (var i = 0; i < imageCount; i++)
            {
                var sequence = await Task.Run(
                    () => FibonacciSequence.Calculate(points, phi),
                    token);

                if (token.IsCancellationRequested)
                {
                    break;
                }

                var imagePath = $"{tempPath}Fibonacci_{points}_{phi:N3}.jpg";
                Status.Text = $"Exporting to {imagePath}";
                ImageGenerator.ExportToJpeg(sequence, imagePath, imageSize, imageSize, pointSize);
                AddImageToPanel(imagePath, imageSize);
                phi += phiIncrement;
            }

            //ImagePanel.EndInit();
            Status.Text = $"Created {imageCount} images";
        }
Exemplo n.º 5
0
        public void Should_Pass_When_ExpectedResultsAreReturned()
        {
            int result = FibonacciSequence.Calculate(6);

            Assert.AreEqual(8, result);
        }
Exemplo n.º 6
0
        public void Should_Pass_When_NIsSmallerThan1()
        {
            int result = FibonacciSequence.Calculate(-10);

            Assert.AreEqual(-1, result);
        }
Exemplo n.º 7
0
        public void Should_Pass_When_NIsGreaterThan100()
        {
            int result = FibonacciSequence.Calculate(102);

            Assert.AreEqual(-1, result);
        }