-
Notifications
You must be signed in to change notification settings - Fork 1
/
test
executable file
·34 lines (29 loc) · 1.57 KB
/
test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env bash
## Tests for bcalc
## Create the debug directory if it doesn't exist.
if ! [ -d "./debug" ]; then mkdir debug; fi
## Common variables used for the tests.
exe="./bcalc"
macro() {
local expected="${1}"
local command="${exe} '${2}'"
local result
result="$(eval "${command}")"
local debug_file="debug/${3}"
if [ "${result}" == "${expected}" ]; then
printf "%s\n" "GOOD -- ${4}"
else
eval "bash -x ${command} --debug" &> "${debug_file}"
printf "BAD -- The result of the test is \"${result}\", when it should be \"${expected}\".\n (A debug file is available at '${debug_file}'.)\n"
fi
}
## Run the tests.
macro "4" "(1+1)*2" "basic_paren_test-debug-output" "The basic parenthesis test has passed."
macro "16" "4^2" "basic_expon_test-debug-output" "The basic exponent test has passed."
macro "32" "16*2" "basic_multi_test-debug-output" "The basic multiplication test has passed."
macro "64" "128/2" "basic_divis_test-debug-output" "The basic division test has passed."
macro "128" "64+64" "basic_addit_test-debug-output" "The basic addition test has passed."
macro "256" "384-128" "basic_subtr_test-debug-output" "The basic subtraction test has passed."
macro "512" "(1256-500+500)*(1+1)" "basi_pemdas_test-debug-output" "The basic PEMDAS test has passed."
macro "1024" "(1256-500+500)*(1+1)*2" "bas_pemdas2_test-debug-output" "The second basic PEMDAS test has passed."
macro "Currently other notations are unsupported, please start with a number." " +11" "error_notat_test-debug-output" "The error test for notations passed."