Example #1
0
    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]
Example #2
0
    def test_grid_init(self):
        """
        This method tests that a Grid object initialises correctly. The expected result of this test is for a Grid
        to be initialised with a number of cells, which are all of state State.
        """
        pattern = [[Cell(),
                    Cell(),
                    Cell(),
                    Cell()],
                   [Cell(),
                    Cell(),
                    Cell(),
                    Cell()],
                   [Cell(),
                    Cell(),
                    Cell(),
                    Cell()],
                   [Cell(),
                    Cell(),
                    Cell(),
                    Cell()]]

        test_grid = Grid(pattern)
        # Assert that the grid has been initialised.
        assert test_grid

        cells = test_grid.get_cells()

        for row in cells:
            # For each row of cells
            for c in row:
                # Assert that the state of a cell is State.
                assert isinstance(c.get_state(), State)
Example #3
0
    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]
Example #4
0
    def test_grid_init(self):
        '''
        Tests correct initialisation of grid objects. Objects should initialise
        with a number of cells that are all dead.
        '''
        pattern = [[Cell(),
                    Cell(),
                    Cell(),
                    Cell()],
                   [Cell(),
                    Cell(),
                    Cell(),
                    Cell()],
                   [Cell(),
                    Cell(),
                    Cell(),
                    Cell()],
                   [Cell(),
                    Cell(),
                    Cell(),
                    Cell()]]

        test_grid = Grid(pattern)
        assert test_grid

        cells = test_grid.get_cells()

        for row in cells:
            for c in row:
                assert isinstance(c.get_state(), State)
Example #5
0
    def __init__(self, cell_pattern=create_empty_grid()):
        """
        Ctor - initialises the grid as a two-dimensional array of GoLCells.

        @param cell_pattern If the cell pattern is given to this method as a parameter, it is used as the initial
                            cell configuration for the grid, otherwise, all the cells in the grid are set to dead.
        """
        Grid.__init__(self, cell_pattern)
Example #6
0
    def test_get_cells(self):
        '''
        Tests the ability for the grid to return its collection of cells.
        '''
        test_grid = Grid()

        cells = test_grid.get_cells()
        assert cells
Example #7
0
    def test_get_cells(self):
        """
        Tests the ability for the grid to return its collection of cells.

        This method tests the ability of the Grid to retrieve the cells that it contains. The expected result of this
        test is for the correct number of cells to be retrieved.
        """
        test_grid = Grid()

        cells = test_grid.get_cells()
        # Assert that the cells have been retrieved.
        assert cells
Example #8
0
    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