Skip to content

Commit 90deb17

Browse files
committed
Error tests
1 parent 8be258e commit 90deb17

2 files changed

Lines changed: 77 additions & 6 deletions

File tree

codonPython/tests/tolerance_test.py

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55
import pytest
66

77

8+
testdata = [
9+
np.array([1234, 1235, 1236, 1237, 1238, 1239, 1240, 1241, 1242]),
10+
np.array([1, 2, 3, 4, 5, 5.5, 6, 6.5, 7]),
11+
]
12+
13+
814
@pytest.mark.parametrize("t, y, to_exclude, poly_features, alpha, expected", [
915
(
10-
np.array([1234,1235,1236,1237,1238,1239,1240,1241,1242]),
11-
np.array([1,2,3,4,5,5.5,6,6.5,7]),
16+
*testdata,
1217
2,
1318
[1, 2],
1419
0.05,
@@ -36,8 +41,7 @@
3641
})
3742
),
3843
(
39-
np.array([1234,1235,1236,1237,1238,1239,1240,1241,1242]),
40-
np.array([1,2,3,4,5,5.5,6,6.5,7]),
44+
*testdata,
4145
2,
4246
[3],
4347
0.05,
@@ -70,4 +74,68 @@ def test_tolerance_checking_BAU(t, y, to_exclude, poly_features, alpha, expected
7074
assert expected.equals(obtained)
7175

7276

73-
#@pytest.mark.parametrize("t, y, to_exclude, poly_features, alpha, forecast", [])
77+
@pytest.mark.parametrize("t, y, to_exclude, poly_features, alpha", [
78+
(
79+
*testdata,
80+
2,
81+
"flamingo", # This should be a list
82+
0.05,
83+
),
84+
(
85+
*testdata,
86+
2,
87+
[2],
88+
"flamingo", # Needs to be int
89+
),
90+
(
91+
*testdata,
92+
2,
93+
[2],
94+
42, # Needs to be between 0 and 1
95+
),
96+
(
97+
*testdata,
98+
"flamingo", # Needs to be int
99+
[2],
100+
0.05,
101+
),
102+
])
103+
def test_ValueErrors(t, y, to_exclude, poly_features, alpha):
104+
with pytest.raises(ValueError):
105+
check_tolerance(t, y, to_exclude=to_exclude,
106+
poly_features=poly_features, alpha=alpha)
107+
108+
109+
@pytest.mark.parametrize("t, y, to_exclude, poly_features, alpha", [
110+
(
111+
*testdata,
112+
2,
113+
[42], # Elements in the list should be between 0 and 4
114+
0.05,
115+
),
116+
(
117+
*testdata,
118+
42, # Can't have to_exclude making your sample size smaller than 4
119+
[2],
120+
0.05,
121+
),
122+
(
123+
np.array([1234, 1235, 1236, 1237, 1238, 1239,
124+
1240, 1241, np.nan]), # Missing t value
125+
np.array([1, 2, 3, 4, 5, 5.5, 6, 6.5, 7]),
126+
2,
127+
[2],
128+
0.05,
129+
),
130+
(
131+
np.array([1234, 1235, 1236, 1237, 1238, 1239, 1240, 1241, 1242]),
132+
np.array([1, 2, 3, 4, 5, 5.5, 6, 6.5, np.nan]), # Missing y value
133+
2,
134+
[2],
135+
0.05,
136+
)
137+
])
138+
def test_AssertionErrors(t, y, to_exclude, poly_features, alpha):
139+
with pytest.raises(AssertionError):
140+
check_tolerance(t, y, to_exclude=to_exclude,
141+
poly_features=poly_features, alpha=alpha)

codonPython/tolerance.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def check_tolerance(t, y, to_exclude: int = 1, poly_features: list = [1, 2], alp
6060
)
6161
if not isinstance(alpha, float) or 0 > alpha >= 1:
6262
raise ValueError("Please input a float between 0 and 1 for alpha.")
63-
if not isinstance(to_exclude, int) or len(t) <= to_exclude < 1:
63+
if not isinstance(to_exclude, int):
6464
raise ValueError("Please input an integer between 1 and your sample size for to_exclude.")
6565
assert ((len(t) - to_exclude) >= 4), (
6666
"""The sample size for your model is smaller than 4. This will not produce a good
@@ -69,6 +69,9 @@ def check_tolerance(t, y, to_exclude: int = 1, poly_features: list = [1, 2], alp
6969
assert np.isfinite(y).all(), (
7070
"Your sample contains missing or infinite values for y. Exclude these values to continue."
7171
)
72+
assert np.isfinite(t).all(), (
73+
"Your sample contains missing or infinite values for x. Exclude these values to continue."
74+
)
7275

7376

7477
# Sort data by X increasing

0 commit comments

Comments
 (0)