public void ReturnAnEmptyGridWhenAllALiveCellsDie()
        {
            _gameOfLife.SetGrid(5, 5);
            int[][] graph =
            {
                new[] { 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 1, 0 },
                new[] { 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0 }
            };

            _testHelper.TransformGraphToCells(graph).ForEach(cell => _gameOfLife.AddCellToGrid(cell));

            _gameOfLife.Evolve();

            int[][] expectedLiveCellsGraph =
            {
                new[] { 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 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 actualLivingCells = _gameOfLife.LivingCells;

            expectedLiveCells.Should().BeEquivalentTo(actualLivingCells);
            Assert.Empty(actualLivingCells);
        }
Exemple #2
0
        public void TestIfLessThanTwo()
        {
            var gof = new GameOfLife(8, 4);

            gof.AddLivingCell(5, 2);
            gof.Evolve();
            Boolean is_alive = gof.IsCellAlive(5, 2);


            Assert.IsFalse(is_alive);
        }
Exemple #3
0
        public void TestIfDeadCellGoesAlive()
        {
            var gof = new GameOfLife(4, 4);

            gof.AddLivingCell(0, 0);
            gof.AddLivingCell(2, 0);
            gof.AddLivingCell(1, 1);
            gof.Evolve();

            bool is_alive = gof.IsCellAlive(1, 0);

            Assert.That(is_alive, Is.True);
        }
Exemple #4
0
        public void TestWithExactlyThree()
        {
            var gof = new GameOfLife(8, 4);

            gof.AddLivingCell(5, 1);
            gof.AddLivingCell(5, 2);
            gof.AddLivingCell(4, 2);
            gof.Evolve();
            bool is_alive = gof.IsCellAlive(4, 1);


            Assert.That(is_alive, Is.True);
        }
Exemple #5
0
        public void TestIfMoreThanThree()
        {
            var gof = new GameOfLife(8, 4);

            gof.AddLivingCell(5, 2);
            gof.AddLivingCell(5, 3);
            gof.AddLivingCell(4, 2);
            gof.AddLivingCell(5, 1);
            gof.AddLivingCell(6, 2);
            gof.Evolve();
            bool is_alive = gof.IsCellAlive(5, 2);


            Assert.That(is_alive, Is.False);
        }
        public void ReturnAnEmptyGridWhenAllALiveCellDie()
        {
            var game = new GameOfLife();
            var initialLivingCells = new List <Cell> {
                new Cell(1, 1), new Cell(1, 0), new Cell(3, 3)
            };

            game.SetGridSize(5, 5);
            game.SetInitialStateOfGrid(initialLivingCells);
            game.Evolve();
            var actuaLivingCells = game.LivingCells;

            actuaLivingCells.Should().BeEmpty();
            Assert.Equal(0, actuaLivingCells.Count());
        }
        public void AddADeadCellToGridWhenCellLives()
        {
            var game = new GameOfLife();
            var initialLivingCells = new List <Cell> {
                new Cell(0, 1), new Cell(0, 2), new Cell(1, 0)
            };

            game.SetGridSize(5, 5);
            game.SetInitialStateOfGrid(initialLivingCells);
            game.Evolve();
            var expectedLiveCells = new List <Cell> {
                new Cell(0, 1), new Cell(1, 1)
            };
            var actuaLivingCells = game.LivingCells;

            actuaLivingCells.Should().BeEquivalentTo(expectedLiveCells);
            Assert.Equal(2, actuaLivingCells.Count());
        }
        public void KeepTheStateOfTheGridAsNoCellDies()
        {
            var game = new GameOfLife();
            var initialLivingCells = new List <Cell> {
                new Cell(1, 0), new Cell(1, 1), new Cell(2, 0), new Cell(2, 1)
            };

            game.SetGridSize(5, 5);
            game.SetInitialStateOfGrid(initialLivingCells);
            game.Evolve();
            var expectedLiveCells = new List <Cell> {
                new Cell(1, 0), new Cell(1, 1), new Cell(2, 0), new Cell(2, 1)
            };
            var actuaLivingCells = game.LivingCells;

            actuaLivingCells.Should().BeEquivalentTo(expectedLiveCells);
            Assert.Equal(4, actuaLivingCells.Count());
        }
        public void RemoveCellsFromGridWhenMultipleLiveCellsDieAndAddCellsThatShouldBecomeAlive()
        {
            var game = new GameOfLife();
            var initialLivingCells = new List <Cell> {
                new Cell(1, 1), new Cell(1, 2), new Cell(4, 2), new Cell(1, 0)
            };

            game.SetGridSize(5, 5);
            game.SetInitialStateOfGrid(initialLivingCells);
            game.Evolve();
            var expectedLiveCells = new List <Cell> {
                new Cell(1, 1), new Cell(0, 2), new Cell(2, 1)
            };
            var actuaLivingCells = game.LivingCells;

            actuaLivingCells.Should().BeEquivalentTo(expectedLiveCells);
            Assert.Equal(3, actuaLivingCells.Count());
        }
Exemple #10
0
        static void Main(string[] args)
        {
            var UI         = new GameOfLifeUILib();
            var gameOfLife = new GameOfLife();
            IEnumerable <GridIndex> fullGridIndex;

            do
            {
                UI.ShowInputScreen();
                fullGridIndex = gameOfLife.Initialize();
                UI.DisplayGrid(fullGridIndex);

                for (int i = 0; i <= Grid.NumberOfEvolution; i++)
                {
                    fullGridIndex = gameOfLife.Evolve(i, fullGridIndex.ToList <GridIndex>());
                    UI.PrintEvolution(i);
                    UI.DisplayGrid(fullGridIndex);
                }
            }while (UI.Quit());
        }