mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-28 13:02:38 +02:00
test: add assert_scale
assertion to test framework
This commit is contained in:
parent
cee5305a97
commit
fb6ef09a1d
@ -197,6 +197,18 @@ def assert_array_result(object_array, to_match, expected, should_not_find=False)
|
||||
if num_matched > 0 and should_not_find:
|
||||
raise AssertionError("Objects were found %s" % (str(to_match)))
|
||||
|
||||
def assert_scale(number, expected_scale=8):
|
||||
"""Assert number has expected scale, e.g. fractional digits; number of
|
||||
digits after the decimal. The default of 8 corresponds to a Bitcoin amount."""
|
||||
number = str(number)
|
||||
mantissa = number.split('.')[-1].upper()
|
||||
if mantissa[:3] == '0E-':
|
||||
assert_equal(mantissa, '0E-{}'.format(expected_scale)) # zeros in exponent notation
|
||||
elif mantissa == number:
|
||||
assert_equal(0, expected_scale) # no mantissa, ergo, expected scale must be 0
|
||||
else:
|
||||
assert_equal(len(mantissa), expected_scale)
|
||||
|
||||
|
||||
# Utility functions
|
||||
###################
|
||||
|
Loading…
Reference in New Issue
Block a user