Skip to content

Commit 970d8ad

Browse files
committed
test for dt
1 parent b1c0c74 commit 970d8ad

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/unit/test_stepsize.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,21 @@ def test_hit_stepsize_max_with_t_stop(time):
130130
)
131131
max_stepsize = lambda t: 1 if t >= 1 else None
132132
assert my_stepsize.adaptive_stepsize["max_stepsize"](time) == max_stepsize(time)
133+
134+
135+
@pytest.mark.parametrize("time", [1, 2.5, "coucou", np.array([1, 2]), [1, 2]])
136+
def test_stepsize_as_value(time):
137+
"""
138+
A test to check that users can pass an int or float to the dt attribute when
139+
initialising a F.Simulation class, and an error is raised when passed anything else
140+
"""
141+
142+
my_model = festim.Simulation()
143+
144+
if isinstance(time, (int, float, festim.Stepsize)):
145+
my_model.dt = time
146+
else:
147+
with pytest.raises(
148+
TypeError, match="dt must be an int, float, or festim.Stepsize"
149+
):
150+
my_model.dt = time

0 commit comments

Comments
 (0)