mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-23 15:22:46 +02:00
test: add support for Decimal to assert_approx
This commit is contained in:
parent
ce3b75690d
commit
701a64f548
@ -29,6 +29,10 @@ logger = logging.getLogger("TestFramework.utils")
|
|||||||
|
|
||||||
def assert_approx(v, vexp, vspan=0.00001):
|
def assert_approx(v, vexp, vspan=0.00001):
|
||||||
"""Assert that `v` is within `vspan` of `vexp`"""
|
"""Assert that `v` is within `vspan` of `vexp`"""
|
||||||
|
if isinstance(v, Decimal) or isinstance(vexp, Decimal):
|
||||||
|
v=Decimal(v)
|
||||||
|
vexp=Decimal(vexp)
|
||||||
|
vspan=Decimal(vspan)
|
||||||
if v < vexp - vspan:
|
if v < vexp - vspan:
|
||||||
raise AssertionError("%s < [%s..%s]" % (str(v), str(vexp - vspan), str(vexp + vspan)))
|
raise AssertionError("%s < [%s..%s]" % (str(v), str(vexp - vspan), str(vexp + vspan)))
|
||||||
if v > vexp + vspan:
|
if v > vexp + vspan:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user