Skip to content

Commit f06e024

Browse files
Expanding unit test to check for Particle._index behaviour
1 parent 708b825 commit f06e024

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

tests/v4/test_particleset_execute.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,20 @@ def fieldset() -> FieldSet:
2828
return FieldSet([U, V])
2929

3030

31-
def test_pset_remove_particle_in_kernel(fieldset, npart=100):
31+
def test_pset_remove_particle_in_kernel(fieldset):
32+
npart = 100
3233
pset = ParticleSet(fieldset, lon=np.linspace(0, 1, npart), lat=np.linspace(1, 0, npart))
3334

3435
def DeleteKernel(particle, fieldset, time): # pragma: no cover
35-
if particle.lon >= 0.4:
36+
if particle.lon >= 0.4 and particle.lon <= 0.6:
3637
particle.delete()
3738

3839
pset.execute(pset.Kernel(DeleteKernel), runtime=np.timedelta64(1, "s"), dt=np.timedelta64(1, "s"))
39-
assert pset.size == 40
40+
indices = [i for i in range(npart) if not (40 <= i < 60)]
41+
assert [p.trajectory for p in pset] == indices
42+
assert pset[70].trajectory == 90
43+
assert pset[-1].trajectory == npart - 1
44+
assert pset.size == 80
4045

4146

4247
def test_pset_stop_simulation(fieldset):

0 commit comments

Comments
 (0)