Beispiel #1
0
 def test_adjacent_mine_count_for_squares_near_mines(self):
     board = Board(beginner, [1, 2, 3])
     self.assertEqual(3, board.adjacent_mine_count(10))
     self.assertEqual(2, board.adjacent_mine_count(11))
     self.assertEqual(2, board.adjacent_mine_count(9))
     self.assertEqual(1, board.adjacent_mine_count(0))
     self.assertEqual(1, board.adjacent_mine_count(4))
Beispiel #2
0
 def test_adjacent_mine_count_for_corner_mines(self):
     # M   1   x   x   x
     #   1   x   x   x   x
     # x   x   x   x   x
     board = Board(hexagonal, [0])
     self.assertEqual(1, board.adjacent_mine_count(1))
     self.assertEqual(0, board.adjacent_mine_count(2))
     self.assertEqual(1, board.adjacent_mine_count(24))
     self.assertEqual(0, board.adjacent_mine_count(25))
     self.assertEqual(0, board.adjacent_mine_count(48))
Beispiel #3
0
 def test_adjacent_mine_count_for_high_mine_cells(self):
     # x   x   x   x   x
     #   x   1   2   1   x
     # x   1   M   M   2
     #   x   2   4   M   x
     # x   1   M   M   2
     board = Board(hexagonal, [50, 51, 75, 98, 99])
     self.assertEqual(5, board.adjacent_mine_count(74))
     self.assertEqual(2, board.adjacent_mine_count(26))
     self.assertEqual(2, board.adjacent_mine_count(73))
     self.assertEqual(1, board.adjacent_mine_count(97))
Beispiel #4
0
    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)
Beispiel #5
0
    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)
Beispiel #6
0
    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)
Beispiel #7
0
 def test_adjacent_mine_count_for_mine_islands(self):
     # x   x   x   x   x
     #   x   1   1   x   x
     # x   1   M   1   x
     #   x   1   1   x   x
     # x   x   x   x   x
     board = Board(hexagonal, [50])
     # above
     self.assertEqual(0, board.adjacent_mine_count(24))
     self.assertEqual(1, board.adjacent_mine_count(25))
     self.assertEqual(1, board.adjacent_mine_count(26))
     self.assertEqual(0, board.adjacent_mine_count(27))
     # mine row
     self.assertEqual(0, board.adjacent_mine_count(48))
     self.assertEqual(1, board.adjacent_mine_count(49))
     self.assertEqual(1, board.adjacent_mine_count(51))
     self.assertEqual(0, board.adjacent_mine_count(52))
     # below
     self.assertEqual(0, board.adjacent_mine_count(72))
     self.assertEqual(1, board.adjacent_mine_count(73))
     self.assertEqual(1, board.adjacent_mine_count(74))
     self.assertEqual(0, board.adjacent_mine_count(75))
Beispiel #8
0
 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)
Beispiel #9
0
 def test_adjacent_mine_count_for_empty_squares(self):
     board = Board(beginner, [1, 2, 3])
     self.assertEqual(0, board.adjacent_mine_count(63))