Exemplo n.º 1
0
        public void WhenGivenNoSeedCoords_SeedGrid_CreatesGridWithAllDeadCells()
        {
            List <Tuple <int, int> > seedCoords = new List <Tuple <int, int> >();

            Domain.IGridService gridService = new Domain.GridService(new Moq.Mock <ICellService>().Object);

            Grid grid = gridService.SeedGrid(10, 10, seedCoords);

            int totalAliveCells = grid.Cells.Sum(x => x.Count(y => y.State == CellState.alive));

            Assert.True(totalAliveCells == 0);
        }
Exemplo n.º 2
0
        public void WhenGivenHeightAndWidth_SeedGrid_CreatesGridWithCorrectDimensions()
        {
            int height = 10;
            int width  = 8;
            List <Tuple <int, int> > seedCoords = new List <Tuple <int, int> >();

            Domain.IGridService gridService = new Domain.GridService(new Moq.Mock <ICellService>().Object);

            Grid grid = gridService.SeedGrid(height, width, seedCoords);

            Assert.True(grid.Height == height && grid.Width == width);
        }
Exemplo n.º 3
0
        public void WhenGivenOneSeedCoord_SeedGrid_CreatesGridWithCorrectCellAlive()
        {
            int xCoord = 3;
            int yCoord = 2;
            List <Tuple <int, int> > seedCoords = new List <Tuple <int, int> >();

            seedCoords.Add(new Tuple <int, int>(xCoord, yCoord));
            Domain.IGridService gridService = new Domain.GridService(new Moq.Mock <ICellService>().Object);

            Grid grid = gridService.SeedGrid(10, 10, seedCoords);

            int totalAliveCells = grid.Cells.Sum(x => x.Count(y => y.State == CellState.alive));

            Assert.True(totalAliveCells == 1 &&
                        grid.Cells[xCoord][yCoord].State == CellState.alive);
        }
Exemplo n.º 4
0
        public void WhenGivenGrid_PerformTick_NewGridHasUpdatedCells()
        {
            Cell[][] cells = new Cell[][]
            {
                new Cell[] { new Cell(CellState.dead), new Cell(CellState.dead) },
                new Cell[] { new Cell(CellState.dead), new Cell(CellState.dead) }
            };
            Grid initGrid = new Grid(cells);

            Moq.Mock <ICellService> cellService = new Moq.Mock <ICellService>();
            cellService.Setup(x => x.GetNewCellState(Moq.It.IsAny <Cell>(), Moq.It.IsAny <Cell[]>())).Returns(CellState.alive);
            Domain.IGridService gridService = new Domain.GridService(cellService.Object);

            Grid resultGrid = gridService.PerformTick(initGrid);

            int totalAliveCells = resultGrid.Cells.Sum(x => x.Count(y => y.State == CellState.alive));

            Assert.True(totalAliveCells == 4);
        }