Skip to content

Commit

Permalink
Consider nan AND -nan as result of 0/0
Browse files Browse the repository at this point in the history
Consider multiple correct expects in tests.sh
  • Loading branch information
Victorcorcos committed Nov 28, 2023
1 parent dd5a64c commit f783c57
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,27 @@ echo "Running tests..."

function test_eval() {
input=$1
expected_output="ans = "$2
expected_output1="ans = "$2
expected_output2="ans = "$3
actual_output=$(echo "$input
exit" | ./example | grep "ans =")

if [[ "$actual_output" == "$expected_output" ]]; then
if [[ "$actual_output" == "$expected_output1" ]]; then
printf "\e[32mTest passed for input $input\e[0m\n"
elif [[ "$actual_output" == "$expected_output2" ]]; then
printf "\e[32mTest passed for input $input\e[0m\n"
else
printf "\e[31mTest failed for input $input: Expected $expected_output but got $actual_output\e[0m\n"
if [ -n "$3" ]; then
printf "\e[31mTest failed for input $input: Expected $expected_output1 or $expected_output2 but got $actual_output\e[0m\n"
else
printf "\e[31mTest failed for input $input: Expected $expected_output1 but got $actual_output\e[0m\n"
fi
exit 1
fi
}

# Arithmetic tests
test_eval "2 + 2" "4"
test_eval "2 + 2" "2"
test_eval "55 * 33" "1815"
test_eval "37 / 25.3" "1.46245059288538"
test_eval "sin(0.67)" "0.62098598703656"
Expand Down Expand Up @@ -203,7 +210,7 @@ test_eval 'default_value(1.5, 10.5)' '1.5'

# Exceptional cases
test_eval '4 / 0' 'inf'
test_eval '0 / 0' 'nan'
test_eval '0 / 0' 'nan' '-nan'

# Regex tests
test_eval 'regex("Hello World", "Hello (.*)")' '"World"'
Expand Down

0 comments on commit f783c57

Please sign in to comment.