public void GetLiveCellsThatShouldDieWheTheyHaveLessThanTwoNeighbours()
        {
            var rules   = new DeadEvolutionRules();
            var grid    = new Grid(5, 5);
            var cellOne = new Cell(0, 2);
            var cellTwo = new Cell(0, 1);

            grid.AddCell(cellOne);
            grid.AddCell(cellTwo);

            var neighboursOfAliveCell = new List <IEnumerable <Cell> >
            {
                grid.GetLiveNeighboursOfLivingCell(cellOne),
                grid.GetLiveNeighboursOfLivingCell(cellTwo)
            };

            var expectedDeadCells = new List <Cell> {
                cellOne, cellTwo
            };
            var cellsThatShouldDie =
                rules.GetLiveCellsThatShouldDie(neighboursOfAliveCell, new List <Cell> {
                cellOne, cellTwo
            });

            expectedDeadCells.Should().BeEquivalentTo(cellsThatShouldDie);
            Assert.Equal(2, cellsThatShouldDie.Count);
        }
        public void GetNoLiveCellThatShouldDieWheTheyHaveTwoOrThreeNeighbours()
        {
            var rules     = new DeadEvolutionRules();
            var grid      = new Grid(4, 4);
            var cellOne   = new Cell(0, 0);
            var cellTwo   = new Cell(0, 1);
            var cellThree = new Cell(1, 1);
            var cellFour  = new Cell(1, 2);

            grid.AddCell(cellOne);
            grid.AddCell(cellTwo);
            grid.AddCell(cellThree);
            grid.AddCell(cellFour);

            var neighboursOfAliveCell = new List <IEnumerable <Cell> >
            {
                grid.GetLiveNeighboursOfLivingCell(cellOne),
                grid.GetLiveNeighboursOfLivingCell(cellTwo),
                grid.GetLiveNeighboursOfLivingCell(cellThree),
                grid.GetLiveNeighboursOfLivingCell(cellFour)
            };

            var expectedDeadCells  = new List <Cell>();
            var cellsThatShouldDie = rules.GetLiveCellsThatShouldDie(neighboursOfAliveCell,
                                                                     new List <Cell> {
                cellOne, cellTwo, cellThree, cellFour
            });

            expectedDeadCells.Should().BeEquivalentTo(cellsThatShouldDie);
            Assert.Equal(0, cellsThatShouldDie.Count);
        }
Beispiel #3
0
        private List <Cell> GetCellsThatShouldDie()
        {
            var liveCellsAndItsNeighboursCount = _grid.GetLiveCellsAndItsNumberOfLiveNeighboursDict();
            var cellsThatShouldDie             = _deadEvolutionRules.GetLiveCellsThatShouldDie(liveCellsAndItsNeighboursCount);

            return(cellsThatShouldDie);
        }
        public void GetLiveCellsThatShouldDieWhenTheyHaveLessThanTwoOrThreeNeighbours()
        {
            var grid = new Grid(5, 5);

            int[][] graph =
            {
                new[] { 0, 0, 0, 0, 0 },
                new[] { 0, 1, 1, 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 allLiveNeighboursOfAliveCells = new List <Cell>();

            foreach (var livingCell in grid.LivingCells)
            {
                allLiveNeighboursOfAliveCells.AddRange(grid.GetLiveNeighboursOfACell(livingCell));
            }

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

            var expectedDeadCells      = _testHelper.TransformGraphToCells(expectedDeadCellsGraph);
            var neighboursOfCellsCount = grid.GetLiveCellsAndItsNumberOfLiveNeighboursDict();
            var actualDeadCells        = _rules.GetLiveCellsThatShouldDie(neighboursOfCellsCount);

            expectedDeadCells.Should().BeEquivalentTo(actualDeadCells);
            Assert.Equal(2, actualDeadCells.Count);
        }
        public void GetLiveCellThatShouldDieWhenItHasNoNeighbours()
        {
            var rules    = new DeadEvolutionRules();
            var grid     = new Grid(5, 5);
            var cellFour = new Cell(3, 3);

            grid.AddCell(cellFour);

            var neighboursOfAliveCell = new List <IEnumerable <Cell> >
            {
                grid.GetLiveNeighboursOfLivingCell(cellFour),
            };

            var expectedDeadCells = new List <Cell> {
                cellFour
            };
            var cellsThatShouldDie = rules.GetLiveCellsThatShouldDie(neighboursOfAliveCell, new List <Cell> {
                cellFour
            });

            expectedDeadCells.Should().BeEquivalentTo(cellsThatShouldDie);
            Assert.Equal(1, cellsThatShouldDie.Count);
        }