Improve the testing of ConcentrationModel.last_state_change

This commit is contained in:
Phil Elson 2021-08-06 09:29:12 +02:00
parent 9546c1966c
commit 43b9b864af
2 changed files with 27 additions and 1 deletions

View file

@ -775,7 +775,7 @@ class ConcentrationModel:
def last_state_change(self, time: float) -> float:
"""
Find the most recent state change.
Find the most recent/previous state change.
"""
for change_time in self.state_change_times()[::-1]:

View file

@ -68,6 +68,32 @@ def simple_conc_model():
)
@pytest.mark.parametrize(
"time, expected_last_state_change", [
[0., 0],
[1., 0],
[1.05, 1.],
[1.1, 1.],
[1.11, 1.1],
[1.999, 1.1],
[1.9991, 1.999],
[2., 1.999],
[2.1, 2],
[3., 2],
]
)
def test_last_state_change_time(
simple_conc_model: models.ConcentrationModel,
time,
expected_last_state_change,
):
assert simple_conc_model.last_state_change(float(time)) == expected_last_state_change
def test_last_state_change_time_out_of_range(simple_conc_model: models.ConcentrationModel):
assert simple_conc_model.last_state_change(3.1) == 3.0
@pytest.mark.parametrize(
"time, expected_next_state_change", [
[0, 0],