def test_rule3_two_neighbours_lives(self): board = game_of_life.GameOfLife(2, 2) board.set_cell(0, 0, True) board.set_cell(0, 1, True) board.set_cell(1, 0, True) board.next_generation() self.assertEqual(board.get_cell(1, 0), True)
def test_rule4_dead_with_2_neighbours_stays_dead(self): board = game_of_life.GameOfLife(2, 2) board.set_cell(0, 0, True) board.set_cell(0, 1, True) board.set_cell(1, 0, False) board.next_generation() self.assertEqual(board.get_cell(1, 0), False)
def __init__(self, width, height, cell_size, seed): super().__init__(width, height) # calls the inherited constructor # constructing a GoL object and assigning to an attribute self.gameOfLife = game_of_life.GameOfLife(width, height, cell_size, seed) # scheduling updated states pyglet.clock.schedule_interval(self.update, 1.0/20.0) # 20fps
def test_rule4_dead_with_3_neighbours_becomes_alive(self): board = game_of_life.GameOfLife(2, 2) board.set_cell(0, 0, True) board.set_cell(0, 1, True) board.set_cell(1, 0, True) board.set_cell(1, 1, False) board.next_generation() self.assertEqual(board.get_cell(1, 1), True)
def test_rule2_more_than_3_neighbours(self): board = game_of_life.GameOfLife(3, 3) board.set_cell(0, 0, True) board.set_cell(0, 1, True) board.set_cell(0, 2, True) board.set_cell(1, 0, True) board.set_cell(1, 1, True) board.set_cell(2, 1, True) board.next_generation() self.assertEqual(board.get_cell(1, 1), False)
def __init__(self, width=100, height=50): super().__init__() self.main_view = None self.running = False self.game_of_life = game_of_life.GameOfLife(width, height) self.time_value = 1 self.nb_iterations = -1 self.figures_manager = figures_manager.FiguresManager( self.game_of_life.width, self.game_of_life.height ) self.figure_to_place = ()
def sanityTest(self): ''' program[width][height][infect - after][max - generations][seed] ''' args = { 'width': 2, 'height': 3, 'infect-after': 3, 'max-generations': 6, 'seed': "1 0 0 1 1 1", } width, height, infect_after, max_gen, seed = 2, 3, 3, 6, [ 1, 0, 0, 1, 1, 1 ] obj = GOF.GameOfLife(width, height, infect_after, max_gen) obj.playStage()
def __init__(self): self.game = life.GameOfLife() self.running = False
def test_initial_cell_state_is_dead(self): board = game_of_life.GameOfLife(1, 1) self.assertEqual(board.get_cell(0, 0), False)
def test_board_initialisation(self): game_of_life.GameOfLife(10, 10)
def test_rule1_live_cell_becomes_dead(self): board = game_of_life.GameOfLife(1, 1) board.set_cell(0, 0, True) board.next_generation() self.assertEqual(board.get_cell(0, 0), False)
def test_larger_board_stimulating(self): board = game_of_life.GameOfLife(5, 5) board.set_cell(4, 3, True) self.assertEqual(board.get_cell(4, 3), True) self.assertEqual(board.get_cell(3, 3), False)
def test_cell_can_be_stimulated(self): board = game_of_life.GameOfLife(1, 1) board.set_cell(0, 0, True) self.assertEqual(board.get_cell(0, 0), True)
#!/usr/bin/env python3 import game_of_life as gol if __name__ == "__main__": game = gol.GameOfLife() game.init_game()