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
|
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):
|
||||||
|
|
|
@ -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),
|
||||||
|
|
Loading…
Reference in New Issue