public void GenerateNext_ShouldReturnAValidGrid_ForDifferentInput()
        {
            bool[,] grid = new bool[4, 2];
            GameOfLife game = new GameOfLife(grid);

            StringAssert.Contains("4 x 2\n..\n..\n..\n..", game.GenerateNext());
        }
        public void GenerateNext_ShouldReturnDifferentDimensions()
        {
            bool[,] grid = new bool[7, 3];
            GameOfLife game = new GameOfLife(grid);

            StringAssert.Contains("7 x 3", game.GenerateNext());
        }
        public void GenerateNext_ShouldReturnAValidGrid()
        {
            bool[,] grid = new bool[3, 3];
            GameOfLife game = new GameOfLife(grid);

            StringAssert.Contains("3 x 3\n...\n...\n...", game.GenerateNext());
        }
        public void GenerateAll_ShouldReturnACorrectStableGrid()
        {
            bool[,] grid = new bool[15, 15];
            grid[6, 7]   = grid[7, 6] = grid[7, 7] = grid[7, 8] = grid[8, 6] = grid[8, 8] = grid[9, 7] = true;
            GameOfLife game = new GameOfLife(grid);

            StringAssert.Contains(
                "15 x 15" +
                "\n..............." +
                "\n.......*......." +
                "\n......*.*......" +
                "\n......*.*......" +
                "\n.......*......." +
                "\n..............." +
                "\n..**.......**.." +
                "\n.*..*.....*..*." +
                "\n..**.......**.." +
                "\n..............." +
                "\n.......*......." +
                "\n......*.*......" +
                "\n......*.*......" +
                "\n.......*......." +
                "\n...............",
                game.GenerateAll());
        }
        public void GenerateNext_ShouldReturnAValidGridFromDifferentInput_IfNotStable()
        {
            bool[,] grid = new bool[4, 4];
            grid[1, 2]   = grid[2, 1] = grid[2, 2] = true;
            GameOfLife game = new GameOfLife(grid);

            StringAssert.Contains("4 x 4\n....\n.**.\n.**.\n....", game.GenerateNext());
        }
        public void GenerateNext_ShouldReturnValidGridFromInput_IfNotStable()
        {
            bool[,] grid = new bool[3, 3];
            grid[1, 1]   = true;
            GameOfLife game = new GameOfLife(grid);

            StringAssert.Contains("3 x 3\n...\n...\n...", game.GenerateNext());
        }
        public void GenerateNext_ShouldReturnAValidGrid_WithLiveCellsInput()
        {
            bool[,] grid = new bool[4, 4];
            grid[1, 1]   = grid[1, 2] = grid[2, 1] = grid[2, 2] = true;
            GameOfLife game = new GameOfLife(grid);

            StringAssert.Contains("4 x 4\n....\n.**.\n.**.\n....", game.GenerateNext());
        }
示例#8
0
        public void WhenOneDeadCell_ReturnsSameState()
        {
            const string input = "1,1\n.";
            var          game  = new GameOfLife();

            var nextGeneration = game.Next(input);

            Assert.AreEqual(input, nextGeneration);
        }
示例#9
0
        static void Main(string[] args)
        {
            var gof = new GameOfLife(8, 8);

            gof.AddLivingCell(5, 5);
            gof.AddLivingCell(5, 6);
            gof.AddLivingCell(5, 7);

            gof.Output();
        }
示例#10
0
        public void WhenFieldWithDeadAndAliveCell_ReturnsTwoDeadCells()
        {
            const string inputWithDeadAndAlive    = "1,2\n.*";
            const string expectedWithTwoDeadCells = "1,2\n..";
            var          game = new GameOfLife();

            var nextGeneration = game.Next(inputWithDeadAndAlive);

            Assert.AreEqual(expectedWithTwoDeadCells, nextGeneration);
        }
示例#11
0
        public void WhenOneAliveCell_ReturnsDeadCell()
        {
            const string input = "1,1\n*";
            const string expectedWithDeadCell = "1,1\n.";
            var          game = new GameOfLife();

            var nextGeneration = game.Next(input);

            Assert.AreEqual(expectedWithDeadCell, nextGeneration);
        }
示例#12
0
        public static void Main(string[] args)
        {
            //int inputX = int.Parse(Console.ReadLine());
            //int inputY = int.Parse(Console.ReadLine());
            Console.WriteLine("Generating board...");
            bool[,] grid = new bool[15, 15];
            grid[6, 7]   = grid[7, 6] = grid[7, 7] = grid[7, 8] = grid[8, 6] = grid[8, 8] = grid[9, 7] = true;

            GameOfLife game = new GameOfLife(grid);// new bool[inputX, inputY]);

            Console.WriteLine(game.GenerateAll());
            Console.ReadKey();
        }
示例#13
0
        public void KillACellWithoutNeighbors()
        {
            Ecosystem expectedEcosystem = new Ecosystem();

            Ecosystem ecosystem = new Ecosystem();

            ecosystem.AddCell(0, 0);
            GameOfLife gameOfLife = new GameOfLife(ecosystem);

            gameOfLife.Evolve();

            Assert.Equal(expectedEcosystem, ecosystem);
        }
示例#14
0
        public void KeepAliveMiddleCellWhenTheres3CellsInDiagonal()
        {
            Ecosystem expectedEcosystem = new Ecosystem();

            expectedEcosystem.AddCell(1, 1);

            Ecosystem ecosystem = new Ecosystem();

            ecosystem.AddCell(0, 0);
            ecosystem.AddCell(1, 1);
            ecosystem.AddCell(2, 2);
            GameOfLife gameOfLife = new GameOfLife(ecosystem);

            gameOfLife.Evolve();

            Assert.Equal(expectedEcosystem, ecosystem);
        }
示例#15
0
        public void ReviveACellWhenTheres3CellsNextToIt()
        {
            Ecosystem expectedEcosystem = new Ecosystem();

            expectedEcosystem.AddCell(0, 0);

            expectedEcosystem.AddCell(1, 1);
            expectedEcosystem.AddCell(1, 0);
            expectedEcosystem.AddCell(0, 1);

            Ecosystem ecosystem = new Ecosystem();

            ecosystem.AddCell(0, 0);
            ecosystem.AddCell(1, 0);
            ecosystem.AddCell(1, 1);
            GameOfLife gameOfLife = new GameOfLife(ecosystem);

            gameOfLife.Evolve();

            Assert.Equal(expectedEcosystem, ecosystem);
        }
示例#16
0
        public void KillCellWithMoreThan3Neighbors()
        {
            Ecosystem expectedEcosystem = new Ecosystem();

            expectedEcosystem.AddCell(1, 0);
            expectedEcosystem.AddCell(0, 1);
            expectedEcosystem.AddCell(2, 1);
            expectedEcosystem.AddCell(1, 2);


            Ecosystem ecosystem = new Ecosystem();

            ecosystem.AddCell(0, 0);
            ecosystem.AddCell(0, 2);
            ecosystem.AddCell(1, 1);
            ecosystem.AddCell(2, 0);
            ecosystem.AddCell(2, 2);
            GameOfLife gameOfLife = new GameOfLife(ecosystem);

            gameOfLife.Evolve();

            Assert.Equal(expectedEcosystem, ecosystem);
        }
        public void SetUp()
        {
            this.gameOfLife = new GameOfLife();

            this.gameOfLife.Seed(8, 8);
        }