2020-05-09 14:58:28 -04:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
PASSES=0
|
|
|
|
|
FAILS=0
|
2020-05-14 23:50:53 -04:00
|
|
|
|
VALGRIND=0
|
|
|
|
|
|
|
|
|
|
if [ "$1" == "-val" ]; then
|
|
|
|
|
VALGRIND=1
|
|
|
|
|
fi
|
2020-05-09 14:58:28 -04:00
|
|
|
|
|
|
|
|
|
pass() {
|
2020-05-10 12:51:46 -04:00
|
|
|
|
echo "[0;32m$1 test PASSED[0m"
|
2020-05-09 14:58:28 -04:00
|
|
|
|
((PASSES++))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fail() {
|
2020-05-22 01:16:45 -04:00
|
|
|
|
echo "[1;31m$1 test FAILED [0;34m$2[0m"
|
2020-05-09 14:58:28 -04:00
|
|
|
|
((FAILS++))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
check() {
|
2020-05-14 23:50:53 -04:00
|
|
|
|
local output
|
|
|
|
|
if (($VALGRIND == 1)); then
|
2020-05-16 11:12:12 -04:00
|
|
|
|
local output=$(valgrind -q --leak-check=full --track-origins=yes ./pebblisp "$2")
|
2020-05-14 23:50:53 -04:00
|
|
|
|
else
|
|
|
|
|
local output=$(./pebblisp "$2")
|
|
|
|
|
fi
|
|
|
|
|
|
2020-05-09 14:58:28 -04:00
|
|
|
|
if [ "$output" == "$3" ]; then
|
|
|
|
|
pass $1
|
|
|
|
|
else
|
2020-05-22 01:16:45 -04:00
|
|
|
|
fail $1 "$2"
|
2020-05-10 12:51:46 -04:00
|
|
|
|
echo " Expected '$3' but received '$output'"
|
2020-05-09 14:58:28 -04:00
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-14 23:50:53 -04:00
|
|
|
|
check "PlainRet" "10" "10"
|
|
|
|
|
check "StrRetrn" "\"hey\"" "hey"
|
2020-05-10 12:51:46 -04:00
|
|
|
|
echo ""
|
2020-05-09 14:58:28 -04:00
|
|
|
|
check "Addition" "(+ 1093 102852)" "103945"
|
2020-05-10 12:51:46 -04:00
|
|
|
|
check "Multiply" "(*1000 10000)" "10000000"
|
2020-05-09 14:58:28 -04:00
|
|
|
|
check "Division" "(/ 6418425 65)" "98745"
|
|
|
|
|
echo ""
|
|
|
|
|
check "ChainAdd" "(+ 3917 17304 1293844 400 100000)" "1415465"
|
|
|
|
|
check "ChainMul" "(* 8263 23 123)" "23376027"
|
|
|
|
|
check "ChainDiv" "(/ 1493856 741 96 7)" "3"
|
|
|
|
|
echo ""
|
2020-05-10 12:51:46 -04:00
|
|
|
|
check "ListAddi" "(+ 5 (1 2 3 (+ 10 10)))" "( 6 7 8 25 )"
|
|
|
|
|
check "ListModu" "(% 5 (1 2 3 (* 11 11)))" "( 1 2 3 1 )"
|
|
|
|
|
check "ListsMul" "(* (10 20 30) (1 20 300))" "( 10 400 9000 )"
|
|
|
|
|
echo ""
|
2020-05-09 14:58:28 -04:00
|
|
|
|
check "GratrThn" "(> 23847123 19375933)" "T"
|
|
|
|
|
check "LessThan" "(< 23847123 19375933)" "F"
|
|
|
|
|
check "Equality" "(= 987654321 987654321 )" "T"
|
2020-05-22 01:16:45 -04:00
|
|
|
|
check "StringEquality" "(= \"Bean\" \"Bean\" )" "T"
|
|
|
|
|
check "Stringinequality" "(= \"Beans\" \"Bean\" )" "F"
|
2020-05-09 14:58:28 -04:00
|
|
|
|
echo ""
|
|
|
|
|
check "IfReturn" "(if (T) 123456789 987654321)" "123456789"
|
|
|
|
|
check "IfRetTwo" "(if F 123456789 987654321)" "987654321"
|
2020-05-10 12:51:46 -04:00
|
|
|
|
check "EmptyCnd" "(if () T F)" "F"
|
2020-05-22 01:16:45 -04:00
|
|
|
|
check "EtyLstLt" "(if (()) T F)" "T"
|
2020-05-09 14:58:28 -04:00
|
|
|
|
echo ""
|
|
|
|
|
check "RegLists" "(1 2 3 4 5)" "( 1 2 3 4 5 )"
|
2020-05-16 10:46:19 -04:00
|
|
|
|
check "MultiTypeList" "(10 20 \"rascals\")" "( 10 20 rascals )"
|
2020-05-10 12:51:46 -04:00
|
|
|
|
check "EmptyLst" "()" "( )"
|
|
|
|
|
check "EmptLst2" "( )" "( )"
|
|
|
|
|
echo ""
|
|
|
|
|
check "DenseSpc" "(+1093 102852)" "103945"
|
|
|
|
|
check "WideSpac" "( + 1093 102852 )" "103945"
|
|
|
|
|
check "VWidwSpc" " ( + 1093 102852 ) " "103945"
|
|
|
|
|
echo ""
|
|
|
|
|
check "DemoFunc" "(spent 68)" "Tip: \$13.60"
|
2020-05-10 14:15:53 -04:00
|
|
|
|
echo ""
|
2020-05-22 01:16:45 -04:00
|
|
|
|
check "MultStmt" "(def yee (fn (a) (* 10 a))) ; (yee 5)" "50"
|
|
|
|
|
check "DefinMap" "(def yee (fn (a) (* 10 a))) ; (map yee (5 10 2 (+ 12 0)))" "( 50 100 20 120 )"
|
2020-05-14 23:50:53 -04:00
|
|
|
|
check "FbnciSeq" "(def fib (fn (a) \
|
|
|
|
|
(if (< a 2) \
|
|
|
|
|
a \
|
|
|
|
|
(+ (fib (- a 1)) (fib (- a 2))) \
|
2020-05-22 01:16:45 -04:00
|
|
|
|
)));\
|
2020-05-14 23:50:53 -04:00
|
|
|
|
(fib 20)" "6765"
|
2020-05-22 01:16:45 -04:00
|
|
|
|
check "Factorial" "(def fac (fn (a) \
|
|
|
|
|
(if (= a 1) \
|
|
|
|
|
1 \
|
|
|
|
|
(* a (fac (- a 1)) ) \
|
|
|
|
|
)));\
|
|
|
|
|
(fac 11)" "39916800"
|
2020-05-09 14:58:28 -04:00
|
|
|
|
echo ""
|
2020-05-15 00:43:08 -04:00
|
|
|
|
check "ExplicitCat" "(cat \"Big\" \" Kitty\")" "Big Kitty"
|
|
|
|
|
check "CatNums" "(cat \"There are \" (+ 2 3) \" kitties\")" "There are 5 kitties"
|
|
|
|
|
check "ImplicitCat" "(+ \"There are \" (* 5 4) \" bonks\")" "There are 20 bonks"
|
2020-05-22 01:16:45 -04:00
|
|
|
|
# Mixing of `+` and implicit cat not recommended:
|
2020-05-15 00:43:08 -04:00
|
|
|
|
check "CatAssocLeft" "(+ 10 20 \" rascals\")" "30 rascals"
|
2020-05-16 14:31:14 -04:00
|
|
|
|
echo ""
|
2020-05-22 01:16:45 -04:00
|
|
|
|
check "LambdaClone" "(def y (fn (a) (* 10 a))) (def b y) (def y 12345) ((b 5) y)" "( 50 12345 )"
|
|
|
|
|
echo ""
|
2020-05-16 10:46:19 -04:00
|
|
|
|
check "EvalElems" "((* 10 10) 7)" "( 100 7 )"
|
2020-05-22 01:16:45 -04:00
|
|
|
|
check "Duplicate" "(def dupe (fn (a) (a a a)));(dupe (*10 10))" "( 100 100 100 )"
|
2020-05-16 14:31:14 -04:00
|
|
|
|
echo ""
|
|
|
|
|
check "Squaring" "(sq 9876)" "97535376"
|
|
|
|
|
check "Cubing" "(cube 81)" "531441"
|
|
|
|
|
check "Exponent" "(exp 9 9)" "387420489"
|
|
|
|
|
echo ""
|
2020-05-22 01:16:45 -04:00
|
|
|
|
check "Filtering" "(fil (< 321) (30 300 90 1200 135 801))" "( 1200 801 )"
|
|
|
|
|
check "MapFilter" "(fil (< 50) (map sq (1 2 3 4 5 6 7 8 9 10 11 12)))" "( 64 81 100 121 144 )"
|
|
|
|
|
echo ""
|
2020-05-10 12:51:46 -04:00
|
|
|
|
|
|
|
|
|
if [ "$FAILS" -ne "0" ]; then
|
|
|
|
|
echo "[1;31m$FAILS Tests Failed[0m"
|
|
|
|
|
else
|
|
|
|
|
echo "$FAILS Tests Failed[0m"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "[1;32m$PASSES Tests Passed[0m"
|
2020-05-15 16:27:45 -04:00
|
|
|
|
echo ""
|