Browse Source

fixing readme solution and test

DEV-4397-piscine-ai-missing-file-for-ex-7-of-nlp
miguel 2 years ago committed by MSilva95
parent
commit
bc64c2cf03
  1. 8
      sh/tests/grades_test.sh
  2. 5
      sh/tests/solutions/grades.sh
  3. 45
      subjects/devops/grades/README.md

8
sh/tests/grades_test.sh

@ -12,15 +12,15 @@ challenge() {
for e in "${equals[@]}"; do
name=$(echo "$e" | awk '{print $1}')
grade=$(echo "$e" | awk '{print $2}')
submitted=$(echo "$name $grade" | bash -c ""$script_dirS"/student/grades.sh 1")
expected=$(echo "$name $grade" | bash -c ""$script_dirS"/solutions/grades.sh 1")
submitted=$(echo -e "$name $grade" | bash -c ""$script_dirS"/student/grades.sh 1")
expected=$(echo -e "$name $grade" | bash -c ""$script_dirS"/solutions/grades.sh 1")
diff <(echo "$submitted") <(echo "$expected")
done
for d in "${differents[@]}"; do
name=$(echo "$d" | awk '{print $1}')
grade=$(echo "$d" | awk '{print $2}')
submitted=$(echo "$name $grade" | bash -c ""$script_dirS"/student/grades.sh 1")
expected=$(echo "$name $grade" | bash -c ""$script_dirS"/solutions/grades.sh 1")
submitted=$(echo -e "$name $grade" | bash -c ""$script_dirS"/student/grades.sh 1")
expected=$(echo -e "$name $grade" | bash -c ""$script_dirS"/solutions/grades.sh 1")
diff <(echo "$submitted") <(echo "$expected")
done

5
sh/tests/solutions/grades.sh

@ -3,6 +3,11 @@
num_students=$1
declare -a students
if [ $# -ne 1 ]; then
echo "Error: Expect 1 argument only!"
exit 1
fi
for ((i = 0; i < num_students; i++)); do
read -p "Student Name #$((i + 1)): " name
read -p "Student Grade #$((i + 1)): " grade

45
subjects/devops/grades/README.md

@ -2,62 +2,67 @@
### Instructions
Create a script `grades.sh` which will ask the user for a specific number of students in order to evaluate them. After the number is set, the script will ask you to introduce the "names" and "grades" of the persons you wish to evaluate.
Create a script `grades.sh` which will ask, as an argument, for the user to give a specific number of students in order to evaluate them. After the number is set, the script will ask you to introduce the "names" and "grades" of the persons you wish to evaluate.
The grades will have a range between 0 and 100 and will be numeric values only.
According to each student grade you will have to return the following:
- If the student grade is anything lower than 50 you will return the string "<name>: You had a poor performance!":
- If the student grade is anything equal or greater than 90 you will return the string `"<name>: You did an excellent job!"`:
```console
$ ./grades.sh 1
Student Name #1: Sara
Student Grade #1: 34
Sara: You had a poor performance!
Student Grade #1: 90
Sara: You did an excellent job!
```
- If the student grade is anything equal or greater than 50 you will return the string "<name>: You need a bit more effort!":
- If the student grade is anything equal or greater than 70 you will return the string `"<name>: You did a good job!"`:
```console
$ ./grades.sh 1
Student Name #1: Sara
Student Grade #1: 51
Sara: You need a bit more effort!
Student Grade #1: 75
Sara: You did a good job!
```
- If the student grade is anything equal or greater than 70 you will return the string "<name>: You did a good job!":
- If the student grade is anything equal or greater than 50 you will return the string `"<name>: You need a bit more effort!"`:
```console
$ ./grades.sh 1
Student Name #1: Sara
Student Grade #1: 75
Sara: You did a good job!
Student Grade #1: 51
Sara: You need a bit more effort!
```
- If the student grade is anything equal or greater than 90 you will return the string "<name>: You did an excellent job!":
- If the student grade is anything lower than 50 you will return the string `"<name>: You had a poor performance!"`:
```console
$ ./grades.sh 1
Student Name #1: Sara
Student Grade #1: 90
Sara: You did an excellent job!
Student Grade #1: 34
Sara: You had a poor performance!
```
### Error handling
All errors will print a specific message on **stderr** (ending with a newline) and returns a specific non-zero value:
- Wrong number of arguments: `"Error: expect 2 arguments"`, exit with `1`.
- Wrong number of arguments: `"Error: expect 1 argument only!"`, exit with `1`.
- If the student grade is not a number or is greater than 100: `Error: The grade "grade" is not a valid input. Only numerical grades between 0 and 100 are accepted.`, exit with `1`.
```console
$ ./grades.sh 3
./grades.sh 2
$ ./grades.sh 2
Student Name #1: Sara
Student Grade #1: 101
Error: The grade '101' is not a valid input. Only numerical grades between 0 and 100 are accepted.
./grades.sh 2
Student Name #1: Bob
Student Grade #1: ten
Error: The grade 'ten' is not a valid input. Only numerical grades between 0 and 100 are accepted.
$ ./grades.sh 1 2 3
Error: Expect 1 argument only!
$
```
@ -85,22 +90,22 @@ In bash, you can use the `read` command to read input from the user and store it
`read var_name`
You can also use the "-p" option to specify a prompt that will be displayed to the user before reading the input.
You can also use the `-p` option to specify a prompt that will be displayed to the user before reading the input.
Use loops to go through each student. For example the for loop is very helpful.
```console
```bash
for element in sequence
do
# commands to be executed
done
```
You can use an array to store multiple pieces of data. To create an array, you can use the `declare` command with the "-a" option:
You can use an array to store multiple pieces of data. To create an array, you can use the `declare` command with the `-a` option:
`declare -a name_array`
To add elements to the array, you can use the += operator:
To add elements to the array, you can use the `+=` operator:
`name_array+=("Adding this to the array")`

Loading…
Cancel
Save