Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
#
#trace_elapsed;
show_benchmark;
\test_bn==
(
\test_ops==
(
\run_test=
(
\show=(\k\v say [k" = "v])
\label\fn
say ["= test "label]
\try=
(\x\y
\x=(bn_from_dec x)
\y=(bn_from_dec y)
\z=(fn x y)
show "x" x
show "y" y
show "z" z
nl
)
\try2=(\x try x x)
try "0" "0"
try "1" "1"
try "10002" "10003"
try "12370356088" "15123"
try "123470356088" "15123"
try "26019123470356088" "1049752133674165355933"
try2 "999999999999999999999999"
try2 "1111111111111111111111111111111111111111111111111"
)
run_test "add" bn_add
run_test "mul" bn_mul
(
# Compute 2^256.
\x=(bn_from_dec "2") # 2^1
\x=(bn_mul x x) # 2^2
\x=(bn_mul x x) # 2^4
\x=(bn_mul x x) # 2^8
\x=(bn_mul x x) # 2^16
\x=(bn_mul x x) # 2^32
\x=(bn_mul x x) # 2^64
\x=(bn_mul x x) # 2^128
\x=(bn_mul x x) # 2^256
\s=(bn_to_dec x)
say s
say (length s)
)
)
\test_convert==
(
\try=
(\x
\xn=(bn_from_dec x)
\y=(bn_to_dec xn)
say [(as_str x)" "(as_str y)]
)
say "= test convert"
try "0"
try "1"
try "1234"
try "9999"
try "00"
try "1234567890123456789012"
try "1234567890"
try "000000123"
# Test some errors.
# LATER 20211110 These don't map to void anymore, but perhaps they should.
try ""
try "x"
try "x1234"
try "12345abc90123456789012"
nl
)
test_ops
test_convert
)
test_bn