Skip to content

Commit ba27cab

Browse files
authored
Add Conservation Test
Add conservation test
2 parents 76dd9b9 + 4920d13 commit ba27cab

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

tests/test_app.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ def test_model_raw_start():
293293
first = raw_df.iloc[0, :]
294294
second = raw_df.iloc[1, :]
295295

296-
assert first.susceptible + first.infected + first.recovered == param.population
297296
assert first.susceptible == 499600.0
298297
assert round(second.infected, 0) == 449.0
299298
assert list(model.dispositions_df.iloc[0, :]) == [-43, date(year=2020, month=2, day=15), 1.0, 0.4, 0.2]
@@ -304,13 +303,29 @@ def test_model_raw_start():
304303
assert [round(v, 0) for v in (d, s, i, r)] == [17, 549.0, 220.0, 110.0]
305304

306305

306+
def test_model_conservation():
307+
p = copy(PARAM)
308+
m = Model(p)
309+
raw_df = m.raw_df
310+
311+
assert (0.0 <= raw_df.susceptible).all()
312+
assert (0.0 <= raw_df.infected).all()
313+
assert (0.0 <= raw_df.recovered).all()
314+
315+
diff = raw_df.susceptible + raw_df.infected + raw_df.recovered - p.population
316+
assert (diff < 0.1).all()
317+
318+
assert (raw_df.susceptible <= p.population).all()
319+
assert (raw_df.infected <= p.population).all()
320+
assert (raw_df.recovered <= p.population).all()
321+
322+
307323
def test_model_raw_end():
308324
param = copy(PARAM)
309325
model = Model(param)
310326
raw_df = model.raw_df
311327

312328
last = raw_df.iloc[-1, :]
313-
assert last.susceptible + last.infected + last.recovered == param.population
314329
assert round(last.susceptible, 0) == 83391.0
315330

316331

0 commit comments

Comments
 (0)