def test_update_method(self): world = WorldBoard(5) board = world._board board.change_cell_at(0, 0) board.change_cell_at(1, 1) board.change_cell_at(1, 2) board.change_cell_at(0, 3) """ X..X. .XX.. .XX.. .XX.. ..... => ..... ..... ..... ..... ..... """ next_gen_board = Grid(5) next_gen_board.change_cell_at(0, 1) next_gen_board.change_cell_at(0, 2) next_gen_board.change_cell_at(1, 1) next_gen_board.change_cell_at(1, 2) board.next_generation() for cell in board: self.assertEqual(cell.is_alive(), next_gen_board.get_cell_at(cell.x, cell.y).is_alive())
def test_if_cell_should_change(self): board = Grid(5) for cell in board: self.assertFalse(board.should_change(cell)) board.change_cell_at(0, 0) board.change_cell_at(0, 1) board.change_cell_at(0, 2) """ XXX.. ..... ..... ..... ..... """ self.assertTrue(board.should_change(board.get_cell_at(0, 0))) self.assertFalse(board.should_change(board.get_cell_at(0, 1))) self.assertTrue(board.should_change(board.get_cell_at(0, 2)))
def test_next_generation(self): board = Grid(5) board.change_cell_at(0, 0) board.change_cell_at(1, 1) board.change_cell_at(1, 2) board.change_cell_at(0, 3) """ X..X. .XX.. .XX.. .XX.. ..... => ..... ..... ..... ..... ..... """ next_gen_board = Grid(5) next_gen_board.change_cell_at(0, 1) next_gen_board.change_cell_at(0, 2) next_gen_board.change_cell_at(1, 1) next_gen_board.change_cell_at(1, 2) board.next_generation() for cell in board: self.assertEqual(cell.is_alive(), next_gen_board.get_cell_at(cell.x, cell.y).is_alive())
def test_get_cell_at_method(self): board = Grid(3) self.assertEqual(board.get_cell_at(0, 0), board._grid[0][0])