From 80a5161021093adedcf053a20bddfe3d20fd8152 Mon Sep 17 00:00:00 2001 From: Jan Gieseler Date: Mon, 16 Dec 2024 15:18:19 +0200 Subject: [PATCH] Refactor test assertions to use math.isclose for floating-point comparisons --- Bowtie/tests/test.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Bowtie/tests/test.py b/Bowtie/tests/test.py index bad34ad..0257034 100644 --- a/Bowtie/tests/test.py +++ b/Bowtie/tests/test.py @@ -1,4 +1,5 @@ import filecmp +import math import matplotlib import os import pytest @@ -51,8 +52,10 @@ def test_bowtie(): new_e1_results = bowtie.bowtie_analysis(channel=channel, spectra=spectra, plot=False) assert new_e1_results['geometric_factor'] == 0.000744084026271278 - assert new_e1_results['geometric_factor_errors'] == {'gfup': np.float64(4.407576153642298e-05), 'gflo': np.float64(3.07655324791197e-05)} - assert new_e1_results['effective_energy'] == np.float64(0.0713699882077903) + + assert math.isclose(new_e1_results['geometric_factor_errors']['gfup'], np.float64(4.407576153642298e-05)) + assert math.isclose(new_e1_results['geometric_factor_errors']['gflo'], np.float64(3.07655324791197e-05)) + assert math.isclose(new_e1_results['effective_energy'], np.float64(0.0713699882077903)) # assert new_e1_results['fig'] == # assert new_e1_results['axes'] == @@ -62,8 +65,10 @@ def test_bowtie(): # only check the last result assert all_channels_results[6]['geometric_factor'] == 0.2955529518148398 - assert all_channels_results[6]['geometric_factor_errors'] == {'gfup': np.float64(0.027996508853041446), 'gflo': np.float64(0.01830299979208344)} - assert all_channels_results[6]['effective_energy'] == np.float64(7.0097596149373445) + # assert all_channels_results[6]['geometric_factor_errors'] == {'gfup': np.float64(0.027996508853041446), 'gflo': np.float64(0.01830299979208344)} + assert math.isclose(all_channels_results[6]['geometric_factor_errors']['gfup'], np.float64(0.027996508853041446)) + assert math.isclose(all_channels_results[6]['geometric_factor_errors']['gflo'], np.float64(0.01830299979208344)) + assert math.isclose(all_channels_results[6]['effective_energy'], np.float64(7.0097596149373445)) # assert all_channels_results[6]['fig'] == # assert all_channels_results[6]['axes'] ==