def test_parse(): assert np.all( Game.parse(initial_state) == np.array( [ [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 1, 1, 0, 0], [0, 1, 0, 0, 0, 0, 1, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 1, 0, 1, 0, 0, 1, 0], [0, 1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], ] ) )
def setup(self): self.game = Game(initial_state, broken=True)
class TestBrokenGame(object): def setup(self): self.game = Game(initial_state, broken=True) def test_initialize(self): assert np.all( self.game.state == np.array( [ [1, 1, 0, 1, 0, 1], [0, 0, 0, 1, 1, 0], [1, 0, 0, 0, 0, 1], [0, 0, 1, 0, 0, 0], [1, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 1], ] ) ) def test_get_n_neighbours(self): assert np.all( self.game.get_n_neighbours() == np.array( [ [1, 1, 3, 2, 4, 1], [3, 3, 3, 2, 4, 3], [0, 2, 2, 3, 3, 1], [2, 4, 1, 2, 2, 2], [2, 6, 4, 4, 3, 1], [2, 4, 3, 2, 3, 1], ] ) ) def test_step_once(self): self.game.step() assert np.all( self.game.state == np.array( [ [1, 0, 1, 1, 0, 1], [1, 1, 1, 1, 0, 1], [0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 1, 0], [1, 0, 1, 1, 1, 1], ] ) ) def test_step_n_times(self): self.game.step(5) assert np.all( self.game.state == np.array( [ [1, 1, 0, 1, 1, 1], [0, 1, 1, 0, 0, 1], [0, 1, 1, 0, 0, 0], [0, 1, 1, 0, 0, 0], [1, 0, 1, 0, 0, 0], [1, 1, 0, 0, 0, 1], ] ) ) def test_n_lights_on(self): assert self.game.n_lights_on == 17 self.game.step(5) assert self.game.n_lights_on == 17
def setup(self): self.game = Game(initial_state)