本文整理汇总了Python中game_of_life.GameOfLife.neighbours_of方法的典型用法代码示例。如果您正苦于以下问题:Python GameOfLife.neighbours_of方法的具体用法?Python GameOfLife.neighbours_of怎么用?Python GameOfLife.neighbours_of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类game_of_life.GameOfLife
的用法示例。
在下文中一共展示了GameOfLife.neighbours_of方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GameOfLifeTest
# 需要导入模块: from game_of_life import GameOfLife [as 别名]
# 或者: from game_of_life.GameOfLife import neighbours_of [as 别名]
class GameOfLifeTest(unittest.TestCase):
def setUp(self):
self.game = GameOfLife({Vec2D(0, 0): Cell(True), Vec2D(0, 1): Cell(True),
Vec2D(1, 0): Cell(True), Vec2D(3, 3): Cell(True)})
def test_alive_cell_when_game_is_set_up(self):
self.assertEqual(self.game.is_alive(Vec2D(1, 0)), True)
self.assertEqual(self.game.is_alive(Vec2D(1, 1)), False)
def test_number_of_alive_neighbours(self):
self.assertEqual(self.game.number_of_alive_neighbours(Vec2D(0, 0)), 2)
self.assertEqual(self.game.number_of_alive_neighbours(Vec2D(1, 1)), 3)
self.assertEqual(self.game.number_of_alive_neighbours(Vec2D(4, 0)), 0)
def test_neighbours_of(self):
self.assertEqual(sorted(self.game.neighbours_of(Vec2D(0, 0))), sorted([Vec2D(-1, -1), Vec2D(-1, 0), Vec2D(-1, 1),
Vec2D(0, -1), Vec2D(0, 1),
Vec2D(1, -1), Vec2D(1, 0), Vec2D(1, 1)]))
def test_will_be_born(self):
self.assertEqual(self.game.will_be_born(Vec2D(1, 1)), True)
self.assertEqual(self.game.will_be_born(Vec2D(0, 1)), False)
def test_will_servive(self):
self.assertEqual(self.game.will_servive(Vec2D(0, 1)), True)
self.assertEqual(self.game.will_servive(Vec2D(3, 3)), False)
def test_stable_cells(self):
stable_cells = self.game.stable_cells()
self.assertEqual(sorted(stable_cells.keys()), sorted([Vec2D(0, 0), Vec2D(0, 1), Vec2D(1, 0)]))
self.assertEqual(stable_cells[Vec2D(0, 0)].new_born, False)
def test_new_born_cells(self):
new_born_cells = self.game.new_born()
self.assertEqual(sorted(new_born_cells.keys()), [Vec2D(1, 1)])
self.assertEqual(new_born_cells[Vec2D(1, 1)].new_born, True)
def test_next_generation(self):
next_generation = self.game.next_generation()
self.assertEqual(sorted(next_generation.keys()), sorted([Vec2D(0, 0), Vec2D(0, 1), Vec2D(1, 0), Vec2D(1, 1)]))