Skip to content

Commit

Permalink
fix: use almost_equal for tests so we don't get floating point errors
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidni committed Jun 20, 2024
1 parent 6e60fca commit a76caaf
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions seismostats/analysis/tests/test_estimate_mc.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(
[
Expand Down Expand Up @@ -190,15 +188,15 @@ 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
best_mc, best_beta, mcs_tested, betas, ks_ds, ps = mc_ks(
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)
Expand Down

0 comments on commit a76caaf

Please sign in to comment.