From f22ba928e066572b31d81878231c50d50b416937 Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Fri, 6 Aug 2021 15:16:48 +0200 Subject: [PATCH] Ensure that 0 is always one of the state change times. --- cara/models.py | 2 +- cara/tests/models/test_concentration_model.py | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cara/models.py b/cara/models.py index 9d202391..51fc2bbf 100644 --- a/cara/models.py +++ b/cara/models.py @@ -769,7 +769,7 @@ class ConcentrationModel: the times at which their state changes. """ - state_change_times = set() + state_change_times = {0.} state_change_times.update(self.infected.presence.transition_times()) state_change_times.update(self.ventilation.transition_times()) return sorted(state_change_times) diff --git a/cara/tests/models/test_concentration_model.py b/cara/tests/models/test_concentration_model.py index b5895f21..46e7e88e 100644 --- a/cara/tests/models/test_concentration_model.py +++ b/cara/tests/models/test_concentration_model.py @@ -53,7 +53,7 @@ def test_concentration_model_vectorisation(override_params): @pytest.fixture def simple_conc_model(): - interesting_times = models.SpecificInterval(([0., 1.], [1.1, 1.999], [2., 3.]), ) + interesting_times = models.SpecificInterval(([0.5, 1.], [1.1, 2], [2., 3.]), ) return models.ConcentrationModel( models.Room(75), models.AirChange(interesting_times, 100), @@ -71,14 +71,14 @@ def simple_conc_model(): @pytest.mark.parametrize( "time, expected_last_state_change", [ [-15., 0.], # Out of range goes to the first state. - [0., 0], - [1., 0], + [0., 0.], + [0.5, 0.0], + [0.51, 0.5], + [1., 0.5], [1.05, 1.], [1.1, 1.], [1.11, 1.1], - [1.999, 1.1], - [1.9991, 1.999], - [2., 1.999], + [2., 1.1], [2.1, 2], [3., 2], [15., 3.], # Out of range goes to the last state. @@ -94,12 +94,12 @@ def test_last_state_change_time( @pytest.mark.parametrize( "time, expected_next_state_change", [ - [0, 0], + [0.0, 0.0], + [0.5, 0.5], [1, 1], [1.05, 1.1], [1.1, 1.1], - [1.11, 1.999], - [1.9991, 2], + [1.11, 2], [2, 2], [2.1, 3], [3, 3],