Browse Source

fix(comparator):fixing test and adding info to the readme

DEV-4191-DeepInSystem
miguel 1 year ago committed by MSilva95
parent
commit
fb239fd7d2
  1. 18
      sh/tests/comparator_test.sh
  2. 6
      sh/tests/solutions/comparator.sh
  3. 2
      subjects/devops/comparator/README.md

18
sh/tests/comparator_test.sh

@ -4,13 +4,22 @@
set -euo pipefail
IFS='
'
# Test if there were only two arguments given
script_dirS=$(cd -P "$(dirname "$BASH_SOURCE")" &>/dev/null && pwd)
challenge() {
submitted=$(bash "$script_dirS"/student/comparator.sh $1 $2)
expected=$(bash "$script_dirS"/solutions/comparator.sh $1 $2)
diff <(echo "$submitted") <(echo "$expected")
if [ $# -ne 2 ]; then
submitted=$(bash "$script_dirS"/student/comparator.sh $1)
expected=$(bash "$script_dirS"/solutions/comparator.sh $1)
else
submitted=$(bash "$script_dirS"/student/comparator.sh $1 $2)
expected=$(bash "$script_dirS"/solutions/comparator.sh $1 $2)
diff <(echo "$submitted") <(echo "$expected")
fi
}
for i in $(seq 1 10); do
n1=$(shuf -i 1-20 -n 1)
n2=$(shuf -i 1-30 -n 1)
@ -20,3 +29,6 @@ done
challenge "0" "0"
challenge "10" "10"
challenge "-11" "-11"
challenge "14"
challenge "-11" "-11" "4"
challenge "as" "str"

6
sh/tests/solutions/comparator.sh

@ -1,6 +1,10 @@
#!/usr/bin/env bash
if [ "$1" -gt "$2" ]; then
if [ "$#" -ne 2 ]; then
echo "Error: script requires two arguments to run"
elif ! [[ $1 =~ ^-?[0-9]*\.?[0-9]+$ ]] || ! [[ $2 =~ ^-?[0-9]*\.?[0-9]+$ ]]; then
echo "Error: Only two numeric arguments are acceptable"
elif [ "$1" -gt "$2" ]; then
echo "$1 > $2"
elif [ "$1" -lt "$2" ]; then
echo "$1 < $2"

2
subjects/devops/comparator/README.md

@ -2,7 +2,7 @@
### Instructions
Create a script `comparator.sh` which will verify if the first given argument is bigger, smaller or equal than the second given argument.
Create a script `comparator.sh` which will accept only two numbers as arguments and it will verify if the first given argument is bigger, smaller or equal than the second given argument.
You must print te output like the example in usage.
### Usage

Loading…
Cancel
Save