This once again does NOT compile. I've done work on macros; they don't work yet..
This commit is contained in:
parent
e3f922a8bf
commit
2b22780ccf
86 changed files with 279 additions and 153 deletions
92
unit-tests/add.sh
Executable file
92
unit-tests/add.sh
Executable file
|
|
@ -0,0 +1,92 @@
|
|||
#!/bin/bash
|
||||
|
||||
result=0;
|
||||
|
||||
echo -n "$0: Add two small integers... "
|
||||
|
||||
expected='5'
|
||||
actual=`echo "(add 2 3)" | target/psse 2>/dev/null | sed -r '/^\s*$/d' | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: Add float to integer... "
|
||||
|
||||
expected='5.5'
|
||||
actual=`echo "(add 2.5 3)" | target/psse 2>/dev/null | sed -r '/^\s*$/d' | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: Add two rationals... "
|
||||
|
||||
expected='1/4'
|
||||
actual=`echo "(+ 3/14 1/28)" | target/psse 2>/dev/null | sed -r '/^\s*$/d' | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: Add an integer to a rational... "
|
||||
|
||||
# (+ integer ratio) should be ratio
|
||||
expected='25/4'
|
||||
actual=`echo "(+ 6 1/4)" | target/psse 2>/dev/null | sed -r '/^\s*$/d' | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: Add a rational to an integer... "
|
||||
|
||||
# (+ ratio integer) should be ratio
|
||||
expected='25/4'
|
||||
actual=`echo "(+ 1/4 6)" | target/psse 2>/dev/null | sed -r '/^\s*$/d' | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: Add a real to a rational... "
|
||||
|
||||
# (+ real ratio) should be real
|
||||
# for this test, trailing zeros can be ignored
|
||||
expected='6.25'
|
||||
actual=`echo "(+ 6.000000001 1/4)" |\
|
||||
target/psse 2> /dev/null |\
|
||||
sed -r '/^\s*$/d' |\
|
||||
sed 's/0*$//'`
|
||||
|
||||
outcome=`echo "sqrt((${expected} - ${actual})^2) < 0.0000001" | bc`
|
||||
|
||||
if [ "${outcome}" -eq "1" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
exit ${result}
|
||||
22
unit-tests/allocation-tests/allocation-tester.sh
Executable file
22
unit-tests/allocation-tests/allocation-tester.sh
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
#1/bin/bash
|
||||
|
||||
echo "Case, Summary, Allocated, Deallocated, Not deallocated, Delta Allocated, Delta Deallocated, Delta Not Deallocated"
|
||||
basecase=`echo '' | ../../target/psse 2>&1 | grep Allocation | tr -d '[:punct:]'`
|
||||
bca=`echo ${basecase} | awk '{print $4}'`
|
||||
bcd=`echo ${basecase} | awk '{print $6}'`
|
||||
bcn=`echo ${basecase} | awk '{print $9}'`
|
||||
|
||||
echo "\"Basecase\", \"${basecase}\", ${bca}, ${bcd}, ${bcn}"
|
||||
|
||||
while IFS= read -r form; do
|
||||
allocation=`echo ${form} | ../../target/psse 2>&1 | grep Allocation | tr -d '[:punct:]'`
|
||||
tca=`echo ${allocation} | awk '{print $4}'`
|
||||
tcd=`echo ${allocation} | awk '{print $6}'`
|
||||
tcn=`echo ${allocation} | awk '{print $9}'`
|
||||
|
||||
dca=`echo "${tca} - ${bca}" | bc`
|
||||
dcd=`echo "${tcd} - ${bcd}" | bc`
|
||||
dcn=`echo "${tcn} - ${bcn}" | bc`
|
||||
|
||||
echo "\"${form}\", \"${allocation}\", ${tca}, ${tcd}, ${tcn}, ${dca}, ${dcd}, ${dcn}"
|
||||
done
|
||||
28
unit-tests/allocation-tests/allocation-tests.csv
Normal file
28
unit-tests/allocation-tests/allocation-tests.csv
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
Case, Summary, Allocated, Deallocated, Not deallocated, Delta Allocated, Delta Deallocated, Delta Not Deallocated
|
||||
"Basecase", "Allocation summary allocated 19986 deallocated 245 not deallocated 19741", 19986, 245, 19741
|
||||
"", "Allocation summary allocated 19986 deallocated 245 not deallocated 19741", 19986, 245, 19741, 0, 0, 0
|
||||
"nil", "Allocation summary allocated 20019 deallocated 253 not deallocated 19766", 20019, 253, 19766, 33, 8, 25
|
||||
"()", "Allocation summary allocated 19990 deallocated 249 not deallocated 19741", 19990, 249, 19741, 4, 4, 0
|
||||
"(quote ())", "Allocation summary allocated 20025 deallocated 247 not deallocated 19778", 20025, 247, 19778, 39, 2, 37
|
||||
"(list)", "Allocation summary allocated 20023 deallocated 257 not deallocated 19766", 20023, 257, 19766, 37, 12, 25
|
||||
"(list )", "Allocation summary allocated 20023 deallocated 257 not deallocated 19766", 20023, 257, 19766, 37, 12, 25
|
||||
"(list 1)", "Allocation summary allocated 20033 deallocated 259 not deallocated 19774", 20033, 259, 19774, 47, 14, 33
|
||||
"(list 1 1)", "Allocation summary allocated 20043 deallocated 261 not deallocated 19782", 20043, 261, 19782, 57, 16, 41
|
||||
"(list 1 1 1)", "Allocation summary allocated 20053 deallocated 263 not deallocated 19790", 20053, 263, 19790, 67, 18, 49
|
||||
"(list 1 2 3)", "Allocation summary allocated 20053 deallocated 263 not deallocated 19790", 20053, 263, 19790, 67, 18, 49
|
||||
"(+)", "Allocation summary allocated 20022 deallocated 255 not deallocated 19767", 20022, 255, 19767, 36, 10, 26
|
||||
"(+ 1)", "Allocation summary allocated 20030 deallocated 257 not deallocated 19773", 20030, 257, 19773, 44, 12, 32
|
||||
"(+ 1 1)", "Allocation summary allocated 20039 deallocated 259 not deallocated 19780", 20039, 259, 19780, 53, 14, 39
|
||||
"(+ 1 1 1)", "Allocation summary allocated 20048 deallocated 261 not deallocated 19787", 20048, 261, 19787, 62, 16, 46
|
||||
"(+ 1 2 3)", "Allocation summary allocated 20048 deallocated 261 not deallocated 19787", 20048, 261, 19787, 62, 16, 46
|
||||
"(list 'a 'a 'a)", "Allocation summary allocated 20137 deallocated 278 not deallocated 19859", 20137, 278, 19859, 151, 33, 118
|
||||
"(list 'a 'b 'c)", "Allocation summary allocated 20137 deallocated 278 not deallocated 19859", 20137, 278, 19859, 151, 33, 118
|
||||
"(list :a :b :c)", "Allocation summary allocated 20107 deallocated 260 not deallocated 19847", 20107, 260, 19847, 121, 15, 106
|
||||
"(list :alpha :bravo :charlie)", "Allocation summary allocated 20471 deallocated 260 not deallocated 20211", 20471, 260, 20211, 485, 15, 470
|
||||
"{}", "Allocation summary allocated 19992 deallocated 251 not deallocated 19741", 19992, 251, 19741, 6, 6, 0
|
||||
"{:z 0}", "Allocation summary allocated 20029 deallocated 255 not deallocated 19774", 20029, 255, 19774, 43, 10, 33
|
||||
"{:zero 0}", "Allocation summary allocated 20107 deallocated 255 not deallocated 19852", 20107, 255, 19852, 121, 10, 111
|
||||
"{:z 0 :o 1}", "Allocation summary allocated 20066 deallocated 256 not deallocated 19810", 20066, 256, 19810, 80, 11, 69
|
||||
"{:zero 0 :one 1}", "Allocation summary allocated 20196 deallocated 259 not deallocated 19937", 20196, 259, 19937, 210, 14, 196
|
||||
"{:z 0 :o 1 :t 2}", "Allocation summary allocated 20103 deallocated 257 not deallocated 19846", 20103, 257, 19846, 117, 12, 105
|
||||
"{:zero 0 :one 1 :two 2 :three 3 :four 4 :five five :six 6 :seven 7 :eight 8 :nine 9}", "Allocation summary allocated 21164 deallocated 286 not deallocated 20878", 21164, 286, 20878, 1178, 41, 1137
|
||||
|
Can't render this file because it has a wrong number of fields in line 2.
|
BIN
unit-tests/allocation-tests/allocation-tests.ods
Normal file
BIN
unit-tests/allocation-tests/allocation-tests.ods
Normal file
Binary file not shown.
30
unit-tests/allocation-tests/feature-2.test.tmp
Normal file
30
unit-tests/allocation-tests/feature-2.test.tmp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
Case, Summary, Allocated, Deallocated, Not deallocated, Delta Allocated, Delta Deallocated, Delta Not Deallocated
|
||||
"Basecase", "Allocation summary allocated 19986 deallocated 245 not deallocated 19741", 19986, 245, 19741
|
||||
"", "Allocation summary allocated 19986 deallocated 245 not deallocated 19741", 19986, 245, 19741, 0, 0, 0
|
||||
"nil", "Allocation summary allocated 20019 deallocated 253 not deallocated 19766", 20019, 253, 19766, 33, 8, 25
|
||||
"()", "Allocation summary allocated 19990 deallocated 249 not deallocated 19741", 19990, 249, 19741, 4, 4, 0
|
||||
"(quote ())", "Allocation summary allocated 20025 deallocated 247 not deallocated 19778", 20025, 247, 19778, 39, 2, 37
|
||||
"(list)", "Allocation summary allocated 20023 deallocated 257 not deallocated 19766", 20023, 257, 19766, 37, 12, 25
|
||||
"(list )", "Allocation summary allocated 20023 deallocated 257 not deallocated 19766", 20023, 257, 19766, 37, 12, 25
|
||||
"(list 1)", "Allocation summary allocated 20033 deallocated 262 not deallocated 19771", 20033, 262, 19771, 47, 17, 30
|
||||
"(list 1 1)", "Allocation summary allocated 20043 deallocated 267 not deallocated 19776", 20043, 267, 19776, 57, 22, 35
|
||||
"(list 1 1 1)", "Allocation summary allocated 20053 deallocated 272 not deallocated 19781", 20053, 272, 19781, 67, 27, 40
|
||||
"(list 1 2 3)", "Allocation summary allocated 20053 deallocated 272 not deallocated 19781", 20053, 272, 19781, 67, 27, 40
|
||||
"(+)", "Allocation summary allocated 20022 deallocated 255 not deallocated 19767", 20022, 255, 19767, 36, 10, 26
|
||||
"(+ 1)", "Allocation summary allocated 20030 deallocated 260 not deallocated 19770", 20030, 260, 19770, 44, 15, 29
|
||||
"(+ 1 1)", "Allocation summary allocated 20039 deallocated 265 not deallocated 19774", 20039, 265, 19774, 53, 20, 33
|
||||
"(+ 1 1 1)", "Allocation summary allocated 20048 deallocated 270 not deallocated 19778", 20048, 270, 19778, 62, 25, 37
|
||||
"(+ 1 2 3)", "Allocation summary allocated 20048 deallocated 270 not deallocated 19778", 20048, 270, 19778, 62, 25, 37
|
||||
"(list 'a 'a 'a)", "Allocation summary allocated 20137 deallocated 278 not deallocated 19859", 20137, 278, 19859, 151, 33, 118
|
||||
"(list 'a 'b 'c)", "Allocation summary allocated 20137 deallocated 278 not deallocated 19859", 20137, 278, 19859, 151, 33, 118
|
||||
"(list :a :b :c)", "Allocation summary allocated 20107 deallocated 260 not deallocated 19847", 20107, 260, 19847, 121, 15, 106
|
||||
"(list :aa :bb :cc)", "Allocation summary allocated 20185 deallocated 260 not deallocated 19925", 20185, 260, 19925, 199, 15, 184
|
||||
"(list :aaa :bbb :ccc)", "Allocation summary allocated 20263 deallocated 260 not deallocated 20003", 20263, 260, 20003, 277, 15, 262
|
||||
"(list :alpha :bravo :charlie)", "Allocation summary allocated 20471 deallocated 260 not deallocated 20211", 20471, 260, 20211, 485, 15, 470
|
||||
"{}", "Allocation summary allocated 19992 deallocated 251 not deallocated 19741", 19992, 251, 19741, 6, 6, 0
|
||||
"{:z 0}", "Allocation summary allocated 20029 deallocated 257 not deallocated 19772", 20029, 257, 19772, 43, 12, 31
|
||||
"{:zero 0}", "Allocation summary allocated 20107 deallocated 257 not deallocated 19850", 20107, 257, 19850, 121, 12, 109
|
||||
"{:z 0 :o 1}", "Allocation summary allocated 20066 deallocated 261 not deallocated 19805", 20066, 261, 19805, 80, 16, 64
|
||||
"{:zero 0 :one 1}", "Allocation summary allocated 20196 deallocated 263 not deallocated 19933", 20196, 263, 19933, 210, 18, 192
|
||||
"{:z 0 :o 1 :t 2}", "Allocation summary allocated 20103 deallocated 265 not deallocated 19838", 20103, 265, 19838, 117, 20, 97
|
||||
"{:zero 0 :one 1 :two 2 :three 3 :four 4 :five five :six 6 :seven 7 :eight 8 :nine 9}", "Allocation summary allocated 21164 deallocated 306 not deallocated 20858", 21164, 306, 20858, 1178, 61, 1117
|
||||
19
unit-tests/allocation-tests/grep.bb
Executable file
19
unit-tests/allocation-tests/grep.bb
Executable file
|
|
@ -0,0 +1,19 @@
|
|||
#!/home/simon/bin/bb
|
||||
|
||||
(require '[clojure.java.io :as io])
|
||||
(import '[java.lang ProcessBuilder$Redirect])
|
||||
|
||||
(defn grep [input pattern]
|
||||
(let [proc (-> (ProcessBuilder. ["grep" pattern])
|
||||
(.redirectOutput ProcessBuilder$Redirect/INHERIT)
|
||||
(.redirectError ProcessBuilder$Redirect/INHERIT)
|
||||
(.start))
|
||||
proc-input (.getOutputStream proc)]
|
||||
(with-open [w (io/writer proc-input)]
|
||||
(binding [*out* w]
|
||||
(print input)
|
||||
(flush)))
|
||||
(.waitFor proc)
|
||||
nil))
|
||||
|
||||
(grep "hello\nbye\n" "e")
|
||||
28
unit-tests/allocation-tests/test-forms
Normal file
28
unit-tests/allocation-tests/test-forms
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
nil
|
||||
()
|
||||
(quote ())
|
||||
(list)
|
||||
(list )
|
||||
(list 1)
|
||||
(list 1 1)
|
||||
(list 1 1 1)
|
||||
(list 1 2 3)
|
||||
(+)
|
||||
(+ 1)
|
||||
(+ 1 1)
|
||||
(+ 1 1 1)
|
||||
(+ 1 2 3)
|
||||
(list 'a 'a 'a)
|
||||
(list 'a 'b 'c)
|
||||
(list :a :b :c)
|
||||
(list :aa :bb :cc)
|
||||
(list :aaa :bbb :ccc)
|
||||
(list :alpha :bravo :charlie)
|
||||
{}
|
||||
{:z 0}
|
||||
{:zero 0}
|
||||
{:z 0 :o 1}
|
||||
{:zero 0 :one 1}
|
||||
{:z 0 :o 1 :t 2}
|
||||
{:zero 0 :one 1 :two 2 :three 3 :four 4 :five five :six 6 :seven 7 :eight 8 :nine 9}
|
||||
44
unit-tests/append.sh
Executable file
44
unit-tests/append.sh
Executable file
|
|
@ -0,0 +1,44 @@
|
|||
#!/bin/bash
|
||||
|
||||
return=0;
|
||||
|
||||
echo -n "$0: Append two lists... "
|
||||
|
||||
expected='(a b c d e f)'
|
||||
actual=`echo "(append '(a b c) '(d e f))" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: Append two strings... "
|
||||
|
||||
expected='"hellodere"'
|
||||
actual=`echo '(append "hello" "dere")' | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: Append keyword to string should error... "
|
||||
|
||||
expected='Exception:'
|
||||
actual=`echo '(append "hello" :dere)' | target/psse 2>/dev/null | sed -r '/^\s*$/d' | awk '{print $1}'`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
exit ${return}
|
||||
29
unit-tests/apply.sh
Executable file
29
unit-tests/apply.sh
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/bash
|
||||
|
||||
result=1
|
||||
|
||||
echo -n "$0: Apply function to one argument... "
|
||||
expected='1'
|
||||
actual=`echo "(apply 'add '(1))"| target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: Apply function to multiple arguments... "
|
||||
expected='3'
|
||||
actual=`echo "(apply 'add '(1 2))"| target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
exit ${result}
|
||||
60
unit-tests/assoc.sh
Normal file
60
unit-tests/assoc.sh
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#!/bin/bash
|
||||
|
||||
result=0
|
||||
|
||||
expected='1'
|
||||
actual=`echo "(assoc 'foo '((foo . 1) (bar . 2) {ban 3 froboz 4 foo 5} (foobar . 6)))" | target/psse | tail -1`
|
||||
|
||||
|
||||
echo -n "$0 $1: assoc list binding... "
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
expected='4'
|
||||
actual=`echo "(assoc 'froboz '((foo . 1) (bar . 2) {ban 3 froboz 4 foo 5} (foobar . 6)))" | target/psse | tail -1`
|
||||
|
||||
|
||||
echo -n "$0 $1: hashmap binding... "
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
expected='nil'
|
||||
actual=`echo "(assoc 'ban '((foo . 1) (bar . 2) {ban nil froboz 4 foo 5} (foobar . 6) (ban . 7)))" | target/psse | tail -1`
|
||||
|
||||
|
||||
echo -n "$0 $1: key bound to 'nil' (1)... "
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
expected='nil'
|
||||
actual=`echo "(assoc 'foo '((foo . nil) (bar . 2) {ban 3 froboz 4 foo 5} (foobar . 6)))" | target/psse | tail -1`
|
||||
|
||||
|
||||
echo -n "$0 $1: key bound to nil (2)... "
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
278
unit-tests/bignum-add.sh
Executable file
278
unit-tests/bignum-add.sh
Executable file
|
|
@ -0,0 +1,278 @@
|
|||
#!/bin/bash
|
||||
|
||||
return=0
|
||||
|
||||
#####################################################################
|
||||
# add two large numbers, not actally bignums to produce a smallnum
|
||||
# (right on the boundary)
|
||||
a=1152921504606846975
|
||||
b=1
|
||||
c=`echo "$a + $b" | bc`
|
||||
expected='t'
|
||||
output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>tmp/psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
tail -1`
|
||||
|
||||
echo -n "$0 => adding $a to $b: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: checking no bignum was created: "
|
||||
grep -v 'BIGNUM!' tmp/psse.log > /dev/null
|
||||
if [ $? -eq "0" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# add two numbers, not actally bignums to produce a bignum
|
||||
# (just over the boundary)
|
||||
a='1152921504606846976'
|
||||
b=1
|
||||
c=`echo "$a + $b" | bc`
|
||||
expected='t'
|
||||
output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>tmp/psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
tail -1 |\
|
||||
sed 's/\,//g'`
|
||||
|
||||
echo -n "$0 => adding $a to $b: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0 => checking a bignum was created: "
|
||||
grep 'BIGNUM!' tmp/psse.log > /dev/null
|
||||
if [ $? -eq "0" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
|
||||
#####################################################################
|
||||
# add a bignum and a smallnum to produce a bignum
|
||||
# (just over the boundary)
|
||||
a='1152921504606846977'
|
||||
b=1
|
||||
c=`echo "$a + $b" | bc`
|
||||
expected='t'
|
||||
output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>tmp/psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
tail -1 |\
|
||||
sed 's/\,//g'`
|
||||
|
||||
echo -n "$0 => adding $a to $b: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0 => checking a bignum was created: "
|
||||
grep 'BIGNUM!' tmp/psse.log > /dev/null
|
||||
if [ $? -eq "0" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# add a smallnum and a bignum to produce a bignum
|
||||
# (just over the boundary)
|
||||
|
||||
a=1
|
||||
b=1152921504606846977
|
||||
c=`echo "$a + $b" | bc`
|
||||
expected='t'
|
||||
output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>tmp/psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
tail -1 |\
|
||||
sed 's/\,//g'`
|
||||
|
||||
echo -n "$0 => adding $a to $b: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0 => checking a bignum was created: "
|
||||
grep 'BIGNUM!' tmp/psse.log > /dev/null
|
||||
if [ $? -eq "0" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
|
||||
#####################################################################
|
||||
# add two small bignums to produce a bigger bignum
|
||||
|
||||
a=1152921504606846977
|
||||
c=`echo "$a + $a" | bc`
|
||||
echo -n "$0 => adding $a to $a: "
|
||||
expected='t'
|
||||
output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>tmp/psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
tail -1 |\
|
||||
sed 's/\,//g'`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# add five small bignums to produce a bigger bignum
|
||||
|
||||
a=1152921504606846977
|
||||
c=`echo "$a * 5" | bc`
|
||||
echo -n "$0 => adding $a, $a $a, $a, $a: "
|
||||
expected='t'
|
||||
output=`echo "(= (+ $a $a $a $a $a) $c)" | target/psse -v 2 2>tmp/psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
tail -1 |\
|
||||
sed 's/\,//g'`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
#####################################################################
|
||||
# add two bignums to produce a bignum
|
||||
a=10000000000000000000
|
||||
b=10000000000000000000
|
||||
c=`echo "$a + $b" | bc`
|
||||
expected='t'
|
||||
output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>tmp/psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
tail -1 |\
|
||||
sed 's/\,//g'`
|
||||
|
||||
echo -n "$0 => adding $a to $b: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0 => checking a bignum was created: "
|
||||
grep 'BIGNUM!' tmp/psse.log > /dev/null
|
||||
if [ $? -eq "0" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
|
||||
#####################################################################
|
||||
# add a smallnum and a two-cell bignum to produce a three-cell bignum
|
||||
# (just over the boundary)
|
||||
a=1
|
||||
b=1329227995784915872903807060280344576
|
||||
c=`echo "$a + $b" | bc`
|
||||
expected='t'
|
||||
output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>tmp/psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
tail -1 |\
|
||||
sed 's/\,//g'`
|
||||
|
||||
echo -n "$0 => adding $a to $b: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0 => checking a bignum was created: "
|
||||
grep 'BIGNUM!' tmp/psse.log > /dev/null
|
||||
if [ $? -eq "0" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
|
||||
#####################################################################
|
||||
# This currently fails:
|
||||
# (= (+ 1 3064991081731777716716694054300618367237478244367204352)
|
||||
# 3064991081731777716716694054300618367237478244367204353)
|
||||
a=1
|
||||
b=3064991081731777716716694054300618367237478244367204352
|
||||
c=`echo "$a + $b" | bc`
|
||||
expected='t'
|
||||
output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>tmp/psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
tail -1 |\
|
||||
sed 's/\,//g'`
|
||||
|
||||
echo -n "$0 => adding $a to $b: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0 => checking a bignum was created: "
|
||||
grep 'BIGNUM!' tmp/psse.log > /dev/null
|
||||
if [ $? -eq "0" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
exit ${return}
|
||||
136
unit-tests/bignum-expt.sh
Executable file
136
unit-tests/bignum-expt.sh
Executable file
|
|
@ -0,0 +1,136 @@
|
|||
#!/bin/bash
|
||||
|
||||
result=0
|
||||
|
||||
#####################################################################
|
||||
# last 'smallnum' value:
|
||||
# sbcl calculates (expt 2 59) => 576460752303423488
|
||||
expected='576460752303423488'
|
||||
|
||||
output=`target/psse 2>/dev/null <<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 "$0 => (expt 2 59): "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# first 'bignum' value (right on the boundary):
|
||||
# sbcl calculates (expt 2 60) => 1152921504606846976
|
||||
expected='1152921504606846976'
|
||||
|
||||
output=`target/psse 2>/dev/null <<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 "$0 => (expt 2 60): "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# second 'bignum' value (definitely a bignum):
|
||||
# sbcl calculates (expt 2 61) => 2305843009213693952
|
||||
expected='2305843009213693952'
|
||||
|
||||
output=`target/psse 2>/dev/null <<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 "$0 => (expt 2 61): "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
# sbcl calculates (expt 2 64) => 18446744073709551616
|
||||
expected='18446744073709551616'
|
||||
|
||||
output=`target/psse 2>/dev/null <<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 "$0 => (expt 2 64): "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
# sbcl calculates (expt 2 65) => 36893488147419103232
|
||||
expected='36893488147419103232'
|
||||
|
||||
output=`target/psse 2>/dev/null <<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 "$0 => (expt 2 65): "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
exit ${result}
|
||||
104
unit-tests/bignum-print.sh
Executable file
104
unit-tests/bignum-print.sh
Executable file
|
|
@ -0,0 +1,104 @@
|
|||
#!/bin/bash
|
||||
|
||||
return=0
|
||||
|
||||
#####################################################################
|
||||
# large number, not actally a bignum
|
||||
expected='576460752303423488'
|
||||
output=`echo "(progn (print $expected) nil)" | target/psse -v 2 2>psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
sed 's/\,//g' |\
|
||||
sed 's/[^0-9]*\([0-9]*\).*/\1/'`
|
||||
|
||||
echo -n "$0 => printing $expected: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
return=1
|
||||
fi
|
||||
|
||||
|
||||
#####################################################################
|
||||
# right on the boundary
|
||||
expected='1152921504606846976'
|
||||
output=`echo "(progn (print $expected) nil)" | target/psse -v 2 2>psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
sed 's/\,//g' |\
|
||||
sed 's/[^0-9]*\([0-9]*\).*/\1/'`
|
||||
|
||||
echo -n "$0 => printing $expected: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
return=1
|
||||
fi
|
||||
|
||||
|
||||
#####################################################################
|
||||
# definitely a bignum
|
||||
expected='1152921504606846977'
|
||||
output=`echo "(progn (print $expected) nil)" | target/psse -v 2 2>psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
sed 's/\,//g' |\
|
||||
sed 's/[^0-9]*\([0-9]*\).*/\1/'`
|
||||
|
||||
echo -n "$0 => printing $expected: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
return=1
|
||||
fi
|
||||
|
||||
|
||||
# Currently failing from here on, but it's failing in read because of
|
||||
# the multiply bug. We know printing blows up at the 3 cell boundary
|
||||
# because `lisp/scratchpad2.lisp` constructs a 3 cell bignum by
|
||||
# repeated addition.
|
||||
#####################################################################
|
||||
# Just on the three cell boundary
|
||||
expected='1329227995784915872903807060280344576'
|
||||
output=`echo "(progn (print $expected) nil)" | target/psse -v 2 2>psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
sed 's/\,//g' |\
|
||||
sed 's/[^0-9]*\([0-9]*\).*/\1/'`
|
||||
|
||||
echo -n "$0 => printing $expected: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', \n got '${actual}'"
|
||||
return=1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
||||
#####################################################################
|
||||
# definitely a three cell bignum
|
||||
expected='1329227995784915872903807060280344577'
|
||||
output=`echo "(progn (print $expected) nil)" | target/psse -v 2 2>psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
sed 's/\,//g' |\
|
||||
sed 's/[^0-9]*\([0-9]*\).*/\1/'`
|
||||
|
||||
echo -n "$0 => printing $expected: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
return=1
|
||||
fi
|
||||
|
||||
exit ${return}
|
||||
119
unit-tests/bignum-subtract.sh
Executable file
119
unit-tests/bignum-subtract.sh
Executable file
|
|
@ -0,0 +1,119 @@
|
|||
#!/bin/bash
|
||||
|
||||
result=0
|
||||
|
||||
#####################################################################
|
||||
# subtract a smallnum from a smallnum to produce a smallnum
|
||||
# (right on the boundary)
|
||||
a=1152921504606846976
|
||||
b=1
|
||||
expected='1152921504606846975'
|
||||
output=`echo "(- $a $b)" | target/psse -v 2 2>psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
tail -1 |\
|
||||
sed 's/\,//g'`
|
||||
|
||||
echo -n "$0 => subtracting $b from $a: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0 => checking no bignum was created: "
|
||||
grep -v 'BIGNUM!' psse.log > /dev/null
|
||||
if [ $? -eq "0" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# subtract a smallnum from a bignum to produce a smallnum
|
||||
# (just over the boundary)
|
||||
a='1152921504606846977'
|
||||
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 "$0 => subtracting $b from $a: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# subtract a smallnum from a bignum to produce a smallnum
|
||||
a='1152921504606846978'
|
||||
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 "$0 => subtracting $b from $a: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
|
||||
#####################################################################
|
||||
# subtract a bignum from a smallnum to produce a negstive smallnum
|
||||
# (just over the boundary)
|
||||
a=1
|
||||
b=1152921504606846977
|
||||
expected='-1152921504606846976'
|
||||
output=`echo "(- $a $b)" | target/psse -v 2 2>psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
tail -1 |\
|
||||
sed 's/\,//g'`
|
||||
|
||||
echo -n "$0 => subtracting $b from $a: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# subtract a bignum from a bignum to produce a bignum
|
||||
a=20000000000000000000
|
||||
b=10000000000000000000
|
||||
expected=10000000000000000000
|
||||
output=`echo "(- $a $b)" | target/psse -v 2 2>psse.log`
|
||||
|
||||
actual=`echo $output |\
|
||||
tail -1 |\
|
||||
sed 's/\,//g'`
|
||||
|
||||
echo -n "$0 => subtracting $b from $a: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
exit ${result}
|
||||
18
unit-tests/bignum.sh
Executable file
18
unit-tests/bignum.sh
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
#!/bin/bash
|
||||
|
||||
return=0
|
||||
|
||||
expected='1,152,921,504,606,846,976'
|
||||
# 1,152,921,504,606,846,975 is the largest single cell positive integer;
|
||||
# consequently 1,152,921,504,606,846,976 is the first two cell positive integer.
|
||||
actual=`echo '(+ 1,152,921,504,606,846,975 1)' | target/psse -v 68 2>bignum.log | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "$0 => Fail: expected '${expected}', got '${actual}'"
|
||||
return=1
|
||||
fi
|
||||
|
||||
exit ${return}
|
||||
13
unit-tests/complex-list.sh
Executable file
13
unit-tests/complex-list.sh
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash
|
||||
|
||||
expected='(1 2 3 ("Fred") nil 77,354)'
|
||||
actual=`echo "'(1 2 3 (\"Fred\") () 77354)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
exit 0
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
31
unit-tests/cond.sh
Executable file
31
unit-tests/cond.sh
Executable file
|
|
@ -0,0 +1,31 @@
|
|||
#!/bin/bash
|
||||
|
||||
result=0
|
||||
|
||||
echo -n "$0: cond with one clause... "
|
||||
|
||||
expected='5'
|
||||
actual=`echo "(cond ((equal? 2 2) 5))" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: cond with two clauses... "
|
||||
|
||||
expected='"should"'
|
||||
actual=`echo "(cond ((equal? 2 3) \"shouldn't\")(t \"should\"))" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
exit ${result}
|
||||
19
unit-tests/empty-list.sh
Executable file
19
unit-tests/empty-list.sh
Executable file
|
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# File: empty-list.sh.bash
|
||||
# Author: simon
|
||||
#
|
||||
# Created on 14-Aug-2017, 15:06:40
|
||||
#
|
||||
|
||||
expected=nil
|
||||
actual=`echo "'()" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
exit 0
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
13
unit-tests/empty-string.sh
Executable file
13
unit-tests/empty-string.sh
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash
|
||||
|
||||
expected="\"\""
|
||||
actual=`echo '""' | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "$expected" = "$actual" ]
|
||||
then
|
||||
echo "OK"
|
||||
exit 0
|
||||
else
|
||||
echo "Fail: expected '$expected', got '$actual'"
|
||||
exit 1
|
||||
fi
|
||||
206
unit-tests/equal.sh
Normal file
206
unit-tests/equal.sh
Normal file
|
|
@ -0,0 +1,206 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Tests for equality.
|
||||
|
||||
result=0
|
||||
|
||||
echo -n "$0: integers... "
|
||||
|
||||
expected="t"
|
||||
actual=`echo "(= 5 5)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: different integers... "
|
||||
|
||||
expected="nil"
|
||||
actual=`echo "(= 4 5)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
|
||||
echo -n "$0: reals... "
|
||||
|
||||
expected="t"
|
||||
actual=`echo "(= 5.001 5.001)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
|
||||
echo -n "$0: different reals... "
|
||||
|
||||
expected="nil"
|
||||
actual=`echo "(= 5.001 5.002)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: ratios... "
|
||||
|
||||
expected="t"
|
||||
actual=`echo "(= 4/5 4/5)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
|
||||
echo -n "$0: equivalent ratios... "
|
||||
|
||||
expected="t"
|
||||
actual=`echo "(= 4/5 12/15)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
|
||||
echo -n "$0: different ratios... "
|
||||
|
||||
expected="nil"
|
||||
actual=`echo "(= 4/5 5/5)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: atoms... "
|
||||
|
||||
expected="t"
|
||||
actual=`echo "(= 'foo 'foo)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: different atoms... "
|
||||
|
||||
expected="nil"
|
||||
actual=`echo "(= 'foo 'bar)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: keywords... "
|
||||
|
||||
expected="t"
|
||||
actual=`echo "(= :foo :foo)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: different keywords... "
|
||||
|
||||
expected="nil"
|
||||
actual=`echo "(= :foo :bar)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: strings... "
|
||||
|
||||
expected="t"
|
||||
actual=`echo '(= "foo" "foo")' | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: different strings... "
|
||||
|
||||
expected="nil"
|
||||
actual=`echo '(= "foo" "bar")' | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: maps... "
|
||||
|
||||
expected="t"
|
||||
actual=`echo '(= {:foo 1 :bar 2} {:bar 2 :foo 1})' | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: different maps... "
|
||||
|
||||
expected="nil"
|
||||
actual=`echo '(= {:foo 1 :bar 2} {:bar 1 :foo 2})' | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
exit ${result}
|
||||
12
unit-tests/eval-integer.sh
Executable file
12
unit-tests/eval-integer.sh
Executable file
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
expected='5'
|
||||
actual=`echo "(eval 5)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
13
unit-tests/eval-quote-sexpr.sh
Executable file
13
unit-tests/eval-quote-sexpr.sh
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash
|
||||
|
||||
expected='5'
|
||||
actual=`echo "(eval '(add 2 3))" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
2>/dev/null
|
||||
12
unit-tests/eval-quote-symbol.sh
Executable file
12
unit-tests/eval-quote-symbol.sh
Executable file
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
expected='<Special form: ((:primitive . t) (:name . cond) (:documentation . "`(cond clauses...)`: Conditional evaluation, `clauses` is a sequence of lists of forms such that if evaluating the first form in any clause returns non-`nil`, the subsequent forms in that clause will be evaluated and the value of the last returned; but any subsequent clauses will not be evaluated."))>'
|
||||
actual=`echo "(eval 'cond)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
21
unit-tests/eval-real.sh
Executable file
21
unit-tests/eval-real.sh
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
|
||||
# for this test, trailing zeros can be ignored
|
||||
expected='5.05'
|
||||
actual=`echo "(eval 5.05)" |\
|
||||
target/psse 2>/dev/null |\
|
||||
sed 's/0*$//' |\
|
||||
tail -1`
|
||||
|
||||
# one part in a million is close enough...
|
||||
outcome=`echo "sqrt((${expected} - ${actual})^2) < 0.0000001" | bc`
|
||||
|
||||
if [ "${outcome}" = "1" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
12
unit-tests/eval-string.sh
Executable file
12
unit-tests/eval-string.sh
Executable file
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
expected='"5"'
|
||||
actual=`echo '(eval "5")' | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
13
unit-tests/fred.sh
Executable file
13
unit-tests/fred.sh
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash
|
||||
|
||||
expected='"Fred"'
|
||||
actual=`echo ${expected} | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
exit 0
|
||||
else
|
||||
echo "Fail: expected '$expected', got '$actual'"
|
||||
exit 1
|
||||
fi
|
||||
14
unit-tests/integer-allocation.sh
Executable file
14
unit-tests/integer-allocation.sh
Executable file
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
value=354
|
||||
expected="(${value} \"INTR\")"
|
||||
echo "(set! x $value)(list x (type x))" | target/psse 2>&1 | grep "${expected}" > /dev/null
|
||||
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo "OK"
|
||||
exit 0
|
||||
else
|
||||
echo "Expected '${expected}', not found"
|
||||
exit 1
|
||||
fi
|
||||
13
unit-tests/integer.sh
Executable file
13
unit-tests/integer.sh
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash
|
||||
|
||||
expected='354'
|
||||
actual=`echo ${expected} | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
exit 0
|
||||
else
|
||||
echo "Expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
12
unit-tests/interpreter.sh
Executable file
12
unit-tests/interpreter.sh
Executable file
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
expected='6'
|
||||
actual=`echo "(apply '(lambda (x y z) (/ (* y z) x)) '(2 3 4))" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
17
unit-tests/lambda.sh
Executable file
17
unit-tests/lambda.sh
Executable file
|
|
@ -0,0 +1,17 @@
|
|||
#!/bin/bash
|
||||
|
||||
expected='<Anonymous Function: (λ (l) l)> (1 2 3 4 5 6 7 8 9 10)'
|
||||
output=`target/psse 2>/dev/null <<EOF
|
||||
(set! list (lambda (l) l))
|
||||
(list '(1 2 3 4 5 6 7 8 9 10))
|
||||
EOF`
|
||||
actual=`echo $output | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
exit 0
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
29
unit-tests/let.sh
Executable file
29
unit-tests/let.sh
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/bash
|
||||
|
||||
result=0
|
||||
|
||||
expected='11'
|
||||
actual=`echo "(let ((a . 5)(b . 6)) (+ a b))" | target/psse | tail -1`
|
||||
echo -n "$0: let with two bindings, one form in body... "
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '$expected', got '$actual'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
expected='1'
|
||||
actual=`echo "(let ((a . 5)(b . 6)) (+ a b) (- b a))" | target/psse | tail -1`
|
||||
echo -n "$0: let with two bindings, two forms in body..."
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '$expected', got '$actual'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
exit ${result}
|
||||
47
unit-tests/list-test.sh
Normal file
47
unit-tests/list-test.sh
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#!/bin/bash
|
||||
|
||||
result=0
|
||||
|
||||
echo -n "$0: flat list with 16 elements... "
|
||||
expected="(0 1 2 3 4 5 6 7 8 9 a b c d e f)"
|
||||
|
||||
actual=`echo "(list 0 1 2 3 4 5 6 7 8 9 'a 'b 'c 'd 'e 'f)" |\
|
||||
target/psse 2>/dev/null |\
|
||||
tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '$expected', got '$actual'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: flat list with 5 elements... "
|
||||
expected="(0 1 2 3 4)"
|
||||
|
||||
actual=`echo "(list 0 1 2 3 4)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '$expected', got '$actual'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: flat list with 8 elements... "
|
||||
expected="(0 1 2 3 4 5 6 7)"
|
||||
|
||||
actual=`echo "(list 0 1 2 3 4 5 6 7)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
exit 0
|
||||
else
|
||||
echo "Fail: expected '$expected', got '$actual'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
exit ${result}
|
||||
30
unit-tests/many-args.sh
Executable file
30
unit-tests/many-args.sh
Executable file
|
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
|
||||
result=0
|
||||
|
||||
echo -n "$0: plus with fifteen arguments... "
|
||||
|
||||
expected="120"
|
||||
actual=`echo "(+ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: check that all the args are actually being evaluated... "
|
||||
expected="120"
|
||||
actual=`echo "(+ (+ 0 1) (+ 0 2) (+ 0 3) (+ 0 4) (+ 0 5) (+ 0 6) (+ 0 7) (+ 0 8) (+ 0 9) (+ 0 10) (+ 0 11) (+ 0 12) (+ 0 13) (+ 0 14 ) (+ 0 15))" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
exit ${result}
|
||||
95
unit-tests/map.sh
Executable file
95
unit-tests/map.sh
Executable file
|
|
@ -0,0 +1,95 @@
|
|||
#!/bin/bash
|
||||
|
||||
result=0
|
||||
|
||||
#####################################################################
|
||||
# Create an empty map using map notation
|
||||
expected='{}'
|
||||
actual=`echo "$expected" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
echo -n "$0: Empty map using compact map notation... "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=1
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# Create an empty map using make-map
|
||||
expected='{}'
|
||||
actual=`echo "(hashmap)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
echo -n "Empty map using (make-map): "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=1
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# Create a map using map notation: order of keys in output is not
|
||||
# significant at this stage, but in the long term should be sorted
|
||||
# alphanumerically
|
||||
expected='{:one 1, :two 2, :three 3}'
|
||||
actual=`echo "{:one 1 :two 2 :three 3}" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
echo -n "$0: Map using map notation... "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=1
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# Create a map using make-map: order of keys in output is not
|
||||
# significant at this stage, but in the long term should be sorted
|
||||
# alphanumerically
|
||||
expected='{:one 1, :two 2, :three 3}'
|
||||
actual=`echo "(hashmap nil nil '((:one . 1)(:two . 2)(:three . 3)))" |\
|
||||
target/psse 2>/dev/null | tail -1`
|
||||
|
||||
echo -n "$0: Map using (hashmap) with arguments... "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=1
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# Keyword in function position
|
||||
expected='2'
|
||||
actual=`echo "(:two {:one 1 :two 2 :three 3})" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
echo -n "$0: Keyword in function position... "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=1
|
||||
fi
|
||||
|
||||
|
||||
#####################################################################
|
||||
# Map in function position
|
||||
expected='2'
|
||||
actual=`echo "({:one 1 :two 2 :three 3} :two)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
echo -n "$0: Map in function position... "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=1
|
||||
fi
|
||||
|
||||
exit ${result}
|
||||
31
unit-tests/mapcar.sh
Normal file
31
unit-tests/mapcar.sh
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#!/bin/bash
|
||||
|
||||
result=0
|
||||
|
||||
#####################################################################
|
||||
# Create an empty map using map notation
|
||||
expected='(2 3 4)'
|
||||
actual=`echo "(mapcar (lambda (n) (+ n 1)) '(1 2 3))" | target/psse | tail -1`
|
||||
|
||||
echo -n "$0: Mapping interpreted function across list: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=1
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# Create an empty map using make-map
|
||||
expected='("INTR" "REAL" "RTIO" "KEYW")'
|
||||
actual=`echo "(mapcar type '(1 1.0 1/2 :one))" | target/psse | tail -1`
|
||||
|
||||
echo -n "$0: Mapping primitive function across list: "
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=1
|
||||
fi
|
||||
108
unit-tests/memberp.sh
Normal file
108
unit-tests/memberp.sh
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
#!/bin/bash
|
||||
|
||||
result=0
|
||||
|
||||
expected='t'
|
||||
output=`target/psse $1 <<EOF
|
||||
(progn
|
||||
(set! nil? (lambda (o) (= (type o) "NIL ")))
|
||||
(set! member?
|
||||
(lambda
|
||||
(item collection)
|
||||
(cond
|
||||
((nil? collection) nil)
|
||||
((= item (car collection)) t)
|
||||
(t (member? item (cdr collection))))))
|
||||
(member? 1 '(1 2 3 4)))
|
||||
EOF`
|
||||
actual=`echo $output | tail -1`
|
||||
|
||||
echo -n "$0 $1: (member? 1 '(1 2 3 4))... "
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
expected='t'
|
||||
output=`target/psse $1 <<EOF
|
||||
(progn
|
||||
(set! nil? (lambda (o) (= (type o) "NIL ")))
|
||||
(set! member?
|
||||
(lambda
|
||||
(item collection)
|
||||
(cond
|
||||
((nil? collection) nil)
|
||||
((= item (car collection)) t)
|
||||
(t (member? item (cdr collection))))))
|
||||
(member? 4 '(1 2 3 4)))
|
||||
EOF`
|
||||
actual=`echo $output | tail -1`
|
||||
|
||||
echo -n "$0: (member? 4 '(1 2 3 4))... "
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
|
||||
expected='nil'
|
||||
output=`target/psse $1 <<EOF
|
||||
(progn
|
||||
(set! nil? (lambda (o) (= (type o) "NIL ")))
|
||||
(set! member?
|
||||
(lambda
|
||||
(item collection)
|
||||
;; (progn (print (list "In member; collection is:" collection)) (println))
|
||||
(cond
|
||||
((nil? collection) nil)
|
||||
((= item (car collection)) t)
|
||||
(t (member? item (cdr collection))))))
|
||||
(member? 5 '(1 2 3 4)))
|
||||
EOF`
|
||||
actual=`echo $output | tail -1`
|
||||
|
||||
echo -n "$0: (member? 5 '(1 2 3 4))... "
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
expected='nil'
|
||||
output=`target/psse $1 -s100<<EOF
|
||||
(progn
|
||||
(set! nil? (lambda (o) (= (type o) "NIL ")))
|
||||
(set! member?
|
||||
(lambda
|
||||
(item collection)
|
||||
;; (print (list "in member?: " 'item item 'collection collection) *log*)(println *log*)
|
||||
(cond
|
||||
((nil? collection) nil)
|
||||
((= item (car collection)) t)
|
||||
(t (member? item (cdr collection))))))
|
||||
(member? 5 '(1 2 3 4)))
|
||||
EOF`
|
||||
actual=`echo $output | tail -1`
|
||||
|
||||
echo -n "$0: (member? 5 '(1 2 3 4)) with stack limit... "
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
exit $result
|
||||
14
unit-tests/memory.sh
Normal file
14
unit-tests/memory.sh
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
actual=`echo "" | target/psse 2>&1 | tail -2`
|
||||
|
||||
alloc=`echo $actual | sed 's/[[:punct:]]/ /g' | awk '{print $4}'`
|
||||
dealloc=`echo $actual | sed 's/[[:punct:]]/ /g' | awk '{print $6}'`
|
||||
|
||||
if [ "${alloc}" = "${dealloc}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${alloc}', got '${dealloc}'"
|
||||
exit 1
|
||||
fi
|
||||
31
unit-tests/multiply.sh
Executable file
31
unit-tests/multiply.sh
Executable file
|
|
@ -0,0 +1,31 @@
|
|||
#!/bin/bash
|
||||
|
||||
result=0
|
||||
|
||||
echo -n "$0: multiply two integers... "
|
||||
|
||||
expected='6'
|
||||
actual=`echo "(multiply 2 3)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: multiply a real by an integer... "
|
||||
|
||||
expected='7.5'
|
||||
actual=`echo "(multiply 2.5 3)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
exit ${result}
|
||||
13
unit-tests/nil.sh
Executable file
13
unit-tests/nil.sh
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash
|
||||
|
||||
expected=nil
|
||||
actual=`echo 'nil' | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
exit 0
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
13
unit-tests/nlambda.sh
Executable file
13
unit-tests/nlambda.sh
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash
|
||||
|
||||
expected='a'
|
||||
actual=`echo "((nlambda (x) x) a)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
exit 0
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
34
unit-tests/path-notation.sh
Executable file
34
unit-tests/path-notation.sh
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
#!/bin/bash
|
||||
|
||||
result=0
|
||||
|
||||
#####################################################################
|
||||
# Create a path from root using compact path notation
|
||||
echo -n "$0: Create a path from root using compact path notation... "
|
||||
expected='(-> (oblist) :users :simon :functions (quote assoc))'
|
||||
actual=`echo "'/:users:simon:functions/assoc" | target/psse 2>&1 | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
#####################################################################
|
||||
# Create a path from the current session using compact path notation
|
||||
echo -n "$0: Create a path from the current session using compact path notation... "
|
||||
expected='(-> session :input-stream)'
|
||||
actual=`echo "'$:input-stream" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
exit ${result}
|
||||
|
||||
29
unit-tests/progn.sh
Executable file
29
unit-tests/progn.sh
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/bash
|
||||
|
||||
result=0
|
||||
|
||||
echo -n "$0: progn with one form... "
|
||||
expected='5'
|
||||
actual=`echo "(progn (add 2 3))" | target/psse | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: progn with two forms... "
|
||||
expected='"foo"'
|
||||
actual=`echo "(progn (add 2.5 3) \"foo\")" | target/psse | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
exit ${result}
|
||||
13
unit-tests/quote.sh
Executable file
13
unit-tests/quote.sh
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash
|
||||
|
||||
expected='Fred'
|
||||
actual=`echo "'Fred" | target/psse 2>&1 | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
exit 0
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
13
unit-tests/quoted-list.sh
Executable file
13
unit-tests/quoted-list.sh
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash
|
||||
|
||||
expected='(123 (4 (5 nil)) Fred)'
|
||||
actual=`echo "'(123 (4 (5 ())) Fred)" | target/psse 2>&1 | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
exit 0
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
12
unit-tests/ratio-addition.sh
Executable file
12
unit-tests/ratio-addition.sh
Executable file
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
expected='1/4'
|
||||
actual=`echo "(+ 3/14 1/28)" | target/psse 2>&1 | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
22
unit-tests/recursion.sh
Executable file
22
unit-tests/recursion.sh
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
#!/bin/bash
|
||||
|
||||
expected='nil 3,628,800'
|
||||
output=`target/psse <<EOF
|
||||
(progn
|
||||
(set! fact
|
||||
(lambda (n)
|
||||
(cond ((= n 1) 1)
|
||||
(t (* n (fact (- n 1)))))))
|
||||
nil)
|
||||
(fact 10)
|
||||
EOF`
|
||||
actual=`echo $output | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
exit 0
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
43
unit-tests/reverse.sh
Executable file
43
unit-tests/reverse.sh
Executable file
|
|
@ -0,0 +1,43 @@
|
|||
#!/bin/bash
|
||||
|
||||
result=0
|
||||
|
||||
echo -n "$0: reverse a string... "
|
||||
expected='"god yzal eht revo depmuj xof nworb kciuq ehT"'
|
||||
actual=`echo '(reverse "The quick brown fox jumped over the lazy dog")' | target/psse 2>&1 | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: reverse a list... "
|
||||
expected='(1,024 512 256 128 64 32 16 8 4 2)'
|
||||
actual=`echo "(reverse '(2 4 8 16 32 64 128 256 512 1024))" | target/psse 2>&1 | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: reverse a symbol... "
|
||||
expected='esrever'
|
||||
actual=`echo "(reverse 'reverse)" | target/psse 2>&1 | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
exit 0
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
exit ${result}
|
||||
|
||||
13
unit-tests/simple-list.sh
Executable file
13
unit-tests/simple-list.sh
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash
|
||||
|
||||
expected="(1 2 3)"
|
||||
actual=`echo "'(1 2 3)" | target/psse 2>&1 | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
exit 0
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
16
unit-tests/slurp.sh
Executable file
16
unit-tests/slurp.sh
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
tmp=tmp/hi.$$
|
||||
echo "Hello, there." > ${tmp}
|
||||
expected='"Hello, there.'
|
||||
actual=`echo "(slurp (open \"${tmp}\"))" | target/psse 2>&1 | tail -2 | head -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
rm ${tmp}
|
||||
exit 0
|
||||
else
|
||||
echo "$0 => Fail: expected '$expected', got '$actual'"
|
||||
exit 1
|
||||
fi
|
||||
15
unit-tests/string-allocation.sh
Executable file
15
unit-tests/string-allocation.sh
Executable file
|
|
@ -0,0 +1,15 @@
|
|||
#!/bin/bash
|
||||
|
||||
value='"Fred"'
|
||||
expected="String cell: character 'F'"
|
||||
# set! protects "Fred" from the garbage collector.
|
||||
actual=`echo "(set! x ${value})" | target/psse -d 2>&1 | grep "$expected" | sed 's/ *\(.*\) next.*$/\1/'`
|
||||
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo "OK"
|
||||
exit 0
|
||||
else
|
||||
echo "$0 => Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
30
unit-tests/string-cons.sh
Executable file
30
unit-tests/string-cons.sh
Executable file
|
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
|
||||
result=0
|
||||
|
||||
echo -n "$0: We should be able to cons a single character string onto the front of a string... "
|
||||
expected='"Test"'
|
||||
actual=`echo '(cons "T" "est")' | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: But if the first argument has more than one character, we should get a dotted pair... "
|
||||
expected='("Test" . "pass")'
|
||||
actual=`echo '(cons "Test" "pass")' | target/psse 2>&1 | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
exit ${result}
|
||||
|
||||
13
unit-tests/string-with-spaces.sh
Executable file
13
unit-tests/string-with-spaces.sh
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash
|
||||
|
||||
expected='"Strings should be able to include spaces (and other stuff)!"'
|
||||
actual=`echo ${expected} | target/psse 2>&1 | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
exit 0
|
||||
else
|
||||
echo "Fail: expected '$expected', got '$actual'"
|
||||
exit 1
|
||||
fi
|
||||
190
unit-tests/subtract.sh
Normal file
190
unit-tests/subtract.sh
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Tests for smallnum subtraction
|
||||
|
||||
result=0
|
||||
|
||||
|
||||
echo -n "$0: (- 5 4)... "
|
||||
|
||||
expected="1"
|
||||
actual=`echo "(- 5 4)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: (- 5.0 4)... "
|
||||
|
||||
expected="1"
|
||||
actual=`echo "(- 5.0 4)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: (- 5 4.0)... "
|
||||
|
||||
expected="1"
|
||||
actual=`echo "(- 5 4.0)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: (- 5.01 4.0)... "
|
||||
|
||||
expected="1.0100000000000000002082"
|
||||
actual=`echo "(- 5.01 4.0)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: (- 5 4/5)... "
|
||||
|
||||
expected="24/5"
|
||||
actual=`echo "(- 5 4/5)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: max smallint (- 1152921504606846975 1)... "
|
||||
|
||||
expected="1,152,921,504,606,846,974"
|
||||
actual=`echo "(- 1152921504606846975 1)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: max smallint (- 1152921504606846975 1152921504606846974)... "
|
||||
|
||||
expected="1"
|
||||
actual=`echo "(- 1152921504606846975 1152921504606846974)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: (- 4 5)... "
|
||||
|
||||
expected="-1"
|
||||
actual=`echo "(- 4 5)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: (- 4 5.0)... "
|
||||
|
||||
expected="-1"
|
||||
actual=`echo "(- 4 5.0)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: (- 4.0 5)... "
|
||||
|
||||
expected="-1"
|
||||
actual=`echo "(- 4.0 5)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: (- 4.0 5.01)... "
|
||||
|
||||
expected="-1.0100000000000000002082"
|
||||
actual=`echo "(- 4.0 5.01)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: (- 4/5 5)... "
|
||||
|
||||
expected="-3/5"
|
||||
actual=`echo "(- 4/5 5)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: max smallint (- 1 1152921504606846975)... "
|
||||
|
||||
expected="-1,152,921,504,606,846,974"
|
||||
actual=`echo "(- 1 1152921504606846975)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: max smallint (- 1152921504606846974 1152921504606846975)... "
|
||||
|
||||
expected="-1"
|
||||
actual=`echo "(- 1152921504606846974 1152921504606846975)" | target/psse 2>/dev/null | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
result=`echo "${result} + 1" | bc`
|
||||
fi
|
||||
|
||||
exit ${result}
|
||||
54
unit-tests/try.sh
Executable file
54
unit-tests/try.sh
Executable file
|
|
@ -0,0 +1,54 @@
|
|||
#!/bin/bash
|
||||
|
||||
result=0
|
||||
|
||||
echo -n "$0: if the body of a try errors, the last form in the catch block is returned... "
|
||||
expected=':foo'
|
||||
actual=`echo "(try ((+ 2 (/ 1 'a))) (:foo))" | target/psse 2>&1 | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: if the body of a try errors, the last form in the catch block is evaluated... "
|
||||
|
||||
expected='4'
|
||||
actual=`echo "(try ((+ 2 (/ 1 'a))) ((+ 2 2)))" | target/psse 2>&1 | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: body and catch block can optionally be marked with keywords... "
|
||||
expected='8'
|
||||
actual=`echo "(try (:body (+ 2 (/ 1 'a))) (:catch (* 2 2 2)))" | target/psse 2>&1 | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
echo -n "$0: the exception is bound to the symbol \`*exception*\` in the catch environment... "
|
||||
expected='Exception: ((:location . /) (:payload . "Cannot divide: not a number"))'
|
||||
actual=`echo "(try (:body (+ 2 (/ 1 'a))) (:catch *exception*))" | target/psse 2>&1 | grep Exception`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
return=`echo "${return} + 1" | bc`
|
||||
fi
|
||||
|
||||
exit ${result}
|
||||
13
unit-tests/varargs.sh
Executable file
13
unit-tests/varargs.sh
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash
|
||||
|
||||
expected='(1 2 3 4 5 6 7 8 9 10)'
|
||||
actual=`echo "(set! list (lambda l l))(list 1 2 3 4 5 6 7 8 9 10)" | target/psse 2>&1 | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
exit 0
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
12
unit-tests/wide-character.sh
Executable file
12
unit-tests/wide-character.sh
Executable file
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
expected='"λάμ(β)δα"'
|
||||
actual=`echo $expected | target/psse 2>&1 | tail -1`
|
||||
|
||||
if [ "${expected}" = "${actual}" ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "Fail: expected '${expected}', got '${actual}'"
|
||||
exit 1
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue