Skip to content

Commit 445ab60

Browse files
Adding more tests
1 parent ec5e9bd commit 445ab60

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

tests/v4/test_particleset.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
)
1717
from parcels._datasets.structured.generic import datasets as datasets_structured
1818
from parcels.xgrid import XGrid
19+
from tests.common_kernels import DoNothing
1920

2021

2122
@pytest.fixture
@@ -27,10 +28,6 @@ def fieldset() -> FieldSet:
2728
return FieldSet([U, V])
2829

2930

30-
def DoNothing(particle, fieldset, time):
31-
pass
32-
33-
3431
def test_pset_create_lon_lat(fieldset):
3532
npart = 100
3633
lon = np.linspace(0, 1, npart, dtype=np.float32)

tests/v4/test_particleset_execute.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from parcels._datasets.unstructured.generic import datasets as datasets_unstructured
1717
from parcels.uxgrid import UxGrid
1818
from parcels.xgrid import XGrid
19+
from tests.common_kernels import DoNothing
1920

2021

2122
@pytest.fixture
@@ -67,6 +68,25 @@ def AddLat(particle, fieldset, time): # pragma: no cover
6768
assert np.allclose([p.lat - n * 0.1 for p in pset], np.zeros(npart), rtol=1e-12)
6869

6970

71+
@pytest.mark.parametrize(
72+
"starttime, endtime, dt",
73+
[
74+
(0, 10, 1),
75+
(0, 10, 3),
76+
(2, 16, 3),
77+
(20, 10, -1),
78+
(20, -10, -2),
79+
],
80+
)
81+
def test_execution_endtime(fieldset, starttime, endtime, dt):
82+
starttime = fieldset.time_interval.left + np.timedelta64(starttime, "s")
83+
endtime = fieldset.time_interval.left + np.timedelta64(endtime, "s")
84+
dt = np.timedelta64(dt, "s")
85+
pset = ParticleSet(fieldset, time=starttime, lon=0, lat=0)
86+
pset.execute(DoNothing, endtime=endtime, dt=dt)
87+
assert np.isclose(pset.time_nextloop.values, endtime)
88+
89+
7090
@pytest.mark.parametrize("verbose_progress", [True, False])
7191
def test_uxstommelgyre_pset_execute(verbose_progress):
7292
ds = datasets_unstructured["stommel_gyre_delaunay"]

0 commit comments

Comments
 (0)