diff --git a/sh/tests/Dockerfile b/sh/tests/Dockerfile index e6df75101..192dbed0a 100644 --- a/sh/tests/Dockerfile +++ b/sh/tests/Dockerfile @@ -1,7 +1,7 @@ FROM docker.01-edu.org/debian:10.9-slim RUN apt-get update -RUN apt-get -y install jq curl tree apt-utils +RUN apt-get -y install jq curl tree apt-utils bc WORKDIR /app/assets/superhero RUN curl --remote-name --location https://demo.01-edu.org/assets/superhero/all.json diff --git a/sh/tests/division_test.sh b/sh/tests/division_test.sh index d6990dbfe..a287f5aca 100755 --- a/sh/tests/division_test.sh +++ b/sh/tests/division_test.sh @@ -9,20 +9,18 @@ script_dirS=$(cd -P "$(dirname "$BASH_SOURCE")" &>/dev/null && pwd) challenge() { # Test if test command was used - if grep -q "test" "$script_dirS"/student/division.sh - then + if grep -q "test" "$script_dirS"/student/division.sh; then echo "Error: the test command cannot be used in the student script" return fi # Test with one or two arguments - if [ $# -eq 1 ] - then - submitted=$(bash "$script_dirS"/student/division.sh $1) - expected=$(bash "$script_dirS"/solutions/division.sh $1) + if [ $# -eq 1 ]; then + submitted=$(bash "$script_dirS"/student/division.sh $1) + expected=$(bash "$script_dirS"/solutions/division.sh $1) else - submitted=$(bash "$script_dirS"/student/division.sh $1 $2) - expected=$(bash "$script_dirS"/solutions/division.sh $1 $2) + submitted=$(bash "$script_dirS"/student/division.sh $1 $2) + expected=$(bash "$script_dirS"/solutions/division.sh $1 $2) fi diff <(echo "$submitted") <(echo "$expected") } diff --git a/sh/tests/solutions/division.sh b/sh/tests/solutions/division.sh index b1523e222..3ec09c94c 100755 --- a/sh/tests/solutions/division.sh +++ b/sh/tests/solutions/division.sh @@ -1,24 +1,21 @@ #!/usr/bin/env bash # Check if two arguments were provided -if [ $# -ne 2 ] -then +if [ $# -ne 2 ]; then echo "Error: two numbers must be provided" # # Check if the arguments are numeric -elif ! [[ $1 =~ ^-?[0-9]*\.?[0-9]+$ ]] || ! [[ $2 =~ ^-?[0-9]*\.?[0-9]+$ ]] -then +elif ! [[ $1 =~ ^-?[0-9]*\.?[0-9]+$ ]] || ! [[ $2 =~ ^-?[0-9]*\.?[0-9]+$ ]]; then echo "Error: both arguments must be numeric" # Check if the second argument is not 0 -elif [ $(echo "$2 == 0" | bc) -eq 1 ] -then +elif [[ $(echo "$2 == 0" | bc) -eq 1 ]]; then echo "Error: division by zero is not allowed" # Divide the first argument by the second using bc -else -result=$(echo "$1 / $2" | bc ) +else + result=$(echo "$1 / $2" | bc) -# Output the result -echo $result + # Output the result + echo $result fi