Skip to content

Commit

Permalink
Add robust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matejak committed Sep 8, 2024
1 parent 317acba commit d96cbde
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/test_statops_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import pytest


def montecarlo_is_lower_test(one, two, samples=1000):
rvs_one, rvs_two = [est._get_rv().rvs(samples) for est in (one, two)]
return sum(rvs_one < rvs_two) / samples


def integ_approx(x):
return pytest.approx(x, abs=tm.INTEGRATION_PRECISION)

Expand All @@ -23,6 +28,7 @@ def test_compare_equal():
assert tm.estimate_is_lower(simple_estimate, simple_estimate) == 0.5
concrete_estimate = data.Estimate.from_triple(2, 1, 3)
assert tm.estimate_is_lower(concrete_estimate, concrete_estimate) == 0.5
assert montecarlo_is_lower_test(concrete_estimate, concrete_estimate) == pytest.approx(0.5, abs=0.05)


def test_compare_clear():
Expand All @@ -47,7 +53,20 @@ def test_compare_overlapping():
assert 0.5 < tm.estimate_is_lower(low_estimate, almost_low_estimate) < 0.6
low_end_estimate = data.Estimate.from_triple(0.5, 0, 1)
assert 0.1 < tm.estimate_is_lower(low_estimate, low_end_estimate) < 0.2
assert 0.8 < tm.estimate_is_lower(low_end_estimate, low_estimate) < 0.9
rate = tm.estimate_is_lower(low_end_estimate, low_estimate)
assert 0.8 < rate < 0.9
assert montecarlo_is_lower_test(low_end_estimate, low_estimate) == pytest.approx(rate, abs=0.05)


def test_compare_general():
one = data.Estimate.from_triple(2, 1, 3)
two = data.Estimate.from_triple(1.5, -2, 4)
rate = tm.estimate_is_lower(one, two)
assert montecarlo_is_lower_test(one, two, 4000) == pytest.approx(rate, abs=0.01)
one = data.Estimate.from_triple(2.5, 1, 3)
two = data.Estimate.from_triple(1.5, 1, 4)
rate = tm.estimate_is_lower(one, two)
assert montecarlo_is_lower_test(one, two) == pytest.approx(rate, abs=0.05)


def test_compare_weighted():
Expand Down

0 comments on commit d96cbde

Please sign in to comment.