Skip to content

Commit b4e1d8b

Browse files
committed
TEST: Explicitly test that we are exercising w2_thresh
1 parent d0da775 commit b4e1d8b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

nibabel/tests/test_quaternions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,28 @@ def test_fillpos_precision(dtype):
7575
rand = np.random.default_rng()
7676
# Permit 1 epsilon per value
7777
w2_thresh = 3 * -np.finfo(dtype).eps
78+
79+
pos_error = neg_error = False
7880
for _ in range(50):
7981
xyz = rand.uniform(size=(3,)).astype(dtype)
8082
# Normalize to unit vector up to type precision
8183
xyz /= np.sqrt(xyz @ xyz)
8284
wxyz = nq.fillpositive(xyz, w2_thresh)
8385
assert wxyz[0] == 0.0
8486

87+
# Verify that we exercise the threshold
88+
magnitude = xyz @ xyz
89+
if magnitude < 1:
90+
pos_error = True
91+
elif magnitude > 1:
92+
neg_error = True
93+
94+
if pos_error and neg_error:
95+
break
96+
97+
assert pos_error, 'Did not encounter a case where 1 - |xyz| > 0'
98+
assert neg_error, 'Did not encounter a case where 1 - |xyz| < 0'
99+
85100

86101
def test_conjugate():
87102
# Takes sequence

0 commit comments

Comments
 (0)