Skip to content

Commit 2cf8b37

Browse files
author
Eric Smyth
committed
Add tests for daily_growth_helper and updated display_header test to include test for daily growth when halving
1 parent 398cde4 commit 2cf8b37

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/penn_chime/parameters.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414

1515

1616
def daily_growth_helper(doubling_time):
17-
return (power(2, 1.0 / doubling_time) - 1) * 100
17+
result = 0
18+
if doubling_time != 0:
19+
result = (power(2, 1.0 / doubling_time) - 1) * 100
20+
return result
1821

1922

2023
class Parameters:

tests/test_app.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from src.penn_chime.charts import new_admissions_chart, admitted_patients_chart, chart_descriptions
1111
from src.penn_chime.models import sir, sim_sir, build_admissions_df
12-
from src.penn_chime.parameters import Parameters
12+
from src.penn_chime.parameters import Parameters, daily_growth_helper
1313
from src.penn_chime.presentation import display_header
1414
from src.penn_chime.settings import DEFAULTS
1515
from src.penn_chime.defaults import RateLos
@@ -79,11 +79,33 @@ def test_daily_growth():
7979
assert len((list(filter(lambda s: initial_growth in s, st.render_store))))
8080
assert len((list(filter(lambda s: mitigated_growth in s, st.render_store))))
8181
st.cleanup()
82+
mitigated_halving = "and daily growth rate of **-1.33%**."
83+
halving_params = Parameters(
84+
current_hospitalized=100,
85+
doubling_time=6.0,
86+
known_infected=5000,
87+
market_share=0.05,
88+
relative_contact_rate=0.7,
89+
susceptible=500000,
90+
hospitalized=RateLos(0.05, 7),
91+
icu=RateLos(0.02, 9),
92+
ventilated=RateLos(0.01, 10),
93+
n_days=60,
94+
)
95+
display_header(st, halving_params)
96+
assert len((list(filter(lambda s: mitigated_halving in s, st.render_store))))
97+
st.cleanup()
8298

8399

84100
st.cleanup()
85101

86102

103+
def test_daily_growth_helper():
104+
assert np.round(daily_growth_helper(5), decimals=4) == 14.8698
105+
assert np.round(daily_growth_helper(0), decimals=4) == 0.0
106+
assert np.round(daily_growth_helper(-4), decimals=4) == -15.9104
107+
108+
87109
@pytest.mark.xfail()
88110
def test_header_fail():
89111
"""

0 commit comments

Comments
 (0)