mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
1.9 KiB
105 lines
1.9 KiB
2 years ago
|
#!/usr/bin/env bash
|
||
|
|
||
|
IFS='
|
||
|
'
|
||
|
script_dirS=$(cd -P "$(dirname "$BASH_SOURCE")" &>/dev/null && pwd)
|
||
|
|
||
|
challenge() {
|
||
|
|
||
|
declare -a equals=("Student1 90" "Student2 70" "Student3 50")
|
||
|
declare -a differents=("Student1 92" "Student2 75" "Student3 55" "Student4 25")
|
||
|
|
||
|
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")
|
||
|
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")
|
||
|
diff <(echo "$submitted") <(echo "$expected")
|
||
|
done
|
||
|
|
||
|
# Testing multiple students
|
||
|
submitted=$(
|
||
|
bash -c ""$script_dirS"/student/grades.sh 3" <<EOF
|
||
|
Bob
|
||
|
90
|
||
|
Alice
|
||
|
75
|
||
|
Eve
|
||
|
55
|
||
|
EOF
|
||
|
)
|
||
|
expected=$(
|
||
|
bash -c ""$script_dirS"/solutions/grades.sh 3" <<EOF
|
||
|
Bob
|
||
|
90
|
||
|
Alice
|
||
|
75
|
||
|
Eve
|
||
|
55
|
||
|
EOF
|
||
|
)
|
||
|
diff <(echo "$submitted") <(echo "$expected")
|
||
|
|
||
|
submitted=$(
|
||
|
bash -c ""$script_dirS"/student/grades.sh 5" <<EOF
|
||
|
Bob
|
||
|
90
|
||
|
Alice
|
||
|
75
|
||
|
Eve
|
||
|
55
|
||
|
john
|
||
|
49
|
||
|
Eric
|
||
|
65
|
||
|
EOF
|
||
|
)
|
||
|
expected=$(
|
||
|
bash -c ""$script_dirS"/solutions/grades.sh 5" <<EOF
|
||
|
Bob
|
||
|
90
|
||
|
Alice
|
||
|
75
|
||
|
Eve
|
||
|
55
|
||
|
john
|
||
|
49
|
||
|
Eric
|
||
|
65
|
||
|
EOF
|
||
|
)
|
||
|
diff <(echo "$submitted") <(echo "$expected")
|
||
|
|
||
|
# Checking if it fails with invallid grades
|
||
|
submitted=$(
|
||
|
bash -c ""$script_dirS"/student/grades.sh 3" <<EOF
|
||
|
Bob
|
||
|
90
|
||
|
Alice
|
||
|
150
|
||
|
Eve
|
||
|
55
|
||
|
EOF
|
||
|
)
|
||
|
expected=$(
|
||
|
bash -c ""$script_dirS"/solutions/grades.sh 3" <<EOF
|
||
|
Bob
|
||
|
90
|
||
|
Alice
|
||
|
150
|
||
|
Eve
|
||
|
55
|
||
|
EOF
|
||
|
)
|
||
|
diff <(echo "$submitted") <(echo "$expected")
|
||
|
}
|
||
|
|
||
|
challenge
|