labs/lab-3/check.sh

139 lines
2.3 KiB
Bash
Executable file

#!/usr/bin/env bash
declare -r program="$1"
declare -r tmp1=tmp1 #"$(mktemp)"
declare -r tmp2=tmp2 #"$(mktemp)"
declare -ri case_1_a1=1
declare -ri case_1_a2=4
declare -r case_1="$(mktemp)"
cat <<'EOM' > "$case_1"
$$$$
$$$$
$$$$
$$$$
EOM
declare -ri case_2_a1=1
declare -ri case_2_a2=10
declare -r case_2="$(mktemp)"
cat <<'EOM' > "$case_2"
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
EOM
declare -ri case_3_a1=2
declare -ri case_3_a2=6
declare -r case_3="$(mktemp)"
cat <<'EOM' > "$case_3"
$$
$$$$
$$$$$$
EOM
declare -ri case_4_a1=2
declare -ri case_4_a2=7
declare -r case_4="$(mktemp)"
cat <<'EOM' > "$case_4"
$
$$$
$$$$$
$$$$$$$
EOM
declare -ri case_5_a1=3
declare -ri case_5_a2=14
declare -r case_5="$(mktemp)"
cat <<'EOM' > "$case_5"
$$$$$$$$$$$$$$
$$$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$
$$$$$$
$$$$
$$
EOM
declare -ri case_6_a1=4
declare -ri case_6_a2=14
declare -r case_6="$(mktemp)"
cat <<'EOM' > "$case_6"
$$
$$$$
$$$$$$
$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$$$
$$$$$$$$$$$$$$
$$$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$
$$$$$$
$$$$
$$
EOM
declare -ri case_7_a1=4
declare -ri case_7_a2=15
declare -r case_7="$(mktemp)"
cat <<'EOM' > "$case_7"
$
$$$
$$$$$
$$$$$$$
$$$$$$$$$
$$$$$$$$$$$
$$$$$$$$$$$$$
$$$$$$$$$$$$$$$
$$$$$$$$$$$$$
$$$$$$$$$$$
$$$$$$$$$
$$$$$$$
$$$$$
$$$
$
EOM
if ! gcc -Wall -Wextra -Werror -std=c99 "$program"; then
echo "Program compiled with errors. Did NOT pass check"
exit 1
fi
run_case() {
local a1="$1"
local a2="$2"
local tmp="$3"
local comp="$4"
local case="$5"
if ! ./a.out $a1 $a2 > "$tmp"; then
echo "Error at runtime on case $case"
exit 2
fi
sed -i 's#\s*$##' "$tmp"
if ! diff -qy "$tmp" "$comp"; then
echo "Input does not match for case $case"
exit 2
fi
}
# Case 1
run_case "$case_1_a1" "$case_1_a2" "$tmp1" "$case_1" 1
run_case "$case_2_a1" "$case_2_a2" "$tmp1" "$case_2" 2
run_case "$case_3_a1" "$case_3_a2" "$tmp1" "$case_3" 3
run_case "$case_4_a1" "$case_4_a2" "$tmp1" "$case_4" 4
run_case "$case_5_a1" "$case_5_a2" "$tmp1" "$case_5" 5
run_case "$case_6_a1" "$case_6_a2" "$tmp1" "$case_6" 6
run_case "$case_7_a1" "$case_7_a2" "$tmp1" "$case_7" 7
echo "You passed! Commit to git before the deadline"