feat(scripts): validate script to compare outputs between ASPforABA and aba2sat
This commit is contained in:
parent
3cef363869
commit
5aa9201a27
111
scripts/validate.sh
Executable file
111
scripts/validate.sh
Executable file
|
@ -0,0 +1,111 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
|
||||
print_help_and_exit() {
|
||||
if [ -n "$1" ]; then
|
||||
printf "$1\n\n"
|
||||
fi
|
||||
printf "Usage: validate [OPTIONS] \n"
|
||||
printf "\n"
|
||||
printf "Options:\n"
|
||||
printf " --aspforaba\n"
|
||||
printf " Binary to use when calling aspforaba\n"
|
||||
printf " -p, --problem\n"
|
||||
printf " The problem to solve\n"
|
||||
printf " -a, --arg\n"
|
||||
printf " The additional argument for the problem\n"
|
||||
printf " -f, --file\n"
|
||||
printf " The file containing the problem in ABA format\n"
|
||||
printf " --file-dir\n"
|
||||
printf " Use the following dir to read files, specify a single file with --file instead\n"
|
||||
exit 1
|
||||
}
|
||||
|
||||
run_dc_co() {
|
||||
if [ ! -n "$ADDITIONAL_ARG" ]; then
|
||||
print_help_and_exit "Parameter --arg is missing!"
|
||||
fi
|
||||
if [ ! -n "$ABA_FILE" ]; then
|
||||
print_help_and_exit "Parameter --file is missing!"
|
||||
fi
|
||||
printf "%40s " $(basename $ABA_FILE)
|
||||
our_result=$($ABA2SAT --file "$ABA_FILE" dc-co --query "$ADDITIONAL_ARG")
|
||||
other_result=$($ASPFORABA --file "$ABA_FILE" --problem DC-CO --query "$ADDITIONAL_ARG")
|
||||
if [ "$our_result" != "$other_result" ]; then
|
||||
printf "❌\n"
|
||||
printf "%40s:%s\n" "arg" "$ADDITIONAL_ARG"
|
||||
printf "%40s:%s\n" "Ours" "$our_result"
|
||||
printf "%40s:%s\n" "Theirs" "$other_result"
|
||||
else
|
||||
printf "✅\n"
|
||||
fi
|
||||
}
|
||||
|
||||
POSITIONAL_ARGS=()
|
||||
ASPFORABA=ASPforABA
|
||||
ABA2SAT=aba2sat
|
||||
ABA_FILE=
|
||||
ABA_FILE_DIR=
|
||||
ABA_FILE_EXT=aba
|
||||
ADDITIONAL_ARG_FILE_EXT=asm
|
||||
PROBLEM=
|
||||
ADDITIONAL_ARG=
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
-h | --help)
|
||||
print_help_and_exit;;
|
||||
--aspforaba)
|
||||
shift; ASPFORABA=$1; shift;;
|
||||
-p | --problem)
|
||||
shift; PROBLEM=$1; shift;;
|
||||
-f | --file)
|
||||
if [ -n "$ABA_FILE_DIR" ]; then
|
||||
print_help_and_exit "Parameters --file and --files-from cannot be mixed"
|
||||
fi
|
||||
shift; ABA_FILE=$1; shift;;
|
||||
--files-from)
|
||||
if [ -n "$ABA_FILE" ]; then
|
||||
print_help_and_exit "Parameters --file and --files-from cannot be mixed"
|
||||
fi
|
||||
if [ -n "$ADDITIONAL_ARG" ]; then
|
||||
print_help_and_exit "Parameters --arg and --files-from cannot be mixed"
|
||||
fi
|
||||
shift; ABA_FILE_DIR=$1; shift;;
|
||||
-a | --arg)
|
||||
if [ -n "$ABA_FILE_DIR" ]; then
|
||||
print_help_and_exit "Parameters --arg and --files-from cannot be mixed"
|
||||
fi
|
||||
shift; ADDITIONAL_ARG=$1; shift;;
|
||||
--aba2sat)
|
||||
shift; ABA2SAT=$1; shift;;
|
||||
-*)
|
||||
echo "Unknown option $1"
|
||||
print_help_and_exit
|
||||
;;
|
||||
*)
|
||||
POSITIONAL_ARGS+=("$1") # save positional arg
|
||||
shift # past argument
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
set -- "''${POSITIONAL_ARGS[@]}" # restore positional parameters
|
||||
|
||||
|
||||
|
||||
case "$PROBLEM" in
|
||||
dc-co | DC-CO)
|
||||
if [ -n "$ABA_FILE_DIR" ]; then
|
||||
# run for every file found in the directory
|
||||
for file in "$ABA_FILE_DIR"/*."$ABA_FILE_EXT"; do
|
||||
ABA_FILE="$file" ADDITIONAL_ARG="$(cat $file.asm)" run_dc_co
|
||||
done
|
||||
else
|
||||
# run for the single configured file
|
||||
run_dc_co
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
print_help_and_exit;;
|
||||
esac
|
Loading…
Reference in a new issue