|
1 | 1 | import pytest
|
| 2 | +import pandas as pd |
2 | 3 |
|
3 |
| -from penn_chime.models import sir |
4 |
| -from penn_chime.presentation import display_header |
| 4 | +from app import (S_default, known_infections, known_cases, current_hosp, doubling_time, relative_contact_rate, |
| 5 | + hosp_rate, icu_rate, vent_rate, hosp_los, icu_los, vent_los, market_share, S, initial_infections, |
| 6 | + detection_prob, hospitalization_rates, I, R, beta, gamma, n_days, beta_decay, |
| 7 | + projection_admits, alt) |
| 8 | +from penn_chime.models import sir, sim_sir |
| 9 | +from penn_chime.presentation import display_header, new_admissions_chart |
5 | 10 |
|
6 | 11 |
|
7 | 12 | # set up
|
@@ -75,3 +80,52 @@ def test_sir():
|
75 | 80 | 0.20297029702970298,
|
76 | 81 | 0.0049504950495049506,
|
77 | 82 | ), "This contrived example should work"
|
| 83 | + |
| 84 | + |
| 85 | +def test_sim_sir(): |
| 86 | + """ |
| 87 | + Rounding to move fast past decimal place issues |
| 88 | + """ |
| 89 | + s, i, r = sim_sir(S, I, R, beta, gamma, n_days, beta_decay=beta_decay) |
| 90 | + assert round(s[0], 0) == 4119405 |
| 91 | + assert round(s[-1], 2) == 3421436.31 |
| 92 | + assert round(i[0], 2) == 533.33 |
| 93 | + assert round(i[-1], 2) == 418157.62 |
| 94 | + assert round(r[0], 0) == 0 |
| 95 | + assert round(r[-1], 2) == 280344.40 |
| 96 | + |
| 97 | + |
| 98 | +def test_initial_conditions(): |
| 99 | + """ |
| 100 | + Note: For the rates (ie hosp_rate) - just change the value, leave the "100" alone. |
| 101 | + Easier to change whole numbers than decimals. |
| 102 | + """ |
| 103 | + assert current_hosp == known_cases |
| 104 | + assert doubling_time == 6 |
| 105 | + assert relative_contact_rate == 0 |
| 106 | + assert hosp_rate == 5 / 100 |
| 107 | + assert icu_rate == 2 / 100 |
| 108 | + assert vent_rate == 1 / 100 |
| 109 | + assert hosp_los == 7 |
| 110 | + assert icu_los == 9 |
| 111 | + assert vent_los == 10 |
| 112 | + assert market_share == 15 / 100 |
| 113 | + assert S == S_default |
| 114 | + assert initial_infections == known_infections |
| 115 | + |
| 116 | + |
| 117 | +def test_derived_variables(): |
| 118 | + assert hospitalization_rates == (hosp_rate, icu_rate, vent_rate) |
| 119 | + assert detection_prob == initial_infections / (current_hosp / market_share / hosp_rate) |
| 120 | + |
| 121 | + |
| 122 | +def test_new_admissions_chart(): |
| 123 | + chart = new_admissions_chart(alt, projection_admits, n_days - 10) |
| 124 | + assert type(chart) == alt.Chart |
| 125 | + assert chart.data.iloc[1].Hospitalized < 1 |
| 126 | + assert round(chart.data.iloc[49].ICU, 0) == 43 |
| 127 | + with pytest.raises(TypeError): |
| 128 | + new_admissions_chart() |
| 129 | + |
| 130 | + empty_chart = new_admissions_chart(alt, pd.DataFrame(), -1) |
| 131 | + assert empty_chart.data.empty |
0 commit comments