Make ApproxScalar hashable
This commit is contained in:
parent
5f57481563
commit
01bb8013e8
|
@ -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):
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue