示例#1
0
 def setUp(self):
     create_test_board = CreateTestBoard(BOARD_ROWS, BOARD_COLUMNS, TOTAL_MINES)
     self.board = Board(create_test_board)
示例#2
0
class BoardTest(TestCase):
    def setUp(self):
        create_test_board = CreateTestBoard(BOARD_ROWS, BOARD_COLUMNS, TOTAL_MINES)
        self.board = Board(create_test_board)

    def test_click_mine(self):
        self.failUnlessEqual(self.board.is_mined(0,0), True, 'There was no mine at 0,0')
        self.failUnlessEqual(self.board.is_mined(1,0), False, 'There was no mine at 1,0')

    def test_place_flag(self):
        self.board.place_flag(0,0)
        self.failUnlessEqual(self.board.flags_left(), TOTAL_MINES - 1, 'A flag was not placed')

        self.board.place_flag(0,0)
        self.failUnlessEqual(self.board.flags_left(), TOTAL_MINES, 'Flag was not unclicked')

    def test_win(self):
        for column in range(BOARD_COLUMNS - 1):
            self.board.place_flag(0, column)

        self.failUnlessEqual(self.board.has_won(), False, 'The player should not have won')

        for column in range(5, BOARD_COLUMNS):
            self.board.place_flag(1, column)
        self.failUnlessEqual(self.board.has_won(), True, 'The player should have won but did not')

    def test_get_num_surronding_mines(self):
        mines_surronding = self.board.get_num_surronding_mines(2, 4)
        self.failUnlessEqual(mines_surronding, 1, 'There should be one bordering mine at 2,4 found: ' + str(mines_surronding))

        mines_surronding = self.board.get_num_surronding_mines(1, 0)
        self.failUnlessEqual(mines_surronding, 2, 'There should be two bordering mines at 1,0 found: ' + str(mines_surronding))

        mines_surronding = self.board.get_num_surronding_mines(7, 7)
        self.failUnlessEqual(mines_surronding, 0, 'There should be zero bordering mines at 7,7 found: ' + str(mines_surronding))

    def test_get_clear_area(self):
        clear_area = self.board.get_clear_area(7,7, [])
        NUM_CLEAR_RETURNED = 53
        self.failUnlessEqual(len(clear_area), NUM_CLEAR_RETURNED)