Added unit tests to establish that bignum addition and print work
the bug must be in multiplication.
This commit is contained in:
parent
7f93b04b72
commit
c209abb4f9
14
src/debug.h
14
src/debug.h
|
@ -14,14 +14,14 @@
|
|||
#define __debug_print_h
|
||||
|
||||
#define DEBUG_ALLOC 1
|
||||
#define DEBUG_STACK 2
|
||||
#define DEBUG_ARITH 4
|
||||
#define DEBUG_EVAL 8
|
||||
#define DEBUG_LAMBDA 16
|
||||
#define DEBUG_BOOTSTRAP 32
|
||||
#define DEBUG_IO 64
|
||||
#define DEBUG_ARITH 2
|
||||
#define DEBUG_BIND 4
|
||||
#define DEBUG_BOOTSTRAP 8
|
||||
#define DEBUG_EVAL 16
|
||||
#define DEBUG_IO 32
|
||||
#define DEBUG_LAMBDA 64
|
||||
#define DEBUG_REPL 128
|
||||
#define DEBUG_BIND 256
|
||||
#define DEBUG_STACK 256
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ void dump_object( FILE * output, struct cons_pointer pointer ) {
|
|||
L"\t\tInteger cell: value %ld, count %u\n",
|
||||
cell.payload.integer.value, cell.count );
|
||||
if ( !nilp( cell.payload.integer.more ) ) {
|
||||
fputws( L"\t\tBIGNUM! More at\n:", output );
|
||||
fputws( L"\t\tBIGNUM! More at:\n", output );
|
||||
dump_object( output, cell.payload.integer.more );
|
||||
}
|
||||
break;
|
||||
|
|
155
unit-tests/bignum-add.sh
Normal file
155
unit-tests/bignum-add.sh
Normal file
|
@ -0,0 +1,155 @@
|
|||
#!/bin/bash
|
||||
|
||||
#####################################################################
|
||||
# add two large numbers, not actally bignums to produce a smallnum
|
||||
# (right on the boundary)
|
||||
a=1152921504606846975
|
||||
b=1
|
||||
expected='1152921504606846976'
|
||||
output=`echo "(+ $a $b)" | target/psse -v 2 2>psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
tail -1 |\
|
||||
sed 's/\,//g'`
|
||||
|
||||
echo -n "adding $a to $b: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -n "checking no bignum was created: "
|
||||
grep -v 'BIGNUM!' psse.log > /dev/null
|
||||
if [ $? -eq "0" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# add two numbers, not actally bignums to produce a bignum
|
||||
# (just over the boundary)
|
||||
a='1152921504606846976'
|
||||
b=1
|
||||
expected='1152921504606846977'
|
||||
output=`echo "(+ $a $b)" | target/psse -v 2 2>psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
tail -1 |\
|
||||
sed 's/\,//g'`
|
||||
|
||||
echo -n "adding $a to $b: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -n "checking a bignum was created: "
|
||||
grep 'BIGNUM!' psse.log > /dev/null
|
||||
if [ $? -eq "0" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# add a bignum and a smallnum to produce a bignum
|
||||
# (just over the boundary)
|
||||
a='1152921504606846977'
|
||||
b=1
|
||||
expected='1152921504606846978'
|
||||
output=`echo "(+ $a $b)" | target/psse -v 2 2>psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
tail -1 |\
|
||||
sed 's/\,//g'`
|
||||
|
||||
echo -n "adding $a to $b: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -n "checking a bignum was created: "
|
||||
grep 'BIGNUM!' psse.log > /dev/null
|
||||
if [ $? -eq "0" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# add a smallnum and a bignum to produce a bignum
|
||||
# (just over the boundary)
|
||||
a=1
|
||||
b=1152921504606846977
|
||||
expected='1152921504606846978'
|
||||
output=`echo "(+ $a $b)" | target/psse -v 2 2>psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
tail -1 |\
|
||||
sed 's/\,//g'`
|
||||
|
||||
echo -n "adding $a to $b: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -n "checking a bignum was created: "
|
||||
grep 'BIGNUM!' psse.log > /dev/null
|
||||
if [ $? -eq "0" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# add two bignums to produce a bignum
|
||||
a=10000000000000000000
|
||||
b=10000000000000000000
|
||||
expected='20000000000000000000'
|
||||
output=`echo "(+ $a $b)" | target/psse -v 2 2>psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
tail -1 |\
|
||||
sed 's/\,//g'`
|
||||
|
||||
echo -n "adding $a to $b: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -n "checking a bignum was created: "
|
||||
grep 'BIGNUM!' psse.log > /dev/null
|
||||
if [ $? -eq "0" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail"
|
||||
exit 1
|
||||
fi
|
135
unit-tests/bignum-expt.sh
Normal file
135
unit-tests/bignum-expt.sh
Normal file
|
@ -0,0 +1,135 @@
|
|||
#!/bin/bash
|
||||
|
||||
#####################################################################
|
||||
# last 'smallnum' value:
|
||||
# sbcl calculates (expt 2 59) => 576460752303423488
|
||||
expected='576460752303423488'
|
||||
|
||||
output=`target/psse <<EOF
|
||||
(progn
|
||||
(set! expt (lambda
|
||||
(n x)
|
||||
(cond
|
||||
((= x 1) n)
|
||||
(t (* n (expt n (- x 1)))))))
|
||||
nil)
|
||||
(expt 2 59)
|
||||
EOF`
|
||||
|
||||
actual=`echo "$output" | tail -1 | sed 's/\,//g'`
|
||||
|
||||
echo -n "(expt 2 59): "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# first 'bignum' value (right on the boundary):
|
||||
# sbcl calculates (expt 2 60) => 1152921504606846976
|
||||
expected='1152921504606846976'
|
||||
|
||||
output=`target/psse <<EOF
|
||||
(progn
|
||||
(set! expt (lambda
|
||||
(n x)
|
||||
(cond
|
||||
((= x 1) n)
|
||||
(t (* n (expt n (- x 1)))))))
|
||||
nil)
|
||||
(expt 2 60)
|
||||
EOF`
|
||||
|
||||
actual=`echo "$output" | tail -1 | sed 's/\,//g'`
|
||||
|
||||
echo -n "(expt 2 60): "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# second 'bignum' value (definitely a bignum):
|
||||
# sbcl calculates (expt 2 61) => 2305843009213693952
|
||||
expected='2305843009213693952'
|
||||
|
||||
output=`target/psse <<EOF
|
||||
(progn
|
||||
(set! expt (lambda
|
||||
(n x)
|
||||
(cond
|
||||
((= x 1) n)
|
||||
(t (* n (expt n (- x 1)))))))
|
||||
nil)
|
||||
(expt 2 61)
|
||||
EOF`
|
||||
|
||||
actual=`echo "$output" | tail -1 | sed 's/\,//g'`
|
||||
|
||||
echo -n "(expt 2 61): "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
|
||||
# sbcl calculates (expt 2 64) => 18446744073709551616
|
||||
expected='18446744073709551616'
|
||||
|
||||
output=`target/psse <<EOF
|
||||
(progn
|
||||
(set! expt (lambda
|
||||
(n x)
|
||||
(cond
|
||||
((= x 1) n)
|
||||
(t (* n (expt n (- x 1)))))))
|
||||
nil)
|
||||
(expt 2 64)
|
||||
EOF`
|
||||
|
||||
actual=`echo "$output" | tail -1 | sed 's/\,//g'`
|
||||
|
||||
echo -n "(expt 2 64): "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# sbcl calculates (expt 2 65) => 36893488147419103232
|
||||
expected='36893488147419103232'
|
||||
|
||||
output=`target/psse <<EOF
|
||||
(progn
|
||||
(set! expt (lambda
|
||||
(n x)
|
||||
(cond
|
||||
((= x 1) n)
|
||||
(t (* n (expt n (- x 1)))))))
|
||||
nil)
|
||||
(expt 2 65)
|
||||
EOF`
|
||||
|
||||
actual=`echo "$output" | tail -1 | sed 's/\,//g'`
|
||||
|
||||
echo -n "(expt 2 65): "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
57
unit-tests/bignum-print.sh
Normal file
57
unit-tests/bignum-print.sh
Normal file
|
@ -0,0 +1,57 @@
|
|||
#!/bin/bash
|
||||
|
||||
#####################################################################
|
||||
# large number, not actally a bignum
|
||||
expected='576460752303423488'
|
||||
output=`echo "(progn (print $expected) nil)" | target/psse`
|
||||
|
||||
actual=`echo $output |\
|
||||
sed 's/\,//g' |\
|
||||
sed 's/[^0-9]*\([0-9]*\).*/\1/'`
|
||||
|
||||
echo -n "printing $expected: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# right on the boundary
|
||||
expected='1152921504606846976'
|
||||
output=`echo "(progn (print $expected) nil)" | target/psse`
|
||||
|
||||
actual=`echo $output |\
|
||||
sed 's/\,//g' |\
|
||||
sed 's/[^0-9]*\([0-9]*\).*/\1/'`
|
||||
|
||||
echo -n "printing $expected: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# definitely a bignum
|
||||
expected='2305843009213693952'
|
||||
output=`echo "(progn (print $expected) nil)" | target/psse`
|
||||
|
||||
actual=`echo $output |\
|
||||
sed 's/\,//g' |\
|
||||
sed 's/[^0-9]*\([0-9]*\).*/\1/'`
|
||||
|
||||
echo -n "printing $expected: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
Loading…
Reference in a new issue