generated from carpentries-incubator/python-intermediate-inflammation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_models.py
64 lines (52 loc) · 2.02 KB
/
test_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Tests for statistics functions within the Model layer."""
import numpy as np
import numpy.testing as npt
import pytest
@pytest.mark.parametrize(
"test, expected",
[
([[0, 0], [0, 0], [0, 0]], [0, 0]),
([[1, 2], [3, 4], [5, 6]], [3, 4]),
]
)
def test_daily_mean(test, expected):
"""Test that mean function works for an array of zeros."""
from inflammation.models import daily_mean
# Need to use Numpy testing functions to compare arrays
npt.assert_array_equal(daily_mean(test), expected)
def test_daily_min_string():
'''Test for TypeError when we pass a string'''
from inflammation.models import daily_min
with pytest.raises(TypeError):
error_expected = daily_min([['abd', 'ads'], ['asd', 'auhs']])
@pytest.mark.parametrize(
"test, expected",
[
([[0, 0, 0], [0, 0, 0], [0, 0, 0]], [0, 0, 0]),
([[4, 2, 5], [1, 6, 2], [4, 1, 9]], [4, 6, 9]),
([[4, -2, 5], [1, -6, 2], [-4, -1, 9]], [4, -1, 9]),
])
def test_daily_max(test, expected):
"""Test that max function works for an array of positive integers."""
from inflammation.models import daily_max
npt.assert_array_equal(daily_max(test), expected)
@pytest.mark.parametrize(
"test, expected",
[
([[0, 0, 0], [0, 0, 0], [0, 0, 0]], [0, 0, 0]),
([[4, 2, 5], [1, 6, 2], [4, 1, 9]], [1, 1, 2]),
([[4, -2, 5], [1, -6, 2], [-4, -1, 9]], [-4, -6, 2]),
])
def test_daily_min(test, expected):
"""Test that min function works for an array of positive and negative integers."""
from inflammation.models import daily_min
npt.assert_array_equal(daily_min(test), expected)
@pytest.mark.parametrize(
"test, expected",
[
([[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[0.33, 0.67, 1], [0.67, 0.83, 1], [0.78, 0.89, 1]])
])
def test_patient_normalise(test, expected):
"""Test normalisation works"""
from inflammation.models import patient_normalise
npt.assert_almost_equal(patient_normalise(np.array(test)), np.array(expected), decimal=2)