Skip to content

Commit

Permalink
fix ages
Browse files Browse the repository at this point in the history
  • Loading branch information
nitsanavni committed Nov 10, 2023
1 parent 366fe6b commit e18756d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
5 changes: 3 additions & 2 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self):
def __str__(self) -> str:
height = self.get_max_y() + 1
width = self.get_max_x() + 1
return "\n".join(["".join(["*" if self.is_alive(x, y) else " " for x in range(width)]) for y in range(height)])
return "\n".join(["".join([f"{self.get_age(x,y)}" if self.is_alive(x, y) else " " for x in range(width)]) for y in range(height)])

def get_max_x(self):
return max([cell[0] for cell in self.alive_cells], default=0)
Expand All @@ -24,7 +24,7 @@ def get_max_y(self):

def set_alive(self, x, y):
self.alive_cells.add((x, y))
self.cell_ages[(x, y)] = self.cell_ages.get((x, y), 0) + 1
self.cell_ages[(x, y)] = 1

def is_alive(self, x, y):
return (x, y) in self.alive_cells
Expand Down Expand Up @@ -64,6 +64,7 @@ def create_glider_at(game,x,y):

def verify_story_board(game,steps):
storyboard = Storyboard()
storyboard.add_frame(game)
for i in range(steps):
game.advance()
storyboard.add_frame(game)
Expand Down
31 changes: 18 additions & 13 deletions tests/test_samples.test_game_of_life.approved.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
Initial:
*
**
**
1
1 1
11

Frame #1:
*
*
***
1
21
22

Frame #2:

* *
**
*
1
2
331

Frame #3:

*
* *
**
1 3
42
1

Frame #4:

4
1 3
21

0 comments on commit e18756d

Please sign in to comment.