public void Given_InterruptedSequentialFibonacciSequence_WhenFindingFibonacciSequence_Expect_FiveCellsReturned()
        {
            // Arrange
            var fibonacciSequenceService = new FibonacciSequenceService();

            var fibonacciCheckerService = Mock.Of <IFibonacciCheckerService>();

            Mock.Get(fibonacciCheckerService).Setup(service => service.IsFibonacci(It.IsAny <int>())).Returns(true);

            var fibonacciCellList = new List <GridCell>();

            foreach (var number in new[] { 0, 1, 2, 3, 5, 8, 10, 13 })
            {
                var gridCell = new GridCell(fibonacciCheckerService);
                gridCell.IncrementGridCellValue(number);
                fibonacciCellList.Add(gridCell);
            }

            // Act
            var sequenceCells = fibonacciSequenceService.FindFibonacciSequences(new List <List <GridCell> > {
                fibonacciCellList
            });

            // Assert
            Assert.AreEqual(5, sequenceCells.Count);
        }
        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);
            }
        }
Esempio n. 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());
        }
        public void Given_GridCellWithNonFibonacciValue_WhenFindingFibonacciSequence_Expect_ArgumentException()
        {
            // Arrange
            var fibonacciSequenceService = new FibonacciSequenceService();

            var fibonacciCheckerService = Mock.Of <IFibonacciCheckerService>();

            Mock.Get(fibonacciCheckerService).Setup(service => service.IsFibonacci(It.IsAny <int>())).Returns(false);
            var gridCell = new GridCell(fibonacciCheckerService);

            gridCell.IncrementGridCellValue(4);

            // Act && Assert
            Assert.Throws <ArgumentException>(() => fibonacciSequenceService.FindFibonacciSequences(new List <List <GridCell> > {
                new List <GridCell> {
                    gridCell
                }
            }));
        }
Esempio n. 5
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());
        }