当前位置: 首页>>代码示例>>Python>>正文


Python GameOfLife.set_alive_cells方法代码示例

本文整理汇总了Python中game_of_life.GameOfLife.set_alive_cells方法的典型用法代码示例。如果您正苦于以下问题:Python GameOfLife.set_alive_cells方法的具体用法?Python GameOfLife.set_alive_cells怎么用?Python GameOfLife.set_alive_cells使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在game_of_life.GameOfLife的用法示例。


在下文中一共展示了GameOfLife.set_alive_cells方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestGameOfLife

# 需要导入模块: from game_of_life import GameOfLife [as 别名]
# 或者: from game_of_life.GameOfLife import set_alive_cells [as 别名]
class TestGameOfLife(unittest.TestCase):
    def setUp(self):
        self.game_of_life = GameOfLife()
        self._cells_alive = None

    def tearDown(self):
        self._cells_alive = None
        self.game_of_life = None

    def test_any_live_cell_with_fewer_than_two_live_neighbours_dies_example_1(self):
        self.game_of_life.set_alive_cells(((0, 0),))
        self._assert_cells_are_dead_in_next_generation((0, 0))

    def test_any_live_cell_with_fewer_than_two_live_neighbours_dies_example_2(self):
        self.game_of_life.set_alive_cells(((0, 0), (0, 1)))
        self._assert_cells_are_dead_in_next_generation(((0, 0), (0, 1)))

    def test_any_live_cell_with_fewer_than_two_live_neighbours_dies_example_3(self):
        self.game_of_life.set_alive_cells(((0, 0),
                                           (1, 0)))
        self._assert_cells_are_dead_in_next_generation(((0, 0),
                                                        (1, 0)))

    def test_any_live_cell_with_more_than_three_live_neighbours_dies_example_1(self):
        self.game_of_life.set_alive_cells((        (0, 1),
                                           (1, 0), (1, 1), (1, 2),
                                                   (2, 1)))
        self._assert_cells_are_dead_in_next_generation((1, 1))

    def test_any_live_cell_with_more_than_three_live_neighbours_dies_example_2(self):
        self.game_of_life.set_alive_cells(((0, 0), (0, 1),
                                           (1, 0), (1, 1), (1, 2),
                                                   (2, 1)))
        self._assert_cells_are_dead_in_next_generation((1, 1))

    def test_any_live_cell_with_more_than_three_live_neighbours_dies_example_3(self):
        self.game_of_life.set_alive_cells(((0, 0), (0, 1), (0, 2),
                                           (1, 0), (1, 1), (1, 2),
                                                   (2, 1)))
        self._assert_cells_are_dead_in_next_generation((1, 1))

    def test_any_live_cell_with_more_than_three_live_neighbours_dies_example_4(self):
        self.game_of_life.set_alive_cells(((0, 0), (0, 1), (0, 2),
                                           (1, 0), (1, 1), (1, 2),
                                           (2, 0), (2, 1)))
        self._assert_cells_are_dead_in_next_generation((1, 1))

    def test_any_live_cell_with_more_than_three_live_neighbours_dies_example_5(self):
        self.game_of_life.set_alive_cells(((0, 0), (0, 1), (0, 2),
                                           (1, 0), (1, 1), (1, 2),
                                           (2, 0), (2, 1), (2, 2)))
        self._assert_cells_are_dead_in_next_generation((1, 1))

    def test_any_live_cell_with_two_or_three_live_neighbours_lives_on_example_1(self):
        self.game_of_life.set_alive_cells((        (0, 1),
                                           (1, 0),         (1, 2),
                                                   (2, 1)))
        self._assert_cells_are_alive_in_next_generation((        (0, 1),
                                                         (1, 0),         (1, 2),
                                                                 (2, 1)))

    def test_any_live_cell_with_two_or_three_live_neighbours_lives_on_example_2(self):
        self.game_of_life.set_alive_cells((        (0, 1),
                                           (1, 0), (1, 1), (1, 2),
                                                   (2, 1)))
        self._assert_cells_are_alive_in_next_generation((        (0, 1),
                                                         (1, 0),         (1, 2),
                                                                 (2, 1)))

    def test_any_dead_cell_with_exactly_three_live_neighbours_becomes_alive(self):
        self.game_of_life.set_alive_cells((        (0, 1),
                                           (1, 0), (1, 1), (1, 2),
                                                   (2, 1)))
        self._assert_cells_are_alive_in_next_generation(((0, 0),       (0, 2),
                                                         (2, 0),       (2, 2)))

    def test_suggested_example(self):
        self.game_of_life.set_alive_cells((        (1, 4),
                                           (2, 3), (2, 4)))
        self._assert_exactly_these_cells_are_alive_in_next_generation(
            ((1, 3), (1, 4),
             (2, 3), (2, 4)))

    def test_oscillation(self):
        initially_alive_cells = ((0, 0), (0, 1), (0, 2))
        self.game_of_life.set_alive_cells(initially_alive_cells)
        self._assert_exactly_these_cells_are_alive_in_next_generation(
            ((-1, 1),
             ( 0, 1),
             ( 1, 1)))
        self._assert_exactly_these_cells_are_alive_in_next_generation(initially_alive_cells)

    def test_glider(self):
        self.game_of_life.set_alive_cells(
            (        (0, 1),
                             (1, 2),
             (2, 0), (2, 1), (2, 2)))

        self._assert_exactly_these_cells_are_alive_in_next_generation(
            (
#.........这里部分代码省略.........
开发者ID:aswna,项目名称:GameOfLife,代码行数:103,代码来源:game_of_life_test.py


注:本文中的game_of_life.GameOfLife.set_alive_cells方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。