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 result: bool = abs(self.expected - actual) <= self.tolerance
return result return result
# Ignore type because of https://github.com/python/mypy/issues/4266. def __hash__(self):
__hash__ = None # type: ignore return hash(self.expected)
@property @property
def tolerance(self): def tolerance(self):

View File

@ -346,6 +346,10 @@ class TestApprox:
assert 10 != approx(1, rel=1e-6, abs=1e-12) assert 10 != approx(1, rel=1e-6, abs=1e-12)
assert not (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): def test_exactly_equal(self):
examples = [ examples = [
(2.0, 2.0), (2.0, 2.0),