Browse Source

feat(comparator): add subject, test and solution for the exercise

pull/1751/head
miguel 2 years ago committed by MSilva95
parent
commit
d07a43ebe8
  1. 22
      sh/tests/comparator_test.sh
  2. 9
      sh/tests/solutions/comparator.sh
  3. 21
      subjects/devops/comparator/README.md

22
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"

9
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

21
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!
Loading…
Cancel
Save