public void BenchmarkApplicationTenTimes()
        {
            // Arrange
            var grid = new Grid(new FibonacciCheckerService());
            var gridCellUpdaterService   = new GridCellUpdaterService();
            var fibonacciNeighborService = new FibonacciNeighborService();
            var fibonacciSequenceService = new FibonacciSequenceService();


            foreach (var i in Enumerable.Range(0, 10))
            {
                // Act
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                gridCellUpdaterService.UpdateCell(grid, 1, 25, 25);
                gridCellUpdaterService.UpdateCell(grid, 1, 26, 27);
                gridCellUpdaterService.UpdateCell(grid, 2, 26, 28);
                gridCellUpdaterService.UpdateCell(grid, 4, 26, 29);
                gridCellUpdaterService.UpdateCell(grid, 7, 26, 30);
                gridCellUpdaterService.UpdateCell(grid, 12, 26, 31);
                var fibonacciCells = gridCellUpdaterService.UpdateCell(grid, 20, 26, 32);

                var fibonacciNeighbors = fibonacciNeighborService.FindNeighbors(grid, fibonacciCells);
                fibonacciSequenceService.FindFibonacciSequences(fibonacciNeighbors);
                stopwatch.Stop();

                // Report
                Console.WriteLine(stopwatch.Elapsed);
            }
        }
        public void Given_Grid_When_UpdatingValue_Expect_UpdatedCorrectIsFibonacci()
        {
            // Arrange
            var grid = new Grid(new FibonacciCheckerService());
            var gridCellUpdaterService = new GridCellUpdaterService();

            const int increment   = 4;
            const int rowIndex    = 25;
            const int columnIndex = 25;

            // Act
            gridCellUpdaterService.UpdateCell(grid, increment, columnIndex, rowIndex);

            // Assert
            var updatedCell = grid.FibonacciGrid[rowIndex, columnIndex];

            Assert.False(updatedCell.IsFibonacci);
        }
예제 #3
0
        public void Given_Grid_When_IncrementingWithOne_Expect_ZeroFibonacciSequences()
        {
            // Arrange
            var grid = new Grid(new FibonacciCheckerService());
            var gridCellUpdaterService   = new GridCellUpdaterService();
            var fibonacciNeighborService = new FibonacciNeighborService();
            var fibonacciSequenceService = new FibonacciSequenceService();

            const int rowIndex    = 25;
            const int columnIndex = 25;

            // Act
            var fibonacciCells     = gridCellUpdaterService.UpdateCell(grid, 1, rowIndex, columnIndex);
            var fibonacciNeighbors = fibonacciNeighborService.FindNeighbors(grid, fibonacciCells);
            var sequenceCells      = fibonacciSequenceService.FindFibonacciSequences(fibonacciNeighbors);

            // Assert
            Assert.AreEqual(0, sequenceCells.Count());
        }
예제 #4
0
        public void Given_Grid_When_IncrementingCellsToAFibonacciSequence_Expect_FiveGridCellsInList()
        {
            // Arrange
            var grid = new Grid(new FibonacciCheckerService());
            var gridCellUpdaterService   = new GridCellUpdaterService();
            var fibonacciNeighborService = new FibonacciNeighborService();
            var fibonacciSequenceService = new FibonacciSequenceService();

            // Act
            gridCellUpdaterService.UpdateCell(grid, 1, 25, 25);
            gridCellUpdaterService.UpdateCell(grid, 1, 26, 27);
            gridCellUpdaterService.UpdateCell(grid, 2, 26, 28);
            var fibonacciCells = gridCellUpdaterService.UpdateCell(grid, 4, 26, 29);

            var fibonacciNeighbors = fibonacciNeighborService.FindNeighbors(grid, fibonacciCells);
            var sequenceCells      = fibonacciSequenceService.FindFibonacciSequences(fibonacciNeighbors);

            // Assert
            Assert.AreEqual(5, sequenceCells.Count());
        }
        public void Given_Grid_When_UpdatingValue_Expect_AllAffectedCellsUpdated()
        {
            // Arrange
            var grid = new Grid(new FibonacciCheckerService());
            var gridCellUpdaterService = new GridCellUpdaterService();

            const int increment   = 5;
            const int rowIndex    = 25;
            const int columnIndex = 25;

            // Act
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            gridCellUpdaterService.UpdateCell(grid, increment, columnIndex, rowIndex);
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed);

            // Assert
            stopwatch.Start();
            for (var row = 0; row < grid.FibonacciGrid.GetLength(0); row++)
            {
                var updatedCell = grid.FibonacciGrid[row, columnIndex];
                Assert.AreEqual(increment, updatedCell.Value);
                Assert.True(updatedCell.IsFibonacci);
            }

            for (var column = 0; column < grid.FibonacciGrid.GetLength(1); column++)
            {
                if (column == columnIndex)
                {
                    continue;
                }
                var updatedCell = grid.FibonacciGrid[rowIndex, column];
                Assert.AreEqual(increment, updatedCell.Value);
                Assert.True(updatedCell.IsFibonacci);
            }
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed);
        }