Skip to content

Commit 371356a

Browse files
author
PJ Hoberman
committed
added tests around the new Parameters class
1 parent f5faf04 commit 371356a

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/test_app.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,52 @@ def test_new_admissions_chart():
175175

176176
empty_chart = new_admissions_chart(alt, pd.DataFrame(), -1)
177177
assert empty_chart.data.empty
178+
179+
180+
def test_parameters():
181+
from penn_chime.models import Parameters
182+
from penn_chime.defaults import RateLos
183+
param = Parameters(
184+
current_hospitalized=100,
185+
doubling_time=6.0,
186+
known_infected=5000,
187+
market_share=0.05,
188+
relative_contact_rate=0.15,
189+
susceptible=500000,
190+
hospitalized=RateLos(0.05, 7),
191+
icu=RateLos(0.02, 9),
192+
ventilated=RateLos(0.01, 10),
193+
n_days=60
194+
)
195+
196+
# test the Parameters
197+
198+
# hospitalized, icu, ventilated
199+
assert param.rates == (0.05, 0.02, 0.01)
200+
assert param.lengths_of_stay == (7, 9, 10)
201+
202+
assert param.infected == 40000.0
203+
assert isinstance(param.infected, float) # based off note in models.py
204+
205+
# test the class-calculated attributes
206+
assert param.detection_probability == 0.125
207+
assert param.intrinsic_growth_rate == 0.12246204830937302
208+
assert param.beta == 3.2961405355450555e-07
209+
assert param.r_t == 2.307298374881539
210+
assert param.r_naught == 2.7144686763312222
211+
assert param.doubling_time_t == 7.764405988534983
212+
213+
# test the things n_days creates, which in turn tests sim_sir, sir, and get_dispositions
214+
assert len(param.susceptible_v) == len(param.infected_v) == len(param.recovered_v) == param.n_days + 1 == 61
215+
216+
assert param.susceptible_v[0] == 500000.0
217+
assert round(param.susceptible_v[-1], 0) == 67202
218+
assert round(param.infected_v[1], 0) == 43735
219+
assert round(param.recovered_v[30], 0) == 224048
220+
assert [d[0] for d in param.dispositions] == [100.0, 40.0, 20.0]
221+
assert [round(d[-1], 0) for d in param.dispositions] == [115.0, 46.0, 23.0]
222+
223+
# change n_days, make sure it cascades
224+
param.n_days = 2
225+
assert len(param.susceptible_v) == len(param.infected_v) == len(param.recovered_v) == param.n_days + 1 == 3
226+

0 commit comments

Comments
 (0)