public void GetMultipleDeadCellsThatShouldBecomeAliveWhenTheyHaveThreeLiveNeighbours()
        {
            var rules = new LiveEvolutionRules();
            var grid  = new Grid(5, 5);

            grid.AddCell(new Cell(1, 1));
            grid.AddCell(new Cell(1, 2));
            grid.AddCell(new Cell(2, 1));
            grid.AddCell(new Cell(2, 0));

            var neighboursOfAliveCell = new List <IEnumerable <Cell> >
            {
                grid.GetDeadNeighboursOfLivingCell(new Cell(1, 1)),
                grid.GetDeadNeighboursOfLivingCell(new Cell(1, 2)),
                grid.GetDeadNeighboursOfLivingCell(new Cell(2, 0)),
                grid.GetDeadNeighboursOfLivingCell(new Cell(2, 1))
            };

            var expectedLiveCells = new List <Cell> {
                new Cell(1, 0), new Cell(2, 2)
            };
            var cellsThatShouldLive = rules.GetDeadCellsThatShouldLive(neighboursOfAliveCell);

            expectedLiveCells.Should().BeEquivalentTo(cellsThatShouldLive);
            Assert.Equal(2, cellsThatShouldLive.Count);
        }
Exemple #2
0
        private List <Cell> GetCellsThatShouldLive()
        {
            var allDeadNeighboursOfLiveCells = new List <Cell>();

            foreach (var cell in LivingCells)
            {
                allDeadNeighboursOfLiveCells.AddRange(_grid.GetDeadNeighboursOfACell(cell));
            }

            var cellsThatShouldLive = _liveEvolutionRules.GetDeadCellsThatShouldLive(allDeadNeighboursOfLiveCells);

            return(cellsThatShouldLive);
        }
        public void GetTheDeadCellThatShouldBecomeAliveWhenItHasThreeLiveNeighbours()
        {
            var grid = new Grid(5, 5);

            int[][] graph =
            {
                new[] { 0, 0, 1, 1, 0 },
                new[] { 0, 1, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0 }
            };

            _testHelper.TransformGraphToCells(graph).ForEach(cell => grid.AddCell(cell));

            var allDeadNeighboursOfAliveCells = new List <Cell>();

            foreach (var livingCell in grid.LivingCells)
            {
                allDeadNeighboursOfAliveCells.AddRange(grid.GetDeadNeighboursOfACell(livingCell));
            }

            int[][] expectedLiveCellsGraph =
            {
                new[] { 0, 0, 0, 0, 0 },
                new[] { 0, 0, 1, 0, 0 },
                new[] { 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0 }
            };

            var expectedLiveCells = _testHelper.TransformGraphToCells(expectedLiveCellsGraph);
            var actualLiveCells   = _rules.GetDeadCellsThatShouldLive(allDeadNeighboursOfAliveCells);

            expectedLiveCells.Should().BeEquivalentTo(actualLiveCells);
            Assert.Single(actualLiveCells);
        }