-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsudoku-harness.sh
executable file
·83 lines (72 loc) · 1.5 KB
/
sudoku-harness.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
USAGE(){
echo "USAGE: $0 <directory of sudoku solvers>"
exit
}
if [ -z $1 ]; then
USAGE
elif [ -d $1 ]; then
DIR=$1
shift
echo "Usind directory $DIR for puzzles"
else
USAGE
fi
ROOTDIR=$(dirname $0)
if [ "$ROOTDIR" == "." ]; then
ROOTDIR=$(pwd)
fi
PUZZLES=${ROOTDIR}/puzzles.txt
if [ -z "$1" ]; then
: # : is a shell noop
elif [ "$1" == "-p" ] && [ -f "$2" ]; then
PUZZLES=${ROOTDIR}/$2
shift
shift
else
USAGE
fi
TIME=''
for clock in time gtime ; do
which $clock >/dev/null 2>&1
if [ "$?" == "1" ]; then
continue
fi
version=$($clock -V 2>&1)
if [ "$?" != "0" ]; then
continue
fi
echo $version | grep GNU > /dev/null
if [ "$?" == "0" ]; then
TIME=$clock
break
fi
done
# echo $TIME
if [ -z "$TIME" ]; then
echo "Could not find valid gnu time executable in your PATH"
exit
fi
cd $DIR
for f in ./*.py ; do
echo -n "starting solver $f"
cat $PUZZLES | while read pname puzzle solution; do
echo -n " $pname"
result=$(timeout 60 $TIME --output=${f}@${pname}@time1 python ${f} ${puzzle} 2>&1)
if [ "$result" != "$solution" ]; then
echo
echo "file $f failed to solve puzzle $puzzle"
echo "wrong: -- $result --"
echo "right: -- $solution --"
break
fi
result=$(timeout 60 $TIME --output=${f}@${pname}@time2 python ${f} ${puzzle} 2>&1)
result=$(timeout 60 $TIME --output=${f}@${pname}@time3 python ${f} ${puzzle} 2>&1)
# for res in ${f}@${pname}@time?; do
# t=$(cat $res | grep elapsed)
# done
done
echo " done"
done
${ROOTDIR}/compare.py
rm -f *time?