|
| 1 | +import unittest |
| 2 | + |
| 3 | +from torpydo.game_controller import GameController |
| 4 | +from torpydo.ship import Color, Letter, Position, Ship |
| 5 | + |
| 6 | +class TestShip(unittest.TestCase): |
| 7 | + def setUp(self): |
| 8 | + self.ships = [] |
| 9 | + self.ships.append(init_ship(Ship("Test", 2, Color.RED), [Position(Letter.A, 1), Position(Letter.A, 2)])) |
| 10 | + |
| 11 | + def test_check_is_hit_true(self): |
| 12 | + self.assertTrue(GameController.check_is_hit(self.ships, Position(Letter.A, 1))) |
| 13 | + |
| 14 | + def test_check_is_hit_false(self): |
| 15 | + self.assertFalse(GameController.check_is_hit(self.ships, Position(Letter.B, 1))) |
| 16 | + |
| 17 | + def test_check_is_hit_position_none(self): |
| 18 | + with self.assertRaises(ValueError): |
| 19 | + self.assertRaises(GameController.check_is_hit(self.ships, None)) |
| 20 | + |
| 21 | + def test_check_is_hit_ship_none(self): |
| 22 | + with self.assertRaises(ValueError): |
| 23 | + self.assertRaises(GameController.check_is_hit(None, Position(Letter.A, 1))) |
| 24 | + |
| 25 | + def test_is_ship_valid_false(self): |
| 26 | + self.assertFalse(GameController.is_ship_valid(Ship("Not Valid", 3, Color.RED))) |
| 27 | + |
| 28 | + def test_is_ship_valid_true(self): |
| 29 | + self.assertTrue(GameController.is_ship_valid(self.ships[0])) |
| 30 | + |
| 31 | +def init_ship(ship: Ship, positions: list): |
| 32 | + ship.positions = positions |
| 33 | + |
| 34 | + return ship |
| 35 | + |
| 36 | +if '__main__' == __name__: |
| 37 | + unittest.main() |
0 commit comments