"""Tests de Vessel, Deck, Bulkhead.""" from __future__ import annotations import pytest from pydantic import ValidationError from vmssailor.core import Vessel, VesselSubtype, VesselType from vmssailor.core.vessel import Bulkhead, Deck def test_deck_height() -> None: d = Deck(id="main", name="Main", z_bl_bottom=2.0, z_bl_top=4.5) assert d.height() == pytest.approx(2.5) def test_deck_polygon_empty_ok() -> None: Deck(id="main", name="Main", z_bl_bottom=2.0, z_bl_top=4.5) def test_deck_polygon_too_few_vertices_rejected() -> None: with pytest.raises(ValidationError): Deck( id="main", name="Main", z_bl_bottom=2.0, z_bl_top=4.5, polygon_xy=[(0.0, 0.0), (1.0, 0.0)], ) def test_minimal_vessel(minimal_vessel: Vessel) -> None: assert minimal_vessel.length_overall_m == 24.0 assert minimal_vessel.type == VesselType.YACHT_MOTOR assert minimal_vessel.subtype == VesselSubtype.PLANING assert len(minimal_vessel.decks) == 1 def test_vessel_duplicate_deck_ids_rejected() -> None: with pytest.raises(ValidationError): Vessel( id="x", name="X", type=VesselType.YACHT_MOTOR, subtype=VesselSubtype.PLANING, length_overall_m=20.0, beam_max_m=5.0, draft_m=1.5, decks=[ Deck(id="main", name="A", z_bl_bottom=0.0, z_bl_top=2.0), Deck(id="main", name="B", z_bl_bottom=2.0, z_bl_top=4.0), ], ) def test_vessel_position_helpers(minimal_vessel: Vessel) -> None: bow = minimal_vessel.position_at_bow() assert bow.x_pp == minimal_vessel.length_overall_m origin = minimal_vessel.position_at_origin() assert origin.x_pp == 0.0 def test_vessel_invalid_length_rejected() -> None: with pytest.raises(ValidationError): Vessel( id="x", name="X", type=VesselType.YACHT_MOTOR, subtype=VesselSubtype.PLANING, length_overall_m=-1.0, beam_max_m=5.0, draft_m=1.5, ) def test_bulkhead_basic() -> None: b = Bulkhead(id="col", name="Collision", x_pp=21.0) assert b.x_pp == 21.0 assert b.description == ""