Added validation for number of infected people <= number of total people

This commit is contained in:
Luis Aleixo 2022-07-29 10:01:34 +02:00
parent 814f1dc625
commit fc20bc9e9d
2 changed files with 11 additions and 0 deletions

View file

@ -185,6 +185,10 @@ class FormData:
return form_dict
def validate(self):
# Validate number of infected <= number of total people
if self.infected_people > self.total_people:
raise ValueError('Number of infected people should be less than number of total people.')
# Validate time intervals selected by user
time_intervals = [
['exposed_start', 'exposed_finish'],

View file

@ -167,6 +167,13 @@ def test_ventilation_window_hepa(baseline_form: model_generator.FormData):
assert ventilation == baseline_vent
def test_infected_less_than_total_people(baseline_form: model_generator.FormData):
baseline_form.total_people = 10
baseline_form.infected_people = 11
with pytest.raises(ValueError, match='Number of infected people should be less than number of total people.'):
baseline_form.validate()
def present_times(interval: models.Interval) -> models.BoundarySequence_t:
assert isinstance(interval, models.SpecificInterval)
return interval.present_times