Example #1
0
 def test_get_count_bombs(self):
     my_grid = Grid(3, 3)
     self.assertEqual(my_grid.get_count_bombs(), 0)
     my_grid.get(0, 0).is_bomb = True
     self.assertEqual(my_grid.get_count_bombs(), 1)
     my_grid.get(2, 2).is_bomb = True
     self.assertEqual(my_grid.get_count_bombs(), 2)
     for j in range(3):
         for i in range(3):
             my_grid.get(i, j).is_bomb = True
     self.assertEqual(my_grid.get_count_bombs(), 9)
     my_grid.get(1, 1).is_bomb = False
     self.assertEqual(my_grid.get_count_bombs(), 8)
Example #2
0
    def test_seed_grid(self):
        my_grid = Grid(10, 20)
        my_grid.seed_grid(10)
        self.assertEqual(my_grid.get_count_bombs(), 10)

        with self.assertRaises(TypeError,
                               msg='Num_Bombs needs to be an integer.'):
            my_grid.seed_grid(1.1)
            my_grid.seed_grid(True)
            my_grid.seed_grid('stuff')
            my_grid.seed_grid([1, 2, 3])

        with self.assertRaises(ValueError, msg='Too many bombs.'):
            my_grid.seed_grid(300)

        with self.assertRaises(ValueError, msg='Too many bombs.'):
            my_grid.seed_grid(200)

        my_grid.seed_grid(199)
        self.assertEqual(my_grid.get_count_bombs(), 199)

        my_grid.seed_grid(0)
        self.assertEqual(my_grid.get_count_bombs(), 0)