-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtester.sh
executable file
·116 lines (95 loc) · 2.92 KB
/
tester.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
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
#!/bin/bash
# author: Piotr "pibuxd" Bublik (https://github.com/pibuxd)
# tester for competetive programming (CP)
# color variables
green=$(tput setaf 72);
red=$(tput setaf 1);
blue=$(tput setaf 32);
magenta=$(tput setaf 5)
bold=$(tput bold);
reset=$(tput sgr0);
function help () {
echo "usage:"
echo -ne "\ttester [operation] <param> \n\n"
echo "operations:"
echo -ne "\ttest ==> run test cases genarated on seed from <param2> to ∞\n"
echo -ne "\tgen ==> print generated input for seed <param2>\n"
echo -ne "\n"
echo "defaults:"
echo -ne "\t<param1> ==> help\n"
echo -ne "\t<param2> ==> 0"
echo -ne "\n"; exit 1
}
arg1=$1
arg2=$2
arg3=$3
if [[ "$1" != "" ]]; then
if [[ "$1" != "test" && "$1" != "gen" && "$1" != "help" ]]; then
echo -ne "${red}bad operation:${reset} \"$1\"\n\n"
help
exit 1
fi
fi
if [[ "$1" == "help" || "$1" == "" ]]; then
help
exit 1
fi
# compile generator with CP flags
START=$(date +%s.%N)
g++ -O3 -o generator generator.cpp ||
{ echo "generator.cpp -> ${bold}${red}compilation error${reset}"; exit 1; }
DIFF=$(echo "$(date +%s.%N) - $START" | bc)
printf "generator.cpp -> ${bold}${green}compiled${reset} in %.6f sec \n" $DIFF
if [[ "$2" == "" ]]; then
arg2=0
fi
if [[ "$3" == "" ]]; then
arg3=arg2
fi
if [[ "$1" = "test" ]]; then
# testing
# compile brute and pattern with CP flags
START=$(date +%s.%N)
g++ -O3 -o brute brute.cpp ||
{ echo "brute.cpp -> ${bold}${red}compilation error${reset}"; exit 1; }
DIFF=$(echo "$(date +%s.%N) - $START" | bc)
printf "brute.cpp -> ${bold}${green}compiled${reset} in %.6f sec \n" $DIFF
START=$(date +%s.%N)
g++ -O3 -o pattern pattern.cpp ||
{ echo "pattern.cpp -> ${bold}${red}compilation error${reset}"; exit 1; }
DIFF=$(echo "$(date +%s.%N) - $START" | bc)
printf "pattern.cpp -> ${bold}${green}compiled${reset} in %.6f sec \n" $DIFF
echo -ne "\n"
MAX_TIME=0
MAX_TEST=0
printf "${bold}${blue}testing...${reset}\n"
for ((i = $arg2; i <= $arg3; i++)); do
echo $i > ziarno
./generator < ziarno > input.in
./brute < input.in > brute.out
START=$(date +%s.%N)
./pattern < input.in > pattern.out
END=$(date +%s.%N)
DIFF=$(echo "$(date +%s.%N) - $START" | bc)
if (( $( echo "$DIFF > $MAX_TIME" | bc) )); then
MAX_TIME=$DIFF
MAX_TEST=$i
fi
if diff -b brute.out pattern.out > /dev/null; then
printf "test: $i${green} OK${reset} in %.6f sec \r" $DIFF
else
# if [ -n "$(diff -b brute.out pattern.out)" ]; then
printf "test: $i${red} ERROR${reset} in %.6f sec" $DIFF
break
fi
done
printf "\nMax time on test: ${magenta}$MAX_TEST${reset} in %.6f sec \n" $MAX_TIME
elif [[ "$1" = "gen" ]]; then
# print input of the input generator
echo -ne "\ninput for test: ${magenta}${arg2}${reset}\n"
echo $arg2 > ziarno
./generator < ziarno
echo -ne "\n"
fi
# remove temporary files
rm -f ziarno input.in pattern.out brute.out brute pattern generator