Skip to content

Commit f9310c2

Browse files
Merge pull request #102 from CodeForPhilly/60-tests
#60 Initial tests
2 parents b7c9f75 + 4307fac commit f9310c2

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

__init__.py

Whitespace-only changes.

test_app.py

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import pytest
2+
import pandas as pd
23

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
510

611

712
# set up
@@ -75,3 +80,52 @@ def test_sir():
7580
0.20297029702970298,
7681
0.0049504950495049506,
7782
), "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

Comments
 (0)