-
Notifications
You must be signed in to change notification settings - Fork 0
/
pstester.sh
executable file
·163 lines (151 loc) · 3.32 KB
/
pstester.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
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
#!/bin/bash
# _ _ _ _ _ _ _ _
# / \ / \ / \ / \ / \ / \ / \ / \
# ( p )( s )( t )( e )( s )( t )( e )( r )
# \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
source config.sh
source commands.sh
source short_sets.sh
source long_sets.sh
#
# CLEAN
#
# Remove previous executable file
rm -f a.out 2> /dev/null
# Remove previous log file
rm -f log 2> /dev/null
#
# COMPILE
#
$cc $src $inc $lib
# Display moves
function printMoves ()
{
echo -ne "\n"
timeout $timeout ./a.out $1 2> /dev/null
export moves=$(timeout $timeout ./a.out $1 2> /dev/null | wc -l)
echo -ne "\n"
}
#
# FUNCTIONS
#
# Variables to get the total score
score=0 # Total OKs
average=0;
total=0 # Total tests
unsorted=0 # Total unsorted lists
hm=0 # Total higher moves
count=0 # Number of tested combinations for a set
# Main testing function
function tester ()
{
# Print label
label=$1
echo -e "${cyan}${label}${nc}"
# Allowed max moves
limit=$2
shift
shift
average=0
count=0
# testing loop
for i in "$@"
do
total=$[$total + 1]
# Feed log file
echo -en "[$i]" >> log
printMoves "$i" >> log
# Variable that displays number of moves
if [[ $move_count ]]
then
display_move_count=" (${moves}mv)"
fi
# Print moves
if [[ $all ]]
then
printMoves "$i"
fi
res=$(timeout $timeout ./a.out $i 2> /dev/null | ./$checker $i)
if [[ $res == "OK" ]] && [[ $moves -le $limit ]]
then # Print 'OK'
((score++))
if [[ ${label} == "=== 100 ELEMENTS ===" ]]
then
no=$[$count + 1]
echo -en "${green}.$no [OK${display_move_count}]${nc} "
else
echo -en "${green}[$i${display_move_count}]${nc} "
fi
elif [[ $res == "KO" ]] # print 'ko'
then
((unsorted++))
if [[ $err ]]
then
if [[ ${label} == "=== 100 ELEMENTS ===" ]]
then
no=$[$count + 1]
echo -en "${red}.$no [${display_move_count}]${nc} "
else
echo -en "\n${red}[$i${display_move_count}]${nc} "
fi
printMoves "$i"
else
echo -en "${red}[$i${display_move_count}]${nc} "
fi
elif [[ $res == "OK" ]] && [[ $moves -gt $limit ]]
then
((hm++))
if [[ ${label} == "=== 100 ELEMENTS ===" ]]
then
no=$[$count + 1]
echo -en "${red}.$no [HM${display_move_count}]${nc} "
else
echo -en "${red}[HM:$i${display_move_count}]${nc} "
fi
else
echo -en "${red}[${res}]${nc} "
fi
average=$[$average + $moves]
count=$[$count + 1]
done
average=$[$average / $count]
echo -e "\n"
echo -e "Average: $average moves"
echo -e "\n"
}
#
# Testing
#
echo -en "\n"
echo -e "START...\n"
# Non continuous numbers
tester "=== NON CONTINUOUS ===" "12" "${nonContinuous[@]}"
# Two elements
tester "=== 2 ===" "1" "${two[@]}"
# Three elements
tester "=== 3 ELEMENTS ===" "2" "${three[@]}"
# Four elements
tester "=== 4 ELEMENTS ===" "12" "${four[@]}"
# Five elements
tester "=== 5 ELEMENTS ===" "12" "${five[@]}"
# Six elements
tester "=== 6 ELEMENTS ===" "13" "${six[@]}"
# Seven elements
tester "=== 7 ELEMENTS ===" "17" "${seven[@]}"
# Twenty elements
tester "=== 20 ELEMENTS ===" "90" "${twenty[@]}"
# Hundred elements
tester "=== 100 ELEMENTS ===" "1100" "${hundred[@]}"
#
# Print results
#
echo -en "...END\n\n"
echo -en "Your score:\t\t$score/$total\n"
echo -en "Unsorted lists:\t\t$unsorted\n"
echo -en "Higher moves:\t\t$hm"
echo -en "\n\n"
#
# Clean
#
rm -f ../*.gch 2> /dev/null
rm -f a.out 2> /dev/null