Skip to content

Commit 80a5161

Browse files
committed
Refactor test assertions to use math.isclose for floating-point comparisons
1 parent 6b6f8b3 commit 80a5161

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Bowtie/tests/test.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import filecmp
2+
import math
23
import matplotlib
34
import os
45
import pytest
@@ -51,8 +52,10 @@ def test_bowtie():
5152
new_e1_results = bowtie.bowtie_analysis(channel=channel, spectra=spectra, plot=False)
5253

5354
assert new_e1_results['geometric_factor'] == 0.000744084026271278
54-
assert new_e1_results['geometric_factor_errors'] == {'gfup': np.float64(4.407576153642298e-05), 'gflo': np.float64(3.07655324791197e-05)}
55-
assert new_e1_results['effective_energy'] == np.float64(0.0713699882077903)
55+
56+
assert math.isclose(new_e1_results['geometric_factor_errors']['gfup'], np.float64(4.407576153642298e-05))
57+
assert math.isclose(new_e1_results['geometric_factor_errors']['gflo'], np.float64(3.07655324791197e-05))
58+
assert math.isclose(new_e1_results['effective_energy'], np.float64(0.0713699882077903))
5659
# assert new_e1_results['fig'] ==
5760
# assert new_e1_results['axes'] ==
5861

@@ -62,8 +65,10 @@ def test_bowtie():
6265

6366
# only check the last result
6467
assert all_channels_results[6]['geometric_factor'] == 0.2955529518148398
65-
assert all_channels_results[6]['geometric_factor_errors'] == {'gfup': np.float64(0.027996508853041446), 'gflo': np.float64(0.01830299979208344)}
66-
assert all_channels_results[6]['effective_energy'] == np.float64(7.0097596149373445)
68+
# assert all_channels_results[6]['geometric_factor_errors'] == {'gfup': np.float64(0.027996508853041446), 'gflo': np.float64(0.01830299979208344)}
69+
assert math.isclose(all_channels_results[6]['geometric_factor_errors']['gfup'], np.float64(0.027996508853041446))
70+
assert math.isclose(all_channels_results[6]['geometric_factor_errors']['gflo'], np.float64(0.01830299979208344))
71+
assert math.isclose(all_channels_results[6]['effective_energy'], np.float64(7.0097596149373445))
6772
# assert all_channels_results[6]['fig'] ==
6873
# assert all_channels_results[6]['axes'] ==
6974

0 commit comments

Comments
 (0)