Exemple #1
0
    def testRefreshCell(self):
        self.board[0] = [0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1]
        self.board[1] = [0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1]
        self.board[2] = [0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1]

        data = [{
            'pos': (1, 1),
            'expected': 0
        }, {
            'pos': (1, 3),
            'expected': 0
        }, {
            'pos': (1, 5),
            'expected': 1
        }, {
            'pos': (1, 7),
            'expected': 1
        }, {
            'pos': (1, 11),
            'expected': 1
        }, {
            'pos': (1, 14),
            'expected': 0
        }]

        for d in data:
            with self.subTest():
                new_cell_value = game_of_life.refresh_cell(
                    d['pos'], self.board)
                self.assertEqual(d['expected'], new_cell_value)
Exemple #2
0
    def testDeadWithLessThan2NeighboursAlive(self):
        self.board[0] = [1, 0, 0]
        self.board[1] = [0, 1, 0]
        self.board[2] = [0, 0, 0]

        cell_coord = (1, 1)

        self.board[cell_coord[0]][cell_coord[1]] = game_of_life.refresh_cell(
            cell_coord, self.board)

        self.assertFalse(game_of_life.is_alive(cell_coord, self.board))
Exemple #3
0
    def testDeadWith3NeighboursAliveBecomeAlive(self):
        self.board[0] = [1, 1, 0]
        self.board[1] = [0, 0, 0]
        self.board[2] = [0, 0, 1]

        cell_coord = (1, 1)

        self.board[cell_coord[0]][cell_coord[1]] = game_of_life.refresh_cell(
            cell_coord, self.board)

        self.assertTrue(game_of_life.is_alive(cell_coord, self.board))
Exemple #4
0
    def testAliveWithMoreThan3NeighboursAliveBecomeDead(self):
        self.board[0] = [1, 1, 1]
        self.board[1] = [0, 1, 0]
        self.board[2] = [0, 0, 1]

        cell_coord = (1, 1)

        self.board[cell_coord[0]][cell_coord[1]] = game_of_life.refresh_cell(
            cell_coord, self.board)

        self.assertFalse(game_of_life.is_alive(cell_coord, self.board))