Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }