From a76caaf5e41c3bbda43359fd5f41e9ef1ff555ce Mon Sep 17 00:00:00 2001 From: Nicolas Schmid Date: Thu, 20 Jun 2024 16:49:42 +0200 Subject: [PATCH] fix: use almost_equal for tests so we don't get floating point errors --- seismostats/analysis/tests/test_estimate_mc.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/seismostats/analysis/tests/test_estimate_mc.py b/seismostats/analysis/tests/test_estimate_mc.py index 54faeb7..c94e3ca 100644 --- a/seismostats/analysis/tests/test_estimate_mc.py +++ b/seismostats/analysis/tests/test_estimate_mc.py @@ -1,13 +1,11 @@ -from numpy.testing import assert_allclose, assert_equal -import numpy as np import pickle + +import numpy as np import pytest +from numpy.testing import assert_allclose, assert_almost_equal, assert_equal -from seismostats.analysis.estimate_mc import ( - empirical_cdf, - mc_max_curvature, - mc_ks, -) +from seismostats.analysis.estimate_mc import (empirical_cdf, mc_ks, + mc_max_curvature) @pytest.fixture @@ -148,7 +146,7 @@ def test_estimate_mc_ks(mags, mcs): mags, delta_m=0.1, mcs_test=mcs, p_pass=0.1 ) assert_equal(1.1, best_mc) - assert_equal(2.242124985031149, best_beta) + assert_almost_equal(2.242124985031149, best_beta) assert_equal([0.8, 0.9, 1.0, 1.1], mcs_tested) assert_allclose( [ @@ -190,7 +188,7 @@ def test_estimate_mc_ks(mags, mcs): mags, delta_m=0.1, p_pass=0.1 ) assert_equal(1.1, best_mc) - assert_equal(2.242124985031149, best_beta) + assert_almost_equal(2.242124985031149, best_beta) assert_equal([1.0, 1.1], mcs_tested) # test when b-positive is used @@ -198,7 +196,7 @@ def test_estimate_mc_ks(mags, mcs): mags, delta_m=0.1, b_method="positive" ) assert_equal(1.5, best_mc) - assert_equal(3.2542240043462796, best_beta) + assert_almost_equal(3.2542240043462796, best_beta) assert_equal(len(mcs_tested), 6) assert_equal(len(betas), 6) assert_equal(len(ks_ds), 6)