示例#1
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);
        }
示例#2
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());
        }
示例#3
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);
        }