mirror of https://github.com/01-edu/public.git
fix(division): add the bc to the dockerfile
add the double square brackets in the solution fix indent in the test
This commit is contained in:
parent
69f209c015
commit
48a3186b26
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue