Esempio n. 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]
Esempio n. 2
0
    def __init__(self, state=Dead()):
        """
        Ctor - Initialises the cell with a state in which it can start the game of life.

        @param state The initial state of the cell. If no argument is given, defaults to dead.
        """
        Cell.__init__(self, state)
Esempio n. 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]
Esempio n. 4
0
    def __init__(self, state=Dead()):
        '''
        Sets the initial state of the cell to dead.

        Keyword arguments:
        state -- Initial state of cell. Defaults to Dead
        '''
        Cell.__init__(self, state)