From f783c57490614ee3f7e6d42c79741a09b27b4694 Mon Sep 17 00:00:00 2001 From: Victor Cordeiro Costa Date: Tue, 28 Nov 2023 15:15:33 -0300 Subject: [PATCH] Consider nan AND -nan as result of 0/0 Consider multiple correct expects in tests.sh --- tests.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests.sh b/tests.sh index 8d1ff48..9428c2b 100755 --- a/tests.sh +++ b/tests.sh @@ -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" @@ -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"'