Пример #1
0
    def test_try_remove_ship(self):
        field = Field()
        field.reset()

        self.assertFalse(field.try_remove_ship((0, 0)))
        field.try_place_new_ship((0, 0))
        self.assertTrue(field.try_remove_ship((0, 0)))
Пример #2
0
    def test_get_ship_on(self):
        field = Field()
        field.reset()
        field.try_place_new_ship((0, 0))

        self.assertFalse(field.get_ship_on((0, 0)) is None)
        self.assertTrue(field.get_ship_on((2, 3)) is None)
Пример #3
0
 def test_can_place_ship_on(self):
     field = Field()
     field.reset()
     self.assertFalse(field.can_place_ship_on(None, (0, 0)))
     field.try_place_new_ship((0, 0))
     self.assertFalse(field.can_place_ship_on(Ship(1), (-1, 0)))
     self.assertFalse(field.can_place_ship_on(Ship(1), (0, 0)))
     self.assertFalse(field.can_place_ship_on(Ship(1), (1, 1)))
     self.assertTrue(field.can_place_ship_on(Ship(1), (1, 2)))
Пример #4
0
    def test_shot(self):
        field = Field()
        field.reset()
        self.assertTrue(field.shot((0, 0))[0])
        self.assertFalse(field.shot((0, 0))[1])
        self.assertFalse(field.shot((0, 0))[0])
        self.assertFalse(field.shot((0, 0))[1])

        field.try_place_new_ship((4, 4))
        shot_result = field.shot((4, 4))
        self.assertTrue(shot_result[0])
        self.assertTrue(shot_result[1])