Skip to content

Commit

Permalink
test for dt
Browse files Browse the repository at this point in the history
  • Loading branch information
jhdark committed Jan 13, 2025
1 parent b1c0c74 commit 970d8ad
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/unit/test_stepsize.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,21 @@ def test_hit_stepsize_max_with_t_stop(time):
)
max_stepsize = lambda t: 1 if t >= 1 else None
assert my_stepsize.adaptive_stepsize["max_stepsize"](time) == max_stepsize(time)


@pytest.mark.parametrize("time", [1, 2.5, "coucou", np.array([1, 2]), [1, 2]])
def test_stepsize_as_value(time):
"""
A test to check that users can pass an int or float to the dt attribute when
initialising a F.Simulation class, and an error is raised when passed anything else
"""

my_model = festim.Simulation()

if isinstance(time, (int, float, festim.Stepsize)):
my_model.dt = time
else:
with pytest.raises(
TypeError, match="dt must be an int, float, or festim.Stepsize"
):
my_model.dt = time

0 comments on commit 970d8ad

Please sign in to comment.