def test_set_cells(self): """ Tests the ability of the grid to store a collection of cells. This method tests the ability of the grid to store a collection of cells. The expected result of this test is for the correct cells to be set to the Grid. """ test_grid = Grid() # Create a collection of cell objects # Hard coding the expectation of a 10 x 10 2D array as it will fail # if someone changes the keyword parameters s = 10 cells = [] for x in range(0, s): cells.append([]) for y in range(0, s): c = Cell() if y % 2 == 0: c.set_state(State()) cells[x].append(c) test_grid.set_cells(cells) # Asert that the collection has been correctly stored. assert test_grid.get_cells() recieved_cells = test_grid.get_cells() for x, row in enumerate(recieved_cells): # For each row of cells for y, _column in enumerate(row): # Assert that the expected cell has been stored in this grid 'coordinate'. assert recieved_cells[x][y] == cells[x][y]
def test_set_cells(self): ''' Tests the ability of the grid to store a collection of cells. ''' test_grid = Grid() # Create a collection of cell objects # Hard coding the expectation of a 10 x 10 2D array as it will fail # if someone changes the keyword parameters s = 10 cells = [] for x in range(0, s): cells.append([]) for y in range(0, s): c = Cell() if y % 2 == 0: c.set_state(State()) cells[x].append(c) # Write a test to check that the collection has been stored test_grid.set_cells(cells) assert test_grid.get_cells() # Write a test to check that the correct collection has been stored recieved_cells = test_grid.get_cells() for x, row in enumerate(recieved_cells): for y, _column in enumerate(row): assert recieved_cells[x][y] == cells[x][y]
def set_cells(self, cells): """ This method sets the grid to have the specified cell collection. @param cells The new collection of cells to be set to the grid. """ Grid.set_cells(self, cells) self._no_alive_cells = 0 for row in self._cells: for cell in row: if cell.is_alive(): self._no_alive_cells += 1