-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathck
executable file
·99 lines (84 loc) · 1.77 KB
/
ck
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
set -e
set -u
set -o pipefail
function exit_error(){
echo ERROR: $*
exit 1
}
if [[ ! -d input ]] ; then
d=$(pwd)
chal=${d##*/}
curl -s https://www.hackerrank.com/rest/contests/master/challenges/$chal/download_testcases > test.zip
unzip test.zip
rm test.zip
for i in input/* ; do
echo $i
fn=${i#*/}
base=${fn%.txt}
n=${base#input}
out=output/output${n}.txt
[[ -e $out ]] || exit_error "$out file not found"
# add an eol which is often missing
ed -s $out <<< w
ed -s $i <<< w
# sometimes ^M instead of proper line endings
dos2unix $out
done
fi
if [[ ! -e ans.py ]] ; then
cp ../ans_template.py ans.py
exit_error "ans.py not found, edit template"
fi
[[ -e ans.py ]] || exit_error "ans.py not found"
f=$(mktemp)
echo -n "pep8. "
set +e
pep8 ans.py > $f 2>&1
PRC=$?
if [[ $PRC -ne 0 ]]; then
echo FAIL
cat $f
exit_error "fix pep8 complaints"
else
echo PASS
rm -f $f
fi
echo
for i in input/* ; do
echo $i
fn=${i#*/}
base=${fn%.txt}
n=${base#input}
out=output/output${n}.txt
[[ -e $out ]] || exit_error "$out file not found"
echo "Test $n .."
f=$(mktemp)
chmod u+x ans.py
set +e
./ans.py < $i > out 2> err
RC=$?
set -e
if [[ $RC -ne 0 ]] ; then
echo FAIL
cat out
cat err
echo "non-zero exit $RC from ans.py"
fi
set +e
diff out $out > $f
DRC=$?
set -e
if [[ $DRC -ne 0 ]] ; then
echo FAIL
echo "output mismatch non-zero exit $DRC from diff"
echo "compare out and $out"
cat $f
fi
if [[ $DRC -eq 0 && $PRC -eq 0 ]] ; then
echo PASS
else
echo FAIL
exit 1
fi
done