Skip to content

Commit c708804

Browse files
author
PJ Hoberman
committed
Added some more tests around sir and sim_sir, removed old initial conditions test
1 parent da39136 commit c708804

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

src/test_app.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
import pandas as pd
3-
3+
import numpy as np
44

55
from app import (projection_admits, alt)
66
from penn_chime.models import sir, sim_sir, sim_sir_df, Parameters
@@ -81,12 +81,18 @@ def test_sir():
8181
"""
8282
Someone who is good at testing, help
8383
"""
84-
assert sir(100, 1, 0, 0.2, 0.5, 1) == (
84+
sir_test = sir(100, 1, 0, 0.2, 0.5, 1)
85+
assert sir_test == (
8586
0.7920792079207921,
8687
0.20297029702970298,
8788
0.0049504950495049506,
8889
), "This contrived example should work"
8990

91+
assert isinstance(sir_test, tuple)
92+
for v in sir_test:
93+
assert isinstance(v, float)
94+
assert v >= 0
95+
9096
# Certain things should *not* work
9197
with pytest.raises(TypeError) as error:
9298
sir("S", 1, 0, 0.2, 0.5, 1)
@@ -121,7 +127,8 @@ def test_sim_sir():
121127
"""
122128
Rounding to move fast past decimal place issues
123129
"""
124-
s, i, r = sim_sir(5, 6, 7, 0.1, 0.1, 40)
130+
sim_sir_test = sim_sir(5, 6, 7, 0.1, 0.1, 40)
131+
s, i, r = sim_sir_test
125132

126133
assert round(s[0], 0) == 5
127134
assert round(i[0], 2) == 6
@@ -130,6 +137,11 @@ def test_sim_sir():
130137
assert round(i[-1], 2) == 0.18
131138
assert round(r[-1], 2) == 17.82
132139

140+
assert isinstance(sim_sir_test, tuple)
141+
for v in sim_sir_test:
142+
assert isinstance(v, np.ndarray)
143+
144+
133145

134146
def test_sim_sir_df():
135147
"""
@@ -147,25 +159,6 @@ def test_sim_sir_df():
147159
assert round(last[2], 2) == 17.82
148160

149161

150-
#ef test_initial_conditions():
151-
# """
152-
# Note: For the rates (ie hosp_rate) - just change the value, leave the "100" alone.
153-
# Easier to change whole numbers than decimals.
154-
# """
155-
# assert current_hosp == known_cases
156-
# assert doubling_time == 6
157-
# assert relative_contact_rate == 0
158-
# assert hosp_rate == 5 / 100
159-
# assert icu_rate == 2 / 100
160-
# assert vent_rate == 1 / 100
161-
# assert hosp_los == 7
162-
# assert icu_los == 9
163-
# assert vent_los == 10
164-
# assert market_share == 15 / 100
165-
# assert S == S_default
166-
# assert initial_infections == known_infections
167-
168-
169162
def test_new_admissions_chart():
170163
chart = new_admissions_chart(alt, projection_admits, 60 - 10)
171164
assert isinstance(chart, alt.Chart)

0 commit comments

Comments
 (0)