def test_get_cell_type(self): field = Field() point1 = (0, 0) point2 = (2, 0) ship = Ship(1) ship.placed_location = point2 field.ships.append(ship) ship.on_shot(point2) point3 = (4, 0) ship = Ship(1) ship.placed_location = point3 field.ships.append(ship) point4 = (6, 0) ship = Ship(2) ship.rotate() ship.placed_location = point4 field.ships.append(ship) ship.on_shot(point4) point5 = (8, 0) field.shot(point5) self.assertEqual(field.get_cell_type(point1, True), Cell.Empty) self.assertEqual(field.get_cell_type(point2, True), Cell.FullDeadShip) self.assertEqual(field.get_cell_type(point3, True), Cell.ShipPeace) self.assertEqual(field.get_cell_type(point4, True), Cell.DeadShipPeace) self.assertEqual(field.get_cell_type(point5, True), Cell.Shot) self.assertEqual(field.get_cell_type(point5, False), Cell.Empty) self.assertEqual(field.get_cell_type(point2, False), Cell.ShipPeace)
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])