本文整理匯總了Python中game_of_life.GameOfLife.evolve方法的典型用法代碼示例。如果您正苦於以下問題:Python GameOfLife.evolve方法的具體用法?Python GameOfLife.evolve怎麽用?Python GameOfLife.evolve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類game_of_life.GameOfLife
的用法示例。
在下文中一共展示了GameOfLife.evolve方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestGameOfLife
# 需要導入模塊: from game_of_life import GameOfLife [as 別名]
# 或者: from game_of_life.GameOfLife import evolve [as 別名]
class TestGameOfLife(TestCase):
def setUp(self):
self.game = GameOfLife()
def test_any_live_cell_with_less_than_two_neighbors_dies(self):
self.evolve([(0, 0)])
self.assert_dead((0, 0))
self.evolve([(0, 0), (0, 1)])
self.assert_dead((0, 1))
def test_any_live_cell_with_two_or_three_neighbors_survives(self):
self.evolve([(1, 1), (2, 1),
(0, 2), (1, 2)])
self.assert_alive((0, 2))
self.assert_alive((1, 2))
def test_any_live_cell_with_more_than_three_neighbors_dies(self):
self.evolve([(0, 1), (1, 1), (2, 1),
(0, 2), (1, 2), (2, 2)])
self.assert_dead((1, 1))
self.assert_dead((1, 2))
def test_any_dead_cell_with_three_neighbors_becomes_alive(self):
self.evolve([(1, 1), (2, 1),
(0, 2)])
self.assert_alive((1, 2))
def evolve(self, cells):
self.next_gen = self.game.evolve(cells)
def assert_alive(self, cell):
self.assertTrue(cell in self.next_gen)
def assert_dead(self, cell):
self.assertFalse(cell in self.next_gen)