コード例 #1
0
        public void Blinker_should_oscillate_over_two_periods()
        {
            //arrange
            var input = new List <Library.Cell> {
                new Library.Cell(2, 3),
                new Library.Cell(3, 3),
                new Library.Cell(4, 3)
            };

            var game = new Library.Game(5, 5, 1, input); //initialize game with 5x5 board, 1 generation, and given input

            //act
            game.Start();

            //assert
            Assert.True(game.Cell(3, 2).Alive, "This cell should have come alive");
            Assert.False(game.Cell(2, 3).Alive, "This cell should be dead");
            Assert.True(game.Cell(3, 3).Alive, "This cell should still be alive");
            Assert.False(game.Cell(4, 3).Alive, "This cell should have died");
            Assert.True(game.Cell(3, 4).Alive, "This cell should have come alive");

            //arrange for 2 generations
            game = new Library.Game(5, 5, 2, input); //initialize game with 5x5 board, 2 generations, and given input

            //act
            game.Start();

            //assert
            Assert.False(game.Cell(3, 2).Alive, "This cell should have died");
            Assert.True(game.Cell(2, 3).Alive, "This cell should be alive again");
            Assert.True(game.Cell(3, 3).Alive, "This cell should still be alive");
            Assert.True(game.Cell(4, 3).Alive, "This cell should be alive again");
            Assert.False(game.Cell(3, 4).Alive, "This cell should have died");
        }
コード例 #2
0
        public void Toad_should_oscillate_over_two_periods()
        {
            //arrange
            var input = new List <Library.Cell> {
                new Library.Cell(3, 3),
                new Library.Cell(4, 3),
                new Library.Cell(5, 3),
                new Library.Cell(2, 4),
                new Library.Cell(3, 4),
                new Library.Cell(4, 4)
            };

            var game = new Library.Game(6, 6, 1, input); //initialize game with 6x6 board, 1 generation, and given input

            //act
            game.Start();

            //assert that it has oscillated
            Assert.True(game.Cell(4, 2).Alive, "This cell should have come alive");
            Assert.True(game.Cell(2, 3).Alive, "This cell should have come alive");
            Assert.False(game.Cell(3, 3).Alive, "This cell should have died");
            Assert.False(game.Cell(4, 3).Alive, "This cell should have died");
            Assert.True(game.Cell(5, 3).Alive, "This cell should remain alive");
            Assert.True(game.Cell(2, 4).Alive, "This cell should remain alive");
            Assert.False(game.Cell(3, 4).Alive, "This cell should have died");
            Assert.False(game.Cell(4, 4).Alive, "This cell should have died");
            Assert.True(game.Cell(5, 4).Alive, "This cell should have come alive");
            Assert.True(game.Cell(3, 5).Alive, "This cell should have come alive");


            //arrange for 2 generations
            game = new Library.Game(5, 5, 2, input); //initialize game with 5x5 board, 2 generations, and given input

            //act
            game.Start();

            //assert that it is back to original state
            Assert.False(game.Cell(4, 2).Alive, "This cell should have died again");
            Assert.False(game.Cell(2, 3).Alive, "This cell should have died again");
            Assert.True(game.Cell(3, 3).Alive, "This cell should have come alive again");
            Assert.True(game.Cell(4, 3).Alive, "This cell should have come alive again");
            Assert.True(game.Cell(5, 3).Alive, "This cell should remain alive");
            Assert.True(game.Cell(2, 4).Alive, "This cell should remain alive");
            Assert.True(game.Cell(3, 4).Alive, "This cell should have come alive again");
            Assert.True(game.Cell(4, 4).Alive, "This cell should have come alive again");
            Assert.False(game.Cell(5, 4).Alive, "This cell should have died again");
            Assert.False(game.Cell(3, 5).Alive, "This cell should have died again");
        }
