Skip to content

Commit c000515

Browse files
committed
add test for _calc_sail_time
1 parent ab0489e commit c000515

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

tests/test_utils.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
from parcels import FieldSet
1010
from virtualship.instruments.types import InstrumentType
1111
from virtualship.models.expedition import Expedition
12+
from virtualship.models.location import Location
1213
from virtualship.utils import (
14+
PROJECTION,
15+
_calc_sail_time,
1316
_calc_wp_stationkeeping_time,
1417
_find_nc_file_with_variable,
1518
_get_bathy_data,
@@ -242,7 +245,25 @@ def test_data_dir_and_filename_compliance():
242245

243246
# TODO: test for calc_sail_time
244247

245-
# TODO: test for calc_stationkeeping_time
248+
249+
def test_calc_sail_time(projection=PROJECTION):
250+
LATITUDE = 0.0 # constant at equator
251+
252+
location1 = Location(latitude=LATITUDE, longitude=0.0)
253+
location2 = Location(latitude=LATITUDE, longitude=1.0)
254+
ship_speed_knots = 10.0
255+
256+
sail_time, _, ship_speed_ms = _calc_sail_time(
257+
location1, location2, ship_speed_knots, projection
258+
)
259+
260+
# should be approximately 21638 seconds (6 hours, 0 minutes, 38 seconds)
261+
assert abs(sail_time.total_seconds() - 21638) < 10 # small tolerance
262+
263+
calculated_distance_m = ship_speed_ms * sail_time.total_seconds()
264+
assert (
265+
abs(calculated_distance_m - 111319) < 100
266+
) # # 1 degree longitude at equator ≈ 111319 meters; allow small tolerance
246267

247268

248269
def test_calc_wp_stationkeeping_time(expedition, monkeypatch):
@@ -296,8 +317,6 @@ class XBTConfig: # has no stationkeeping time
296317
InstrumentType.XBT,
297318
]
298319

299-
breakpoint()
300-
301320
# all dummy instruments
302321
stationkeeping_time_all = _calc_wp_stationkeeping_time(
303322
wp_instrument_types_all, expedition

0 commit comments

Comments
 (0)