コード例 #1
0
        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());
        }
コード例 #2
0
        public void GenerateNext_ShouldReturnDifferentDimensions()
        {
            bool[,] grid = new bool[7, 3];
            GameOfLife game = new GameOfLife(grid);

            StringAssert.Contains("7 x 3", game.GenerateNext());
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        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());
        }
コード例 #5
0
        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());
        }
コード例 #6
0
        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());
        }
コード例 #7
0
        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
ファイル: GameOfLifeTests.cs プロジェクト: Undermove/TDDKata
        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
ファイル: GameOfLifeTests.cs プロジェクト: Undermove/TDDKata
        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
ファイル: GameOfLifeTests.cs プロジェクト: Undermove/TDDKata
        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);
        }
コード例 #17
0
        public void SetUp()
        {
            this.gameOfLife = new GameOfLife();

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