|
9 | 9 | from parcels import FieldSet |
10 | 10 | from virtualship.instruments.types import InstrumentType |
11 | 11 | from virtualship.models.expedition import Expedition |
| 12 | +from virtualship.models.location import Location |
12 | 13 | from virtualship.utils import ( |
| 14 | + PROJECTION, |
| 15 | + _calc_sail_time, |
13 | 16 | _calc_wp_stationkeeping_time, |
14 | 17 | _find_nc_file_with_variable, |
15 | 18 | _get_bathy_data, |
@@ -242,7 +245,25 @@ def test_data_dir_and_filename_compliance(): |
242 | 245 |
|
243 | 246 | # TODO: test for calc_sail_time |
244 | 247 |
|
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 |
246 | 267 |
|
247 | 268 |
|
248 | 269 | def test_calc_wp_stationkeeping_time(expedition, monkeypatch): |
@@ -296,8 +317,6 @@ class XBTConfig: # has no stationkeeping time |
296 | 317 | InstrumentType.XBT, |
297 | 318 | ] |
298 | 319 |
|
299 | | - breakpoint() |
300 | | - |
301 | 320 | # all dummy instruments |
302 | 321 | stationkeeping_time_all = _calc_wp_stationkeeping_time( |
303 | 322 | wp_instrument_types_all, expedition |
|
0 commit comments