From cc98bf003b7d2e7f918526595b07a20f1e10827a Mon Sep 17 00:00:00 2001 From: Nicolas Mounet Date: Fri, 4 Jun 2021 09:23:48 +0200 Subject: [PATCH] Fix the tests which depend on the gravitational settlement (tests on concentration, its integration, r0, etc.); set a common seed for all tests --- cara/tests/models/test_exposure_model.py | 12 ++++++------ cara/tests/test_known_quantities.py | 12 ++++++------ cara/tests/test_predefined_distributions.py | 2 +- cara/tests/test_sampleable_distribution.py | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cara/tests/models/test_exposure_model.py b/cara/tests/models/test_exposure_model.py index 35c5ac0c..1c6c6d3d 100644 --- a/cara/tests/models/test_exposure_model.py +++ b/cara/tests/models/test_exposure_model.py @@ -136,12 +136,12 @@ def conc_model(): # expected quanta were computed with a trapezoidal integration, using # a mesh of 10'000 pts per exposed presence interval. @pytest.mark.parametrize("exposed_time_interval, expected_quanta", [ - [(0, 1), 5.4869151], - [(1, 1.01), 0.064013521], - [(1.01, 1.02), 0.062266596], - [(12, 12.01), 0.0019025904], - [(12, 24), 78.190763], - [(0, 24), 84.866592], + [(0, 1), 5.3334352], + [(1, 1.01), 0.061759078], + [(1.01, 1.02), 0.060016487], + [(12, 12.01), 0.0019012647], + [(12, 24), 75.513005], + [(0, 24), 81.956988], ] ) def test_exposure_model_integral_accuracy(exposed_time_interval, diff --git a/cara/tests/test_known_quantities.py b/cara/tests/test_known_quantities.py index 4af1c06f..ab24bb08 100644 --- a/cara/tests/test_known_quantities.py +++ b/cara/tests/test_known_quantities.py @@ -44,7 +44,7 @@ def test_concentrations(baseline_model): concentrations = [baseline_model.concentration(t) for t in ts] npt.assert_allclose( concentrations, - [0.000000e+00, 0.4189594, 1.6422648e-14, 0.4189594, 6.4374587e-28], + [0.000000e+00, 0.41611256, 1.3205628e-14, 0.41611256, 4.1909001e-28], rtol=1e-6 ) @@ -91,7 +91,7 @@ def test_r0(baseline_exposure_model): # expected r0 was computed with a trapezoidal integration, using # a mesh of 100'000 pts per exposed presence interval. r0 = baseline_exposure_model.reproduction_number() - npt.assert_allclose(r0, 973.535888) + npt.assert_allclose(r0, 972.880852) def test_periodic_window(baseline_periodic_window, baseline_room): @@ -359,8 +359,8 @@ def build_exposure_model(concentration_model): @pytest.mark.parametrize( "month, expected_quanta", [ - ['Jan', 10.136783], - ['Jun', 41.800377], + ['Jan', 9.930854], + ['Jun', 37.962708], ], ) def test_quanta_hourly_dep(month,expected_quanta): @@ -379,8 +379,8 @@ def test_quanta_hourly_dep(month,expected_quanta): @pytest.mark.parametrize( "month, expected_quanta", [ - ['Jan', 10.19818], - ['Jun', 44.130683], + ['Jan', 9.989881], + ['Jun', 39.99636], ], ) def test_quanta_hourly_dep_refined(month,expected_quanta): diff --git a/cara/tests/test_predefined_distributions.py b/cara/tests/test_predefined_distributions.py index 1e066432..4197b2fb 100644 --- a/cara/tests/test_predefined_distributions.py +++ b/cara/tests/test_predefined_distributions.py @@ -5,7 +5,7 @@ import pytest from cara.monte_carlo.data import activity_distributions, virus_distributions # TODO: seed better the random number generators -np.random.seed(0) +np.random.seed(2000) # mean & std deviations from CERN-OPEN-2021-04 (Table 4) diff --git a/cara/tests/test_sampleable_distribution.py b/cara/tests/test_sampleable_distribution.py index 585b4dde..c30fcbf7 100644 --- a/cara/tests/test_sampleable_distribution.py +++ b/cara/tests/test_sampleable_distribution.py @@ -53,7 +53,7 @@ def test_lognormal(mean_gaussian, std_gaussian): assert len(samples) == sample_size npt.assert_allclose([samples.mean(), samples.std()], [exact_mean, exact_std], rtol=0.01) - npt.assert_allclose(selected_histogram, exact_dist, rtol=0.02) + npt.assert_allclose(selected_histogram, exact_dist, rtol=0.03) @pytest.mark.parametrize(