mirror of
https://github.com/xlucn/PAT.git
synced 2026-10-03 00:23:15 +08:00
update code formatting
This commit is contained in:
@@ -1,25 +1,44 @@
|
||||
#!/bin/sh
|
||||
|
||||
mkdir -p temp
|
||||
trap 'rm -r temp' EXIT QUIT TERM INT
|
||||
|
||||
tracked_files=$(git ls-tree --name-only HEAD PAT*/)
|
||||
|
||||
for bin in "$@"; do
|
||||
# this problem has not been solved, so there is no code for it
|
||||
[ "$tracked_files" = "${tracked_files%$bin*}" ] && continue
|
||||
|
||||
# PATBasic/1001 -> b1001, etc.
|
||||
dir=$(dirname "$bin")
|
||||
id=$(basename "$bin")
|
||||
[ "$dir" = PATAdvanced ] && cat=a
|
||||
[ "$dir" = PATBasic ] && cat=b
|
||||
[ "$dir" = PATTop ] && cat=t
|
||||
case "$dir" in
|
||||
PATAdvanced) cat=a;;
|
||||
PATBasic) cat=b;;
|
||||
PATTop) cat=t;;
|
||||
esac
|
||||
|
||||
# run test and compare output
|
||||
for sample in "samples/$cat$id-"*.in; do
|
||||
echo "testing $bin, sample $sample"
|
||||
# use `printf "%s" output' to strip white spaces
|
||||
printf "%s" "$("$dir/$id" < "$sample" | tr -d '\0')" > temp/out
|
||||
printf "%s" "$(cat "${sample%.in}.out")" > temp/ans
|
||||
diff temp/out temp/ans || failed="$failed$bin $sample\n"
|
||||
done
|
||||
done
|
||||
|
||||
str_check_output="Scroll back for comparison between answer and actuall output"
|
||||
color_red="\033[1;31m"
|
||||
color_green="\033[1;32m"
|
||||
color_reset="\033[1;0m"
|
||||
|
||||
if [ -n "$failed" ]; then
|
||||
printf "$failed" | while read -r b s; do
|
||||
printf "\033[1;31m%s failed for sample %s\033[1;0m\n" "$b" "$s"
|
||||
printf "$failed%s" | while read -r b s; do
|
||||
printf "$color_red%s failed for sample %s$color_reset\n" "$b" "$s"
|
||||
done
|
||||
printf "\033[1;31mSee the previous output for differences between correct output and execute output\033[1;0m\n"
|
||||
printf "$color_red%s$color_reset\n" "$str_check_output"
|
||||
exit 1
|
||||
else
|
||||
printf "$color_green%s$color_reset\n" "All passed!"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user