2020-05-09 14:58:28 -04:00
|
|
|
|
#!/bin/bash
|
2020-05-28 10:25:36 -04:00
|
|
|
|
|
2020-08-02 16:16:26 -04:00
|
|
|
|
VALCOM="valgrind -q --leak-check=full --track-origins=yes"
|
|
|
|
|
|
2020-05-28 10:25:36 -04:00
|
|
|
|
TOTAL_PASSES=0
|
|
|
|
|
TOTAL_FAILS=0
|
2020-05-09 14:58:28 -04:00
|
|
|
|
PASSES=0
|
|
|
|
|
FAILS=0
|
2020-05-14 23:50:53 -04:00
|
|
|
|
VALGRIND=0
|
|
|
|
|
|
2020-05-28 10:25:36 -04:00
|
|
|
|
CURRENT_BLOCK=""
|
|
|
|
|
|
2020-05-14 23:50:53 -04:00
|
|
|
|
if [ "$1" == "-val" ]; then
|
|
|
|
|
VALGRIND=1
|
|
|
|
|
fi
|
2020-05-09 14:58:28 -04:00
|
|
|
|
|
2020-05-28 10:25:36 -04:00
|
|
|
|
endBlock() {
|
|
|
|
|
echo "[0;32m$PASSES tests PASSED[0m"
|
|
|
|
|
if (($FAILS != 0)); then
|
|
|
|
|
echo "[0;31m$FAILS tests FAILED[0m"
|
|
|
|
|
fi
|
|
|
|
|
PASSES=0
|
|
|
|
|
FAILS=0
|
|
|
|
|
echo ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
title() {
|
|
|
|
|
echo "[1m$1[0m"
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-09 14:58:28 -04:00
|
|
|
|
pass() {
|
|
|
|
|
((PASSES++))
|
2020-05-28 10:25:36 -04:00
|
|
|
|
((TOTAL_PASSES++))
|
2020-05-09 14:58:28 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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++))
|
2020-05-28 10:25:36 -04:00
|
|
|
|
((TOTAL_FAILS++))
|
2020-05-09 14:58:28 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
check() {
|
2020-05-14 23:50:53 -04:00
|
|
|
|
local output
|
|
|
|
|
if (($VALGRIND == 1)); then
|
2020-08-02 16:16:26 -04:00
|
|
|
|
local output=$($VALCOM ./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-28 10:25:36 -04:00
|
|
|
|
echo "[1;33mSTARTING TESTS[0;m"
|
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
|
|
title "Plain return tests"
|
2020-05-14 23:50:53 -04:00
|
|
|
|
check "PlainRet" "10" "10"
|
|
|
|
|
check "StrRetrn" "\"hey\"" "hey"
|
2020-05-28 10:25:36 -04:00
|
|
|
|
check "SingleStrRetrn" "'hey'" "hey"
|
2020-08-02 16:16:26 -04:00
|
|
|
|
check "HexReturn" "0x0f0f0" "61680"
|
|
|
|
|
check "BinaryReturn" "0b011010011010011" "13523"
|
2020-05-28 10:25:36 -04:00
|
|
|
|
endBlock
|
|
|
|
|
|
|
|
|
|
title "Arithmetic"
|
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"
|
|
|
|
|
check "ChainAdd" "(+ 3917 17304 1293844 400 100000)" "1415465"
|
|
|
|
|
check "ChainMul" "(* 8263 23 123)" "23376027"
|
|
|
|
|
check "ChainDiv" "(/ 1493856 741 96 7)" "3"
|
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 )"
|
2020-05-28 10:25:36 -04:00
|
|
|
|
endBlock
|
|
|
|
|
|
|
|
|
|
title "Comparison"
|
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"
|
2020-05-28 10:25:36 -04:00
|
|
|
|
check "StringInequality" "(= \"Beans\" \"Bean\" )" "F"
|
|
|
|
|
endBlock
|
|
|
|
|
|
|
|
|
|
title "Ifs/Bools"
|
2020-05-09 14:58:28 -04:00
|
|
|
|
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-28 10:25:36 -04:00
|
|
|
|
endBlock
|
|
|
|
|
|
|
|
|
|
title "Lists"
|
2020-05-09 14:58:28 -04:00
|
|
|
|
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" "( )" "( )"
|
2020-05-28 10:25:36 -04:00
|
|
|
|
check "ListIndex" "(at (+ 1 1) (1 2 1000 4 5))" "1000"
|
|
|
|
|
check "EvalElems" "((* 10 10) 7)" "( 100 7 )"
|
|
|
|
|
check "AppendToList" "(ap (1 20 300 4000 50000) 600000)" "( 1 20 300 4000 50000 600000 )"
|
2020-08-02 16:16:26 -04:00
|
|
|
|
check "AppndToEnvList" "(def l (50000 4000 300 20)) (def l (ap l 1)) l" "( 50000 4000 300 20 1 )"
|
2020-05-28 10:25:36 -04:00
|
|
|
|
check "Rest(Tail)OfList" "(def l (50000 4000 300 20)) (rest l)" "( 4000 300 20 )"
|
|
|
|
|
check "ListLength" "(def l (1 20 3 'abc' 'banana' (+ 10 5))) (len l)" "6"
|
|
|
|
|
endBlock
|
|
|
|
|
|
|
|
|
|
title "Spacing"
|
2020-05-10 12:51:46 -04:00
|
|
|
|
check "DenseSpc" "(+1093 102852)" "103945"
|
|
|
|
|
check "WideSpac" "( + 1093 102852 )" "103945"
|
|
|
|
|
check "VWidwSpc" " ( + 1093 102852 ) " "103945"
|
2020-05-28 10:25:36 -04:00
|
|
|
|
endBlock
|
|
|
|
|
|
|
|
|
|
title "DemoFunctions"
|
2020-05-10 12:51:46 -04:00
|
|
|
|
check "DemoFunc" "(spent 68)" "Tip: \$13.60"
|
2020-05-28 10:25:36 -04:00
|
|
|
|
check "Squaring" "(sq 9876)" "97535376"
|
|
|
|
|
check "Cubing" "(cube 81)" "531441"
|
|
|
|
|
check "Exponent" "(exp 9 9)" "387420489"
|
|
|
|
|
check "MaxRight" "(max 5 20)" "20"
|
|
|
|
|
check "MaxLeft" "(max 135890 98372)" "135890"
|
|
|
|
|
check "MinRight" "(min 8429 192449)" "8429"
|
|
|
|
|
check "MinLeft" "(min 17294722 17294721)" "17294721"
|
|
|
|
|
endBlock
|
|
|
|
|
|
|
|
|
|
title "Lambdas"
|
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-28 10:25:36 -04:00
|
|
|
|
check "LambdaClone" "(def y (fn (a) (* 10 a))) (def b y) (def y 12345) ((b 5) y)" "( 50 12345 )"
|
|
|
|
|
check "Duplicate" "(def dupe (fn (a) (a a a)));(dupe (*10 10))" "( 100 100 100 )"
|
|
|
|
|
endBlock
|
|
|
|
|
|
|
|
|
|
title "Cat"
|
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-28 10:25:36 -04:00
|
|
|
|
endBlock
|
|
|
|
|
|
|
|
|
|
title "Filtering"
|
2020-05-22 01:16:45 -04:00
|
|
|
|
check "Filtering" "(fil (< 321) (30 300 90 1200 135 801))" "( 1200 801 )"
|
2020-05-28 10:25:36 -04:00
|
|
|
|
check "FilterEval" "(fil (= 1000) ((+ 450 550) (* 20 50) (/ 30 3) (- 10000 100)))" "( 1000 1000 )"
|
2020-05-22 01:16:45 -04:00
|
|
|
|
check "MapFilter" "(fil (< 50) (map sq (1 2 3 4 5 6 7 8 9 10 11 12)))" "( 64 81 100 121 144 )"
|
2020-05-28 10:25:36 -04:00
|
|
|
|
endBlock
|
|
|
|
|
|
|
|
|
|
title "ShouldError"
|
|
|
|
|
check "LenOfNotList" "(len 5)" "NOT_A_LIST"
|
2020-06-12 18:50:36 -04:00
|
|
|
|
check "NoMapList" "(map sq)" "( )"
|
|
|
|
|
check "UnevenLists" "(+ (1 2) (1 2 3))" "LISTS_NOT_SAME_SIZE"
|
2020-08-02 16:16:26 -04:00
|
|
|
|
check "BadNumber" "(5df)" "BAD_NUMBER"
|
|
|
|
|
check "BadHex" "(0x0zf)" "BAD_NUMBER"
|
|
|
|
|
check "BadBinary" "(0b01120)" "BAD_NUMBER"
|
2020-06-12 18:50:36 -04:00
|
|
|
|
check "BadParens" "(hey()" "MISMATCHED_PARENS"
|
|
|
|
|
check "BadParens2" "(hey)(" "MISMATCHED_PARENS"
|
|
|
|
|
check "BadParens3" "((hey(" "MISMATCHED_PARENS"
|
|
|
|
|
check "BadParens4" ")))hey" "MISMATCHED_PARENS"
|
|
|
|
|
check "BadParens5" "hey))(" "MISMATCHED_PARENS"
|
2020-05-28 10:25:36 -04:00
|
|
|
|
endBlock
|
|
|
|
|
|
|
|
|
|
# title "Environment"
|
|
|
|
|
# check "EnvStressTestEarly" "(def a 1)(def b 20)(def c 'yee')(def d 'yeehunnid')(def e 3) (a)" "1"
|
|
|
|
|
# check "EnvStressTestLate" "(def a 1)(def b 2)(def c 3)(def d 4)(def e 5)(def f 6)(def n 40) (n)" "40"
|
|
|
|
|
# endBlock
|
|
|
|
|
|
|
|
|
|
|
2020-05-22 01:16:45 -04:00
|
|
|
|
echo ""
|
2020-05-10 12:51:46 -04:00
|
|
|
|
|
2020-05-28 10:25:36 -04:00
|
|
|
|
if [ "$TOTAL_FAILS" -ne "0" ]; then
|
2020-08-02 16:16:26 -04:00
|
|
|
|
echo -n "[1;31m"
|
|
|
|
|
fi
|
|
|
|
|
echo "$TOTAL_FAILS Tests Failed[0m"
|
|
|
|
|
|
|
|
|
|
if [ "$TOTAL_PASSES" -ne "0" ]; then
|
|
|
|
|
echo -n "[1;32m"
|
2020-05-10 12:51:46 -04:00
|
|
|
|
fi
|
2020-08-02 16:16:26 -04:00
|
|
|
|
echo "$TOTAL_PASSES Tests Passed[0m"
|
2020-05-10 12:51:46 -04:00
|
|
|
|
|
2020-05-15 16:27:45 -04:00
|
|
|
|
echo ""
|