mirror of https://github.com/01-edu/public.git
fix(comparator):fixing the test
improving error message in the solution add readme info about error message
This commit is contained in:
parent
fb239fd7d2
commit
04e90aa8be
|
@ -5,19 +5,12 @@ set -euo pipefail
|
|||
IFS='
|
||||
'
|
||||
|
||||
# Test if there were only two arguments given
|
||||
|
||||
script_dirS=$(cd -P "$(dirname "$BASH_SOURCE")" &>/dev/null && pwd)
|
||||
|
||||
challenge() {
|
||||
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
|
||||
submitted=$(bash $script_dirS/student/comparator.sh "$@")
|
||||
expected=$(bash $script_dirS/solutions/comparator.sh "$@")
|
||||
diff <(echo "$submitted") <(echo "$expected")
|
||||
}
|
||||
|
||||
for i in $(seq 1 10); do
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if [ "$#" -ne 2 ]; then
|
||||
echo "Error: script requires two arguments to run"
|
||||
echo "Error: The script only works with two arguments!"
|
||||
elif ! [[ $1 =~ ^-?[0-9]*\.?[0-9]+$ ]] || ! [[ $2 =~ ^-?[0-9]*\.?[0-9]+$ ]]; then
|
||||
echo "Error: Only two numeric arguments are acceptable"
|
||||
echo "Error: Only two numeric arguments are acceptable!"
|
||||
elif [ "$1" -gt "$2" ]; then
|
||||
echo "$1 > $2"
|
||||
elif [ "$1" -lt "$2" ]; then
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
### Instructions
|
||||
|
||||
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.
|
||||
You must print the output like the example in usage.
|
||||
|
||||
### Usage
|
||||
|
||||
|
@ -14,6 +14,12 @@ $ ./comparator.sh 29 3
|
|||
29 > 3
|
||||
$ ./comparator.sh 12 12
|
||||
12 = 12
|
||||
$ ./comparator.sh 8 9 9
|
||||
Error: The script only works with two arguments!
|
||||
$ ./comparator.sh 8 s
|
||||
Error: Only two numeric arguments are acceptable!
|
||||
$ ./comparator.sh 8
|
||||
Error: The script only works with two arguments!
|
||||
$
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in New Issue