Skip to content

Commit aa4b017

Browse files
committed
TEST: Check case that exceeds threshold
Also remove explicit check that we randomly generated positive and negative errors. Failing this check is unlikely, but not a bug.
1 parent 6b9b676 commit aa4b017

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

nibabel/tests/test_quaternions.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ def test_fillpositive_plus_minus_epsilon(dtype):
9191
assert nq.fillpositive(plus)[0] == 0.0
9292
assert nq.fillpositive(minus)[0] == 0.0
9393

94+
# |(x, y, z)| > 1, no real solutions
95+
plus = baseline * nptype(1 + 2 * np.finfo(dtype).eps)
96+
with pytest.raises(ValueError):
97+
nq.fillpositive(plus)
98+
99+
# |(x, y, z)| < 1, two real solutions, we choose positive
100+
minus = baseline * nptype(1 - 2 * np.finfo(dtype).eps)
101+
assert nq.fillpositive(minus)[0] > 0.0
102+
94103

95104
@pytest.mark.parametrize('dtype', ('f4', 'f8'))
96105
def test_fillpositive_simulated_error(dtype):
@@ -107,18 +116,7 @@ def test_fillpositive_simulated_error(dtype):
107116
for _ in range(50):
108117
xyz = norm(gen_vec(dtype))
109118

110-
wxyz = nq.fillpositive(xyz, w2_thresh)
111-
assert wxyz[0] == 0.0
112-
113-
# Verify that we exercise the threshold
114-
magnitude = xyz @ xyz
115-
if magnitude < 1:
116-
pos_error = True
117-
elif magnitude > 1:
118-
neg_error = True
119-
120-
assert pos_error, 'Did not encounter a case where 1 - |xyz| > 0'
121-
assert neg_error, 'Did not encounter a case where 1 - |xyz| < 0'
119+
assert nq.fillpositive(xyz, w2_thresh)[0] == 0.0
122120

123121

124122
def test_conjugate():

0 commit comments

Comments
 (0)