예제 #1
0
    def test_seeded_grid_should_be_well_seeded(self):
        a_grid = Grid(2, 2)
        a_row = CellsRow(2)
        a_row.seed(cell_index=1)
        a_dead_row = CellsRow(2)

        a_grid.seed(Position(row=0, column=1))

        self.assertEqual([a_row, a_dead_row], a_grid.rows)
예제 #2
0
 def test_facory_created_grid_should_be_equal_to_seeded_grid(self):
     self.initialize_grid_factory()
     a_grid_2 = self.factory.create("11\n" + "10")
     a_grid = Grid(2, 2)
     a_grid.seed(Position(0, 0))
     a_grid.seed(Position(0, 1))
     a_grid.seed(Position(1, 0))
     expected = str(a_grid)
     self.assertEqual(expected, str(a_grid_2))
예제 #3
0
 def test_should_count_alive_cell_in_diagonal(self):
     a_grid = Grid(2, 2)
     a_grid.seed(Position(row=0, column=0))
     self.assertEqual(
         1, a_grid.count_alive_cells_around(Position(row=1, column=1)))
예제 #4
0
 def test_rows_should_be_generated_as_lists_of_lists(self):
     a_grid = Grid(2, 2)
     a_dead_row = CellsRow(2)
     self.assertEqual([a_dead_row, a_dead_row], a_grid.rows)
예제 #5
0
 def test_count_alive_cell_around_cell_with_alive_cell_on_the_north_should_return_1(
         self):
     a_grid = Grid(2, 1)
     a_grid.seed(Position(0, 0))
     self.assertEqual(1, a_grid.count_alive_cells_around(Position(1, 0)))
예제 #6
0
 def test_negative_index_position_should_raise(self):
     a_grid = Grid(1, 2)
     position = Position(-1, 0)
     with self.assertRaises(InvalidPosition):
         a_grid.count_alive_cells_around(position)
예제 #7
0
 def test_unique_alive_cell_should_have_no_living_neighbour(self):
     a_grid = Grid(1, 2)
     position = Position(0, 0)
     a_grid.seed(position)
     self.assertEqual(0, a_grid.count_alive_cells_around(position))
예제 #8
0
 def test_seeding_negative_out_of_board_should_raise_error(self):
     a_grid = Grid(1, 1)
     position = Position(-1, 0)
     with self.assertRaises(InvalidPosition):
         a_grid.seed(position)
예제 #9
0
 def test_empty_grid_should_not_equal_grid_with_1_element(self):
     a_grid = Grid(1, 1)
     position = Position(0, 0)
     a_grid.seed(position)
     self.assertNotEqual(a_grid, Grid(1, 1))
예제 #10
0
 def test_string_to_grid_with_two_rows_1_newline_0_string_should_return_2_1_grid_with_one_alive_at_position_0_0_and_one_dead(
         self):
     a_grid = Grid(2, 1)
     a_grid.seed(Position(row=0, column=0))
     self.initialize_grid_factory()
     self.assertEqual(a_grid, self.factory.create('1\n' + '0'))
예제 #11
0
 def test_string_to_grid_with_00_string_should_return_2_1_grid_with_two_dead_cells(
         self):
     a_grid = Grid(2, 1)
     self.initialize_grid_factory()
     self.assertEqual(a_grid, self.factory.create('0\n' + '0'))
예제 #12
0
 def test_string_to_grid_with_01_string_should_return_1_2_grid_with_1_dead_cell_and_1_alive_cell(
         self):
     a_grid = Grid(1, 2)
     a_grid.seed(Position(0, 1))
     self.initialize_grid_factory()
     self.assertEqual(a_grid, self.factory.create('01'))
예제 #13
0
 def test_string_to_grid_with_00_string_should_return_1_2_grid_with_2_dead_cells(
         self):
     a_grid = Grid(1, 2)
     self.initialize_grid_factory()
     self.assertEqual(a_grid, self.factory.create('00'))
예제 #14
0
 def test_string_to_grid_with_1_string_should_return_1_1_grid_with_1_alive_cell(
         self):
     a_grid_expected = Grid(1, 1)
     a_grid_expected.seed(Position(0, 0))
     self.initialize_grid_factory()
     self.assertEqual(a_grid_expected, self.factory.create('1'))
예제 #15
0
 def test_create_new_game_with_1_1_grid_and_a_tick_should_return_1_1_grid_with_dead_cell(
         self):
     a_game = GameOfLife(Grid(1, 1))
     a_game.tick()
     self.assertEqual(Grid(1, 1), a_game.grid)