test.sh: run all years

This commit is contained in:
Xiretza 2022-12-01 19:19:00 +01:00
parent e271b0d585
commit bb0fbc0f8f

37
test.sh
View file

@ -4,9 +4,11 @@ set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")" cd "$(dirname "${BASH_SOURCE[0]}")"
YEAR=2020 COMMON_DIR="$(realpath common)"
export COMMON_DIR
export COMMON_DIR="$(realpath common)" OUTDIR=$(mktemp --directory)
trap "rm -rf '$OUTDIR'" EXIT
run_solution() { run_solution() {
if [ -d "$solution" ]; then if [ -d "$solution" ]; then
@ -33,13 +35,14 @@ run_solution() {
fi fi
} }
shopt -s dotglob nullglob do_day() {
year=$1
day=$2
for n in $(seq 1 25); do input=$year/data/day$day.input
input=$YEAR/data/day$n.input expected=$year/data/day$day.expected
expected=$YEAR/data/day$n.expected
for solution in "$YEAR/day$n"/*; do for solution in "$year/day$day"/*; do
echo -n "$solution... " echo -n "$solution... "
case "${solution##*/}" in case "${solution##*/}" in
@ -48,9 +51,7 @@ for n in $(seq 1 25); do
continue continue
esac esac
solution_output=$(mktemp) solution_output=$OUTDIR/${year}_$day.out
trap "rm -f '$solution_output'" EXIT
run_solution "$solution" > "$solution_output" run_solution "$solution" > "$solution_output"
if ! diff -u "$expected" "$solution_output"; then if ! diff -u "$expected" "$solution_output"; then
@ -67,7 +68,19 @@ for n in $(seq 1 25); do
else else
echo ok echo ok
fi fi
rm "$solution_output"
done done
}
do_year() {
year=$1
for day in $(seq 1 25); do
do_day "$year" "$day"
done
}
shopt -s dotglob nullglob
for year in 2020 2021 2022; do
do_year "$year"
done done