def test_grid_clear(self): my_grid = Grid(3, 3) self.assertEqual(my_grid, Grid(3, 3)) my_grid.get(0, 0).is_bomb = True my_grid.get(1, 1).state = State.FLAGGED my_grid.get(2, 2).state = State.OPEN # Not default anymore so not equal default. self.assertNotEqual(my_grid, Grid(3, 3)) my_grid.clear() # reset should be equal again. self.assertEqual(my_grid, Grid(3, 3))
def test_open(self): my_grid = Grid(3, 3) # Don't open if the game isn't playing my_grid._state = GameState.WIN my_grid.open(0, 0) expected = [' ', ' ', ' '] self.assertEqual(expected, self.grid_to_string(my_grid)) my_grid._state = GameState.PLAYING # Empty grid will expose everything on click. my_grid.open(1, 1) expected = ['___', '___', '___'] self.assertEqual(expected, self.grid_to_string(my_grid)) # Empty grid with a bomb in the middle. my_grid.clear() expected = [' ', ' X ', ' '] my_grid.get(1, 1).is_bomb = True my_grid.open(1, 1) self.assertEqual(expected, self.grid_to_string(my_grid)) # New game with two bombs nothing opened my_grid.clear() expected = [' x', ' ', 'x '] my_grid.get(2, 0).is_bomb = True my_grid.get(0, 2).is_bomb = True self.assertEqual(expected, self.grid_to_string(my_grid)) # Same grid open at 1, 0 my_grid.open(1, 0) expected = [' 1x', ' ', 'x '] self.assertEqual(expected, self.grid_to_string(my_grid)) # Same grid open at 1, 0 my_grid.open(0, 0) expected = ['_1x', '1 ', 'x '] self.assertEqual(expected, self.grid_to_string(my_grid)) my_grid = Grid(4, 4) my_grid.get(0, 1).is_bomb = True my_grid.get(1, 3).is_bomb = True my_grid.open(2, 1) expected = [' 1__', 'x1__', ' 1_', ' x1_'] self.assertEqual(expected, self.grid_to_string(my_grid)) my_grid = Grid(3, 4) my_grid.get(1, 1).is_bomb = True my_grid.get(2, 2).is_bomb = True my_grid.open(0, 3) expected = [' ', ' x ', '1 x', '_1 '] self.assertEqual(expected, self.grid_to_string(my_grid))