Skip to content

Commit

Permalink
glider collides with square in 22 frames
Browse files Browse the repository at this point in the history
  • Loading branch information
nitsanavni committed Nov 10, 2023
1 parent 9443722 commit ae4d27e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
26 changes: 22 additions & 4 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@ def __init__(self, game_of_life,width=10,height=10):
self.root = tk.Tk()
self.root.title("Game of Life")
self.cell_size = 10
self.frame_duration = 400
self.frame_duration = 250
self.cells = {}
self.create_widgets()

def show(self):
def show(self, num_of_iterations=-1):
self.iterations = 0
self.num_of_iterations = num_of_iterations
self.root.after(self.frame_duration, self.advance_turn)
self.root.mainloop()

def advance_turn(self):
if self.iterations == self.num_of_iterations:
self.root.destroy()
return
self.iterations += 1
self.game.advance()
self.update_cells()
self.root.after(self.frame_duration, self.advance_turn)
Expand Down Expand Up @@ -55,9 +61,15 @@ def update_cells(self):

def test_tkinter_gui():
game = GameOfLife()
create_square_at(game, 8, 8)
create_glider_at(game, 0, 0)
gui = TkinterGui(game)
gui.show()
gui.show(22)

def create_blinker_at(game,x,y):
game.set_alive(x+0,y+1)
game.set_alive(x+1,y+1)
game.set_alive(x+2,y+1)

def create_square_at(game,x,y):
game.set_alive(x+0,y+0)
Expand All @@ -72,6 +84,12 @@ def create_glider_at(game,x,y):
game.set_alive(x+2,y+1)
game.set_alive(x+2,y+2)

def create_applesauce_at(game,x,y):
create_square_at(game,x,y)
create_square_at(game,x+3,y)
create_square_at(game,x,y+3)
create_square_at(game,x+3,y+3)

def verify_story_board(game,steps):
storyboard = Storyboard()
storyboard.add_frame(game)
Expand All @@ -83,7 +101,7 @@ def verify_story_board(game,steps):
def test_game_of_life():
game = GameOfLife()
create_glider_at(game, 0, 0)
verify_story_board(game,4)
verify_story_board(game,5)

def test_game_of_life_with_blinker():
game = GameOfLife()
Expand Down
6 changes: 6 additions & 0 deletions tests/test_samples.test_game_of_life.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ Frame #4:
1 3
21

Frame #5:

1
41
32

0 comments on commit ae4d27e

Please sign in to comment.