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)))
def test_get_next(self): field = Field() field.reset() self.assertFalse(field.get_next_ship_to_place() is None) field.ships_to_place = [] self.assertTrue(field.get_next_ship_to_place() is None)
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)
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)))
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])
def test_reset(self): field = Field() field.reset() self.assertEqual(len(field.ships), 0) self.assertEqual(len(field.shots), 0) self.assertEqual(len(field.ships_to_place), 10)