diff --git a/tests/test_functionaltest.py b/tests/test_functionaltest.py index e2af4b9..ef3befa 100644 --- a/tests/test_functionaltest.py +++ b/tests/test_functionaltest.py @@ -20,42 +20,6 @@ from simulation.model import Param, Model, Runner, MonitoredResource -@pytest.mark.parametrize('param_name, value, rule', [ - ('patient_inter', 0, 'positive'), - ('mean_n_consult_time', 0, 'positive'), - ('number_of_runs', 0, 'positive'), - ('audit_interval', 0, 'positive'), - ('warm_up_period', -1, 'non_negative'), - ('data_collection_period', -1, 'non_negative') -]) -def test_negative_inputs(param_name, value, rule): - """ - Check that the model fails when inputs that are zero or negative are used. - - Arguments: - param_name (string): - Name of parameter to change in the Param() class. - value (float|int): - Invalid value for parameter. - rule (string): - Either 'positive' (if value must be > 0) or 'non-negative' (if - value must be >= 0). - """ - # Create parameter class with an invalid value - param = Param(**{param_name: value}) - - # Construct the expected error message - if rule == 'positive': - expected_message = f'Parameter "{param_name}" must be greater than 0.' - else: - expected_message = (f'Parameter "{param_name}" must be greater than ' + - 'or equal to 0.') - - # Verify that initialising the model raises the correct error - with pytest.raises(ValueError, match=expected_message): - Model(param=param, run_number=0) - - def test_negative_results(): """ Check that values are non-negative. diff --git a/tests/test_unittest.py b/tests/test_unittest.py index f9761e0..9b0080f 100644 --- a/tests/test_unittest.py +++ b/tests/test_unittest.py @@ -22,7 +22,7 @@ import pytest from simulation.logging import SimLogger -from simulation.model import Param, Exponential +from simulation.model import Param, Model, Exponential def test_new_attribute(): @@ -38,6 +38,42 @@ def test_new_attribute(): param.new_entry = 3 +@pytest.mark.parametrize('param_name, value, rule', [ + ('patient_inter', 0, 'positive'), + ('mean_n_consult_time', 0, 'positive'), + ('number_of_runs', 0, 'positive'), + ('audit_interval', 0, 'positive'), + ('warm_up_period', -1, 'non_negative'), + ('data_collection_period', -1, 'non_negative') +]) +def test_negative_inputs(param_name, value, rule): + """ + Check that the model fails when inputs that are zero or negative are used. + + Arguments: + param_name (string): + Name of parameter to change in the Param() class. + value (float|int): + Invalid value for parameter. + rule (string): + Either 'positive' (if value must be > 0) or 'non-negative' (if + value must be >= 0). + """ + # Create parameter class with an invalid value + param = Param(**{param_name: value}) + + # Construct the expected error message + if rule == 'positive': + expected_message = f'Parameter "{param_name}" must be greater than 0.' + else: + expected_message = (f'Parameter "{param_name}" must be greater than ' + + 'or equal to 0.') + + # Verify that initialising the model raises the correct error + with pytest.raises(ValueError, match=expected_message): + Model(param=param, run_number=0) + + def test_exponentional(): """ Test that the Exponentional class behaves as expected.