"""Tests del sistema de coordenadas naval.""" from __future__ import annotations import pytest from pydantic import ValidationError from vmssailor.core import ShipCoord def test_construct_valid() -> None: c = ShipCoord(x_pp=10.0, y_cl=-1.5, z_bl=2.0) assert c.x_pp == 10.0 assert c.y_cl == -1.5 assert c.z_bl == 2.0 def test_frozen() -> None: c = ShipCoord(x_pp=10.0, y_cl=0.0, z_bl=1.0) with pytest.raises(ValidationError): c.x_pp = 99.0 # type: ignore[misc] def test_as_tuple() -> None: c = ShipCoord(x_pp=1.0, y_cl=2.0, z_bl=3.0) assert c.as_tuple() == (1.0, 2.0, 3.0) def test_is_starboard_port_centerline() -> None: starboard = ShipCoord(x_pp=5.0, y_cl=1.0, z_bl=0.0) port = ShipCoord(x_pp=5.0, y_cl=-1.0, z_bl=0.0) centerline = ShipCoord(x_pp=5.0, y_cl=0.0, z_bl=0.0) assert starboard.is_starboard() assert not starboard.is_port() assert not starboard.is_centerline() assert port.is_port() assert not port.is_starboard() assert centerline.is_centerline() assert not centerline.is_starboard() assert not centerline.is_port() def test_distance_to() -> None: a = ShipCoord(x_pp=0.0, y_cl=0.0, z_bl=0.0) b = ShipCoord(x_pp=3.0, y_cl=4.0, z_bl=0.0) assert a.distance_to(b) == pytest.approx(5.0) def test_out_of_range_rejected() -> None: with pytest.raises(ValidationError): ShipCoord(x_pp=999.0, y_cl=0.0, z_bl=0.0) with pytest.raises(ValidationError): ShipCoord(x_pp=10.0, y_cl=999.0, z_bl=0.0) with pytest.raises(ValidationError): ShipCoord(x_pp=10.0, y_cl=0.0, z_bl=-999.0) def test_extra_fields_forbidden() -> None: with pytest.raises(ValidationError): ShipCoord(x_pp=1.0, y_cl=0.0, z_bl=0.0, foo="bar") # type: ignore[call-arg] def test_str_representation() -> None: c = ShipCoord(x_pp=10.0, y_cl=-1.5, z_bl=2.0) s = str(c) assert "10.00" in s assert "-1.50" in s assert "+2.00" in s assert "[m]" in s