def test_neighbours(): game = Life() neighbours = ((-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1)) assert len(neighbours) == len(list(game.neighbours((0, 0)))) assert sorted(neighbours) == sorted(list(game.neighbours((0, 0))))
def test_over_population_death(): for count in range(4, 8): game = Life() game.set_living((0, 0)) neighbour = game.neighbours((0, 0)) for i in range(0, count): game.set_living(neighbour.next()) assert game.is_alive((0, 0)) game.tick() assert not game.is_alive((0, 0))
def test_invalid_neighbours(): game = Life() with pytest.raises(TypeError): list(game.neighbours((True, True)))