Skip to content

Commit

Permalink
Consider multiple correct results in equations-parser automated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorcorcos committed Nov 28, 2023
1 parent b81e50b commit fefff44
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,14 +5,21 @@ 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
echo -e "\e[32mTest passed for input $input\e[0m"
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
echo -e "\e[31mTest failed for input $input: Expected $expected_output but got $actual_output\e[0m"
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
}
Expand Down Expand Up @@ -187,7 +194,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 fefff44

Please sign in to comment.