def iterate(self): new_grid = Grid() for x, y in self.get_candidate_cells(): neighbors = self.get_num_of_neighbors(x, y) alive_now = self[(x, y)] alive_next = alive_next_turn(neighbors, alive_now) if alive_next: new_grid[(x, y)] = True return new_grid
def test_statusquo_2_neighbors_and_alive_stays_alive(): assert alive_next_turn(2, True)
def test_underpop(): assert not alive_next_turn(1, True)
def test_overpop(): assert not alive_next_turn(4, True)
def test_birth(): assert alive_next_turn(3, False)
def test_statusquo_2_neighbors_and_dead_stays_dead(): assert not alive_next_turn(2, False)
def test_statusquo_3_neighbors_and_alive_stays_alive(): assert alive_next_turn(3, True)