Example #1
0
        public void SetNeighboursToAllCellsShouldSetEightNeighboursToMiddleCells()
        {
            // Arrange
            var grid = MockGrid.Context();

            var gridService       = new GridService(grid);
            var cellActionService = new CellActionService(gridService);
            var twoDGridService   = new TwoDGridActionService(grid, cellActionService);

            // Act
            twoDGridService.SetNeighboursToAllCells();

            // Assert
            grid[1][2]
            .Neighbours
            .Count
            .Should()
            .Be(8);

            grid[2][2]
            .Neighbours
            .Count
            .Should()
            .Be(8);
        }
Example #2
0
        public void CountOfTargetBeingGreenWithSetTargetSellAfterGenerateShouldReturnRigthCount()
        {
            // Arrange
            var grid = MockGrid.Context();

            var gridService       = new GridService(grid);
            var cellActionService = new CellActionService(gridService);
            var twoDGridService   = new TwoDGridActionService(grid, cellActionService);

            var targetY            = 2;
            var targetX            = 2;
            var numberOfGeneration = 15;

            twoDGridService.SetNeighboursToAllCells();
            twoDGridService.SetTargetCell(targetY, targetX);

            // Act
            twoDGridService.Generate(numberOfGeneration);

            // Assert
            twoDGridService
            .GetCountOfTargetBeingGreen()
            .Should()
            .Be(14);
        }
Example #3
0
        public void GetCountOfTargetBeingGreenReturnsZeroWithNotSetTargetCell()
        {
            // Arrange
            var grid = MockGrid.Context();

            var gridService       = new GridService(grid);
            var cellActionService = new CellActionService(gridService);
            var twoDGridService   = new TwoDGridActionService(grid, cellActionService);

            // Act

            // Assert
            twoDGridService
            .GetCountOfTargetBeingGreen()
            .Should()
            .Be(0);
        }
Example #4
0
        public void Start()
        {
            var sizeTokensForGrid = Console.ReadLine()
                                    .Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                    .Select(int.Parse)
                                    .ToArray();

            var width  = sizeTokensForGrid[0];
            var height = sizeTokensForGrid[1];

            Cell[][]               grid        = new Cell[height][];
            IGridService           gridService = new GridService(grid);
            ICellActionService     cellAction  = new CellActionService(gridService);
            ITwoDGridActionService gridAction  = new TwoDGridActionService(grid, cellAction);

            for (int row = 0; row < height; row++)
            {
                var inputRowValues = Console.ReadLine()
                                     .ToCharArray()
                                     .Select(x => int.Parse(x.ToString()))
                                     .ToArray();

                var gridRow = new Cell[width];
                for (int col = 0; col < inputRowValues.Length; col++)
                {
                    gridRow[col] = new Cell(row, col, inputRowValues[col]);
                }
                gridAction.AddRow(gridRow, row);
            }
            gridAction.SetNeighboursToAllCells();

            var startPointRotationTokens = Console.ReadLine()
                                           .Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                           .Select(int.Parse)
                                           .ToArray();

            var targetX         = startPointRotationTokens[0];
            var targetY         = startPointRotationTokens[1];
            var generationCount = startPointRotationTokens[2];

            gridAction.SetTargetCell(targetY, targetX);
            gridAction.Generate(generationCount);

            Console.WriteLine(gridAction.GetCountOfTargetBeingGreen());
        }
        public void AddNeighboursShouldSetEightNeighboursToMiddleCell()
        {
            // Arrange
            var grid = MockGrid.Context();

            var gridService       = new GridService(grid);
            var cellActionService = new CellActionService(gridService);

            // Act
            cellActionService.AddNeighbours(grid[1][2]);

            // Assert
            grid[1][2]
            .Neighbours
            .Count
            .Should()
            .Be(8);
        }
        public void AddNeighboursShouldSetFiveNeighboursToSideCell()
        {
            // Arrange
            var grid = MockGrid.Context();

            var gridService       = new GridService(grid);
            var cellActionService = new CellActionService(gridService);

            // Act
            cellActionService.AddNeighbours(grid[0][1]);

            // Assert
            grid[0][1]
            .Neighbours
            .Count
            .Should()
            .Be(5);
        }
        public void AddNeighboursShouldSetThreeNeighboursToCornerCell()
        {
            // Arrange
            var grid = MockGrid.Context();

            var gridService       = new GridService(grid);
            var cellActionService = new CellActionService(gridService);

            // Act
            cellActionService.AddNeighbours(grid[0][0]);

            // Assert
            grid[0][0]
            .Neighbours
            .Count
            .Should()
            .Be(3);
        }
