2022-03-09 15:28:30 +00:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
# tests all functions 3 times using numbers generated using $RPATH
|
|
|
|
# psh-prng is used here with my testing
|
|
|
|
# math is comparred to bc
|
|
|
|
fd() {
|
|
|
|
m="$1"; n=1; while [ "$m" ]; do
|
|
|
|
next="${m%?}"
|
|
|
|
[ "$n" -eq "${#1}" ] && {
|
|
|
|
echo "${m%next}"
|
|
|
|
break
|
|
|
|
}
|
|
|
|
: $((n+=1)); m="$next"
|
|
|
|
done
|
|
|
|
}
|
2022-04-05 16:24:44 +00:00
|
|
|
ran() {
|
|
|
|
ran="$(${RPATH})"
|
|
|
|
ran="${ran#0.}"
|
|
|
|
until [ "${#ran}" -le 5 ]; do
|
|
|
|
ran="${ran%?}"
|
|
|
|
done
|
|
|
|
echo "${ran}"
|
|
|
|
}
|
|
|
|
case "$1" in
|
|
|
|
"") types="addition/add subtraction/sub multiplication/mul division/div" ;;
|
|
|
|
*) types="$1"
|
|
|
|
esac
|
|
|
|
IFS=" "; for i in ${types}; do
|
2022-03-09 15:28:30 +00:00
|
|
|
for n in 1 2; do
|
2022-04-05 16:24:44 +00:00
|
|
|
ran="$(fd $(ran))"; : $((ran-=1)); until [ "$ran" -eq 1 -o "$ran" -eq 0 ]; do
|
|
|
|
ran="$(fd $(ran))"; : $((ran-=1))
|
2022-03-09 15:28:30 +00:00
|
|
|
done
|
|
|
|
case $ran in
|
2022-04-05 16:24:44 +00:00
|
|
|
0) ran=""; tn="$(ran).$(ran) $(ran)";;
|
|
|
|
1) ran=""; tn="$(ran) $(ran).$(ran)"
|
|
|
|
ran="$(fd $(ran))"; : $((ran-=1)); until [ "$ran" -eq 1 -o "$ran" -eq 0 ]; do
|
|
|
|
ran="$(fd $(ran))"; : $((ran-=1))
|
2022-03-09 15:28:30 +00:00
|
|
|
done
|
|
|
|
case $ran in
|
2022-04-05 16:24:44 +00:00
|
|
|
1) ran=""; tn="${tn% *}.$(ran) ${tn#* }"
|
2022-03-09 15:28:30 +00:00
|
|
|
esac
|
|
|
|
esac
|
|
|
|
# use random number to determine if number will have decimal place
|
|
|
|
case $i in
|
2022-04-05 16:24:44 +00:00
|
|
|
*addition/add) op="+";;
|
|
|
|
*subtraction/sub) op="-";;
|
|
|
|
*multiplication/mul) op="*";;
|
|
|
|
*division/div) op="/"
|
2022-03-09 15:28:30 +00:00
|
|
|
esac
|
|
|
|
aws="$(echo ${tn% *}${op}${tn#* } | bc -l)"; case "$(fd $aws)" in
|
|
|
|
'.') aws="0${aws}"
|
|
|
|
esac
|
|
|
|
printf ' %s\n%s %s\n_____\nbc: %s\n' "${tn% *}" "$op" "${tn#* }" "$aws"
|
2022-04-05 16:24:44 +00:00
|
|
|
oaws="$aws"; aws="${aws%.*}${aws#*.}"
|
|
|
|
[ "$aws" -ge 9223372036854775807 ] 2>/dev/null && {
|
|
|
|
printf 'psh: too large...\n\n'
|
|
|
|
} || printf 'psh: %s\n' "$(${i} ${tn% *} ${tn#* })"
|
|
|
|
[ "$oaws" = "$(${i} ${tn% *} ${tn#* })" ] && {
|
|
|
|
status=0
|
|
|
|
} || status=1
|
|
|
|
case "$status" in
|
|
|
|
0) printf 'Correct!\n\n' ;;
|
|
|
|
1) printf 'False..\n\n'
|
|
|
|
esac
|
2022-03-09 15:28:30 +00:00
|
|
|
done
|
|
|
|
done
|