Browse Source

fix(division): refactor to exit with 0

pull/1749/head
eslopfer 2 years ago
parent
commit
596e6bc683
  1. 1
      sh/tests/division_test.sh
  2. 8
      sh/tests/solutions/division.sh

1
sh/tests/division_test.sh

@ -24,7 +24,6 @@ challenge() {
submitted=$(bash "$script_dirS"/student/division.sh $1 $2)
expected=$(bash "$script_dirS"/solutions/division.sh $1 $2)
fi
diff <(echo "$submitted") <(echo "$expected")
}

8
sh/tests/solutions/division.sh

@ -4,21 +4,21 @@
if [ $# -ne 2 ]
then
echo "Error: two numbers must be provided"
exit 1
exit 0
fi
# Check if the arguments are numeric
# # Check if the arguments are numeric
if ! [[ $1 =~ ^-?[0-9]*\.?[0-9]+$ ]] || ! [[ $2 =~ ^-?[0-9]*\.?[0-9]+$ ]]
then
echo "Error: both arguments must be numeric"
exit 1
exit 0
fi
# Check if the second argument is not 0
if [ $(echo "$2 == 0" | bc) -eq 1 ]
then
echo "Error: division by zero is not allowed"
exit 1
exit 0
fi
# Divide the first argument by the second using bc

Loading…
Cancel
Save