Example #8
0
        public void GenerateWithoutSetTargetSellShouldThrowNullReferenceException()
        {
            // Arrange
            var grid = MockGrid.Context();

            var gridService       = new GridService(grid);
            var cellActionService = new CellActionService(gridService);
            var twoDGridService   = new TwoDGridActionService(grid, cellActionService);

            var numberOfGeneration = 15;

            // Act
            Action action = () => twoDGridService.Generate(numberOfGeneration);

            // Assert
            action
            .Should()
            .Throw <NullReferenceException>();
        }
Example #9
0
        public void AddRowShouldAddSuccessfullyRowIntoTheGrid()
        {
            // Arrange
            var grid = new Cell[4][];

            var gridService       = new GridService(grid);
            var cellActionService = new CellActionService(gridService);
            var twoDGridService   = new TwoDGridActionService(grid, cellActionService);

            var rowIndex       = 0;
            var testingRowData = new Cell[]
            {
                new Cell(rowIndex, 0, 1),
                new Cell(rowIndex, 1, 0),
                new Cell(rowIndex, 2, 1),
                new Cell(rowIndex, 3, 0)
            };

            // Act
            twoDGridService.AddRow(testingRowData, rowIndex);

            // Assert
            grid[0][0]
            .EvenColourState
            .Should()
            .Be(1);

            grid[0][1]
            .EvenColourState
            .Should()
            .Be(0);

            grid[0][2]
            .EvenColourState
            .Should()
            .Be(1);

            grid[0][3]
            .EvenColourState
            .Should()
            .Be(0);
        }
        public void EvenChangeStateShouldSetTheCellCorrectly()
        {
            // Arrange
            var grid = MockGrid.Context();

            var gridService       = new GridService(grid);
            var cellActionService = new CellActionService(gridService);
            var twoDGridService   = new TwoDGridActionService(grid, cellActionService);

            twoDGridService.SetNeighboursToAllCells();

            // Act
            cellActionService.EvenChangeState(grid[2][2]);

            // Assert
            grid[2][2]
            .OddColourState
            .Should()
            .Be(0);
        }
Example #11
0
        public void GetCountOfTargetBeingGreenReturnsZeroWithSetTargetCellEqualToRedColour()
        {
            // Arrange
            var grid = MockGrid.Context();

            var gridService       = new GridService(grid);
            var cellActionService = new CellActionService(gridService);
            var twoDGridService   = new TwoDGridActionService(grid, cellActionService);

            var targetY = 0;
            var targetX = 1;

            // Act
            twoDGridService.SetTargetCell(targetY, targetX);

            // Assert
            twoDGridService
            .GetCountOfTargetBeingGreen()
            .Should()
            .Be(0);
        }
Example #12
0
        public void SetNeighboursToAllCellsShouldSetThreeNeighboursToCornerCells()
        {
            // Arrange
            var grid = MockGrid.Context();

            var gridService       = new GridService(grid);
            var cellActionService = new CellActionService(gridService);
            var twoDGridService   = new TwoDGridActionService(grid, cellActionService);

            // Act
            twoDGridService.SetNeighboursToAllCells();

            // Assert
            grid[0][0]
            .Neighbours
            .Count
            .Should()
            .Be(3);

            grid[3][3]
            .Neighbours
            .Count
            .Should()
            .Be(3);

            grid[3][0]
            .Neighbours
            .Count
            .Should()
            .Be(3);

            grid[0][3]
            .Neighbours
            .Count
            .Should()
            .Be(3);
        }