From 388465ba9b33830b22be4a2b3ffd3ab93f18fa85 Mon Sep 17 00:00:00 2001 From: Luis Aleixo Date: Mon, 10 Oct 2022 15:17:44 +0200 Subject: [PATCH] added tests for simulation time start and end with breaks --- caimira/apps/calculator/model_generator.py | 9 +++++++-- .../apps/calculator/test_aria_model_generator.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/caimira/apps/calculator/model_generator.py b/caimira/apps/calculator/model_generator.py index 52cca792..13bac79f 100644 --- a/caimira/apps/calculator/model_generator.py +++ b/caimira/apps/calculator/model_generator.py @@ -744,6 +744,11 @@ class FormData: # Parse break times. begin = time_string_to_minutes(n["start_time"]) end = time_string_to_minutes(n["finish_time"]) + for time in [begin, end]: + # In ARIA, the infected and exposed presence is the same. + if not getattr(self, 'infected_start') < time < getattr(self, 'infected_finish'): + raise ValueError(f'All breaks should be within the simulation time. Got {time_minutes_to_string(time)}.') + break_times.append((begin, end)) return tuple(break_times) @@ -840,7 +845,7 @@ class FormData: return models.SpecificInterval(tuple(present_intervals)) def infected_present_interval(self) -> models.Interval: - if len(self.aria_breaks) > 0: # It means the breaks were defined by ARIA interface + if self.aria_breaks != []: # It means the breaks were defined by ARIA interface breaks = self.generate_aria_break_times() else: breaks = self.infected_lunch_break_times() + self.infected_coffee_break_times() @@ -855,7 +860,7 @@ class FormData: return models.SpecificInterval(present_times=((start_time/60, (start_time + duration)/60),)) def exposed_present_interval(self) -> models.Interval: - if len(self.aria_breaks) > 0: # It means the breaks were defined by ARIA interface + if self.aria_breaks != []: # It means the breaks were defined by ARIA interface breaks = self.generate_aria_break_times() else: breaks = self.exposed_lunch_break_times() + self.exposed_coffee_break_times() diff --git a/caimira/tests/apps/calculator/test_aria_model_generator.py b/caimira/tests/apps/calculator/test_aria_model_generator.py index 7474d5e8..bb87bbdd 100644 --- a/caimira/tests/apps/calculator/test_aria_model_generator.py +++ b/caimira/tests/apps/calculator/test_aria_model_generator.py @@ -22,6 +22,21 @@ def test_aria_break_data_structure(break_input, error, baseline_form: model_gene baseline_form.validate() +@pytest.mark.parametrize( + ["break_input", "error"], + [ + [[{"start_time": "07:00", "finish_time": "11:00"}, ], "All breaks should be within the simulation time. Got 07:00."], + [[{"start_time": "17:00", "finish_time": "18:00"}, ], "All breaks should be within the simulation time. Got 18:00."], + [[{"start_time": "10:00", "finish_time": "11:00"}, {"start_time": "17:00", "finish_time": "20:00"}, ], "All breaks should be within the simulation time. Got 20:00."], + [[{"start_time": "08:00", "finish_time": "11:00"}, {"start_time": "14:00", "finish_time": "15:00"}, ], "All breaks should be within the simulation time. Got 08:00."], + ] +) +def test_aria_break_time(break_input, error, baseline_form: model_generator.FormData): + baseline_form.aria_breaks = break_input + with pytest.raises(ValueError, match=error): + baseline_form.generate_aria_break_times() + + @pytest.mark.parametrize( ["precise_activity_input", "error"], [ @@ -40,6 +55,7 @@ def test_aria_precise_activity_structure(precise_activity_input, error, baseline with pytest.raises(TypeError, match=error): baseline_form.validate() + @pytest.mark.parametrize( ["precise_activity_input", "error"], [