def test_opening_an_invalid_position_raises_an_exception(self): board = Board(beginner, [1, 2, 3], []) with self.assertRaises(InvalidPositionException): board.open(-1) with self.assertRaises(InvalidPositionException): board.open(100000)
def test_opening_a_flagged_position_removes_the_flag_from_the_position( self): board = Board(beginner, [1, 2, 3], []) board = board.toggle_flag(20) self.assertCountEqual([20], board.flagmap) board = board.open(20) self.assertCountEqual([], board.flagmap)
def test_opening_space_with_a_corner_mine(self): # M 1 x x x x x x # 1 1 x x x x x x # x x x x x x x x board = Board(beginner, [0], []) self.assertEqual(0, board.adjacent_mine_count(5)) board = board.open(5) expected_openmap = set((i for i in range(64))).difference([0]) self.assertCountEqual(expected_openmap, board.openmap)
def test_opening_space_with_some_side_mines(self): # H M M M 1 x x x # 1 2 3 2 1 x x x # x x x x x x x x # The top left corner isn't reachable from the open space, so it shouldn't be opened board = Board(beginner, [1, 2, 3], []) self.assertEqual(0, board.adjacent_mine_count(5)) board = board.open(5) expected_openmap = set((i for i in range(64))).difference([0, 1, 2, 3]) self.assertCountEqual(expected_openmap, board.openmap)
def test_opening_space_with_a_mine_island(self): # x x x x x x x x # x x 1 2 2 1 x x # x x 1 M M 1 x x # x x 1 2 2 1 x x # x x x x x x x x board = Board(beginner, [19, 20], []) self.assertEqual(0, board.adjacent_mine_count(0)) board = board.open(0) expected_openmap = set((i for i in range(64))).difference([19, 20]) self.assertCountEqual(expected_openmap, board.openmap)
def test_opening_an_position_adjacent_to_mines_doesnt_autoopen_other_positions( self): board = Board(beginner, [1, 2, 3], []) self.assertGreater(board.adjacent_mine_count(4), 0) board = board.open(4) self.assertCountEqual([4], board.openmap)
def test_opening_all_but_the_mines_wins_the_game(self): board = Board(beginner, [1, 2, 3], (i for i in range(4, 64))) self.assertIsNone(board.won()) board = board.open(0) self.assertTrue(board.won())
def test_opening_a_mine_loses_the_game(self): board = Board(beginner, [1, 2, 3], []) self.assertIsNone(board.won()) board = board.open(1) self.assertFalse(board.won())