diff --git a/tests/test_statops_compare.py b/tests/test_statops_compare.py index e83be41..70bf8fe 100644 --- a/tests/test_statops_compare.py +++ b/tests/test_statops_compare.py @@ -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) @@ -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(): @@ -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():