From 67e2a9e672d78761f992b667a113b8ec7c940420 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Tue, 13 Feb 2024 15:49:06 +0000 Subject: [PATCH] Fixed exact value atol bug for negative values --- causal_testing/testing/causal_test_outcome.py | 4 +++- tests/testing_tests/test_causal_test_outcome.py | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/causal_testing/testing/causal_test_outcome.py b/causal_testing/testing/causal_test_outcome.py index dc412e21..f045828c 100644 --- a/causal_testing/testing/causal_test_outcome.py +++ b/causal_testing/testing/causal_test_outcome.py @@ -77,9 +77,11 @@ class ExactValue(SomeEffect): def __init__(self, value: float, atol: float = None): self.value = value if atol is None: - self.atol = value * 0.05 + self.atol = abs(value * 0.05) else: self.atol = atol + if self.atol < 0: + raise ValueError("Tolerance must be an absolute value.") def apply(self, res: CausalTestResult) -> bool: if res.ci_valid(): diff --git a/tests/testing_tests/test_causal_test_outcome.py b/tests/testing_tests/test_causal_test_outcome.py index 74e724e3..a2b0173d 100644 --- a/tests/testing_tests/test_causal_test_outcome.py +++ b/tests/testing_tests/test_causal_test_outcome.py @@ -189,6 +189,10 @@ def test_exactValue_fail(self): ev = ExactValue(5, 0.1) self.assertFalse(ev.apply(ctr)) + def test_invalid_atol(self): + with self.assertRaises(ValueError): + ExactValue(5, -0.1) + def test_invalid(self): test_value = TestValue(type="invalid", value=5.05) ctr = CausalTestResult(