コード例 #3
0
        public void FourCellBlock_should_remain_static()
        {
            //arrange
            var input = new List <Library.Cell> {
                new Library.Cell(2, 2),
                new Library.Cell(2, 3),
                new Library.Cell(3, 2),
                new Library.Cell(3, 3)
            };

            var game = new Library.Game(4, 4, 1, input); //initialize game with 4x4 board, 1 generation, and given input

            //act
            game.Start();

            //assert
            Assert.True(game.Cell(2, 2).Alive, "This cell should still be alive");
            Assert.True(game.Cell(2, 3).Alive, "This cell should still be alive");
            Assert.True(game.Cell(3, 2).Alive, "This cell should still be alive");
            Assert.True(game.Cell(3, 3).Alive, "This cell should still be alive");
        }
コード例 #4
0
        public void Beehive_should_remain_static()
        {
            //arrange
            //......
            //..XX..
            //.X..X.
            //..XX..
            //......
            var input = new List <Library.Cell> {
                new Library.Cell(3, 2),
                new Library.Cell(4, 2),
                new Library.Cell(2, 3),
                new Library.Cell(5, 3),
                new Library.Cell(3, 4),
                new Library.Cell(4, 4)
            };

            var game = new Library.Game(6, 5, 1, input); //initialize game with 6x5 board, 1 generation, and given input

            //act
            game.Start();

            //assert
            //......
            //..XX..
            //.X..X.
            //..XX..
            //......
            Assert.True(game.Cell(3, 2).Alive, "This cell should still be alive");
            Assert.True(game.Cell(4, 2).Alive, "This cell should still be alive");
            Assert.True(game.Cell(2, 3).Alive, "This cell should still be alive");
            Assert.True(game.Cell(5, 3).Alive, "This cell should still be alive");
            Assert.True(game.Cell(3, 4).Alive, "This cell should still be alive");
            Assert.True(game.Cell(4, 4).Alive, "This cell should still be alive");
        }
コード例 #5
0
        public void A_dead_cell_with_exactly_three_live_neighbours_comes_alive()
        {
            //arrange
            //..........
            //..........
            //..........
            //..........
            //....X.....
            //....X.....
            //....X.....
            //..........
            //..........
            //..........
            var input = new List <Library.Cell> {
                new Library.Cell(5, 5),
                new Library.Cell(5, 6),
                new Library.Cell(5, 7)
            };

            var game = new Library.Game(10, 10, 1, input); //initialize game with 10x10 board, 1 generation, and given input

            //act
            game.Start();

            //assert
            //..........
            //..........
            //..........
            //..........
            //....?.....
            //...X?X....
            //....?.....
            //..........
            //..........
            //..........
            Assert.True(game.Cell(4, 6).Alive, "This cell should have come alive");
            Assert.True(game.Cell(6, 6).Alive, "This cell should have come alive");
        }
コード例 #6
0
        public void A_live_cell_more_than_three_live_neighbours_dies()
        {
            //arrange
            //..........
            //..........
            //..........
            //....X.....
            //...XX.....
            //...XX.....
            //..........
            //..........
            //..........
            //..........
            var input = new List <Library.Cell> {
                new Library.Cell(5, 5),
                new Library.Cell(5, 6),
                new Library.Cell(5, 4),
                new Library.Cell(4, 5),
                new Library.Cell(4, 6)
            };

            var game = new Library.Game(10, 10, 1, input); //initialize game with 10x10 board, 1 generation, and given input

            //act
            game.Start();

            //assert
            //..........
            //..........
            //..........
            //....?.....
            //...?......
            //...??.....
            //..........
            //..........
            //..........
            //..........
            Assert.False(game.Cell(5, 5).Alive, "This cell should be dead");
        }
コード例 #7
0
        public void A_live_cell_with_two_live_neighbours_lives()
        {
            //arrange
            //..........
            //..........
            //..........
            //..........
            //...XX.....
            //....X.....
            //..........
            //..........
            //..........
            //..........
            var input = new List <Library.Cell> {
                new Library.Cell(5, 5),
                new Library.Cell(5, 6),
                new Library.Cell(4, 5)
            };

            var game = new Library.Game(10, 10, 1, input); //initialize game with 10x10 board, 1 generation, and given input

            //act
            game.Start();

            //assert
            //..........
            //..........
            //..........
            //..........
            //...?X.....
            //....?.....
            //..........
            //..........
            //..........
            //..........
            Assert.True(game.Cell(5, 5).Alive, "This cell should be alive");
        }