-
Notifications
You must be signed in to change notification settings - Fork 56
Closed
Description
Failure Case 1
Not sure if this is expected failure case of unit tests in bash. Here is an example HumanEval_45_triangle_area
#!/bin/bash
#
#
# $1 is an integer
# $2 is an integer
triangle_area() {
echo "$1 * $2 / 2.0" | bc -l
}
candidate() {
triangle_area "$@"
}
set -e
run_test() {
[[ $(candidate "5" "3") = "7.5" ]]
[[ $(candidate "2" "2") = "2.0" ]]
[[ $(candidate "10" "8") = "40.0" ]]
}
run_testIf we print the output of $(candidate "5" "3"), it is "7.500000000", and it is different from the expected "7.5", tests fails. Maybe something with bc to evaluate the numeric value of the strings instead of comparing strings?
Failure Case 2
HumanEval_42_incr_list
#!/bin/bash
#
#
# $1 is a space-separated list
incr_list() {
for e in $1; do
echo $((e + 1))
done
}
candidate() {
incr_list "$@"
}
set -e
run_test() {
# [[ $(candidate "") = "" ]]
echo $(candidate "3 2 1") # prints -> 4 3 2\n
# [[ $(candidate "3 2 1") = "4 3 2" ]]
echo $(candidate "5 2 5 2 3 3 9 0 123") # prints -> 6 3 6 3 4 4 10 1 124\n
[[ $(candidate "5 2 5 2 3 3 9 0 123") = "6 3 6 3 4 4 10 1 124" ]]
}
run_testfirst test passes, second and third tests fail. And so I printed out the output of each cases.
I tried adding the newline character \n to the end of expected values and that didn't work. My lack of knowledge in Bash is not giving me any idea how it might be fixed.. but I don't think this should fail?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels