diff --git a/sh/tests/comparator_test.sh b/sh/tests/comparator_test.sh new file mode 100755 index 000000000..8f0bb9e6c --- /dev/null +++ b/sh/tests/comparator_test.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +# Unofficial Bash Strict Mode +set -euo pipefail +IFS=' +' +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") +} +for i in $(seq 1 10); do + n1=$(shuf -i 1-20 -n 1) + n2=$(shuf -i 1-30 -n 1) + challenge $n1 $n2 +done + +challenge "0" "0" +challenge "10" "10" +challenge "-11" "-11" diff --git a/sh/tests/solutions/comparator.sh b/sh/tests/solutions/comparator.sh new file mode 100755 index 000000000..891748c57 --- /dev/null +++ b/sh/tests/solutions/comparator.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +if [ "$1" -gt "$2" ]; then + echo "$1 > $2" +elif [ "$1" -lt "$2" ]; then + echo "$1 < $2" +else + echo "$1 = $2" +fi diff --git a/subjects/devops/comparator/README.md b/subjects/devops/comparator/README.md new file mode 100644 index 000000000..f4fafab0e --- /dev/null +++ b/subjects/devops/comparator/README.md @@ -0,0 +1,21 @@ +## comparator + +### Instructions + +Create a script `comparator.sh` which 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 + +```console +$ ./comparator.sh 6 14 +6 < 14 +$ ./comparator.sh 29 3 +29 > 3 +$ ./comparator.sh 12 12 +12 = 12 +$ +``` + +> You have to use Man or Google to know more about commands flags, in order to solve this exercise! +> Google and Man will be your friends!