Browse Source

test(grades) fix stderror testing scenarios for grades exercise

pull/1956/head
Zouhair AMAZZAL 1 year ago committed by MSilva95
parent
commit
2ba35afd50
  1. 27
      sh/tests/grades_test.sh
  2. 4
      sh/tests/solutions/grades.sh

27
sh/tests/grades_test.sh

@ -4,22 +4,35 @@ IFS='
'
script_dirS=$(cd -P "$(dirname "$BASH_SOURCE")" &>/dev/null && pwd)
challenge() {
input="${@: -1}"
args=${@:1:$#-1}
submitted=$(
bash -c ""$script_dirS"/student/grades.sh $args" <<EOF
bash -c ""$script_dirS"/student/grades.sh $args" 2> grades_submitted_errors 1>grades_submitted_output <<EOF
$input
EOF
)
expected=$(
bash -c ""$script_dirS"/solutions/grades.sh $args" <<EOF
grades_submitted_status=$?
bash -c ""$script_dirS"/solutions/grades.sh $args" 2> grades_expected_errors 1>grades_expected_output <<EOF
$input
EOF
)
diff <(echo "$submitted") <(echo "$expected")
grades_expected_status=$?
diff <(cat grades_submitted_output) <(cat grades_expected_output)
if [ $? != 0 ]; then
exit 1
fi
diff <(cat grades_submitted_errors) <(cat grades_expected_errors)
if [ $? != 0 ]; then
exit 1
fi
diff <(echo $grades_expected_status) <(echo $grades_submitted_status)
if [ $? != 0 ]; then
exit 1

4
sh/tests/solutions/grades.sh

@ -4,7 +4,7 @@ num_students=$1
declare -a students
if [ $# -ne 1 ]; then
echo "Error: expect 1 argument only!"
echo "Error: expect 1 argument only!" >/dev/stderr
exit 1
fi
@ -14,7 +14,7 @@ for ((i = 0; i < num_students; i++)); do
students+=("$name $grade")
if [ $(expr "$grade" \> 100) -eq 1 ] || ! [[ "$grade" =~ ^[0-9]+$ ]]; then
echo "Error: The grade '$grade' is not a valid input. Only numerical grades between 0 and 100 are accepted."
echo "Error: The grade '$grade' is not a valid input. Only numerical grades between 0 and 100 are accepted." >/dev/stderr
exit 1
fi
done

Loading…
Cancel
Save