Make ApproxScalar hashable

This commit is contained in:
Kale Kundert 2022-07-03 18:52:32 -04:00
parent 5f57481563
commit 01bb8013e8
No known key found for this signature in database
GPG Key ID: C6238221D17CAFAE
2 changed files with 6 additions and 2 deletions

View File

@ -459,8 +459,8 @@ class ApproxScalar(ApproxBase):
result: bool = abs(self.expected - actual) <= self.tolerance
return result
# Ignore type because of https://github.com/python/mypy/issues/4266.
__hash__ = None # type: ignore
def __hash__(self):
return hash(self.expected)
@property
def tolerance(self):

View File

@ -346,6 +346,10 @@ class TestApprox:
assert 10 != approx(1, rel=1e-6, abs=1e-12)
assert not (10 == approx(1, rel=1e-6, abs=1e-12))
def test_hash(self):
assert {1} == {approx(1, rel=1e-6, abs=1e-12)}
assert {1+1e-5} != {approx(1, rel=1e-6, abs=1e-12)}
def test_exactly_equal(self):
examples = [
(2.0, 2.0),