added tests for simulation time start and end with breaks

This commit is contained in:
Luis Aleixo 2022-10-10 15:17:44 +02:00
parent 0b37aeca7d
commit 388465ba9b
2 changed files with 23 additions and 2 deletions

View file

@ -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()

View file

@ -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"],
[