-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
168 lines (162 loc) · 3.6 KB
/
.bashrc
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
ulimit -s 10000
function compile {
g++ $1 -g -std=c++14 -Wall -Wextra -Wconversion -Wshadow -Wfatal-errors -fsanitize=address,undefined -o $2
}
function runcompiled {
if [[ $1 == *.py ]]; then
{ time (python3 $1 <$2 >o 2>error) >/dev/null; } 2>timing
else
{ time (./$1 <$2 >o 2>error) >/dev/null; } 2>timing
fi
cat timing | grep real | awk '{print $2}'
cat error
# Not required
rm timing
rm error
# Required
diff -y o ${2%in}[ao]?? >t || cat t || cat o
# Not required
rm o
rm t
}
function run {
clear;clear
first_file=`ls -t *.{cpp,py} | head -n1`
F=${1-$first_file}
if [[ $F == *.c* ]]
then
compile $F sol
runner='sol'
else
runner=$F
fi
if [ -n "$2" ]; then
echo ---$F $2
runcompiled $runner $2
else
for i in *.in; do
echo ---$F $i
runcompiled $runner $i
done
fi
}
## OPTIONAL
function runtests {
# Arguments
# Test generator
# Correct script
# Test script
# Total tests
clear;clear
if [[ $2 == *.c* ]];
then
compile $2 correct
fi
if [[ $3 == *.c* ]];
then
compile $3 test
fi
ITERATIONS=${4:-50}
completed=1
for (( i=1; i<=ITERATIONS; i++ )) do
echo "Test #$i"
python3 $1 > test.in
if [[ $2 == *.c* ]];
then
./correct < test.in > test.out
fi
if [[ $2 == *.py ]];
then
python3 $2 < test.in > test.out
fi
error=$?
if [[ $error -ne 0 ]]
then
echo "Error on test case with truth script"
completed=0
break
fi
if [[ $3 == *.c* ]];
then
./test < test.in > test.cmp
fi
if [[ $3 == *.py ]];
then
python3 $3 < test.in > test.cmp
fi
error=$?
if [[ $error -ne 0 ]]
then
echo "Error on test case with test script"
completed=0
break
fi
diff test.cmp test.out > /dev/null 2>&1
difference=$?
if [[ $difference -eq 1 ]]
then
echo "Difference found:"
echo "test.cmp | test.out"
diff test.cmp test.out
completed=0
break
fi
done
rm test
rm correct
if [[ $completed -eq 1 ]]
then
echo "Completed $ITERATIONS tests successfuly."
rm test.cmp
rm test.in
rm test.out
fi
}
function checkresult {
# Arguments
# Test generator
# Test script
# Postprocessing
# Num tests
clear;clear
if [[ $2 == *.c* ]];
then
compile $2 sol
fi
ITERATIONS=${4:-50}
completed=1
for (( i=1; i<=ITERATIONS; i++ )) do
echo "Test #$i"
python3 $1 > test.in
if [[ $2 == *.c* ]];
then
./sol < test.in > test.out
fi
if [[ $2 == *.py ]];
then
python3 $2 < test.in > test.out
fi
error=$?
if [[ $error -ne 0 ]]
then
echo "Error on test case with test script"
completed=0
break
fi
python3 $3 test.in test.out > test.result
str=GOOD
if [[ $(< test.result) != "$str" ]]; then
echo "Post processing failed."
completed=0
break
fi
done
rm sol
if [[ $completed -eq 1 ]]
then
echo "Completed $ITERATIONS tests successfuly."
rm test.result
rm test.in
rm test.out
fi
}