From d07a43ebe8c3b6b1c7dd06fa6ed363b84958bdf3 Mon Sep 17 00:00:00 2001 From: miguel Date: Fri, 6 Jan 2023 00:22:42 +0000 Subject: [PATCH] feat(comparator): add subject, test and solution for the exercise --- sh/tests/comparator_test.sh | 22 ++++++++++++++++++++++ sh/tests/solutions/comparator.sh | 9 +++++++++ subjects/devops/comparator/README.md | 21 +++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100755 sh/tests/comparator_test.sh create mode 100755 sh/tests/solutions/comparator.sh create mode 100644 subjects/devops/comparator/README.md diff --git a/sh/tests/comparator_test.sh b/sh/tests/comparator_test.sh new file mode 100755 index 00000000..8f0bb9e6 --- /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 00000000..891748c5 --- /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 00000000..f4fafab0 --- /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!