Repository navigation
Expand file tree
/
Copy pathtestea09.sh
More file actions
executable file
·217 lines (189 loc) · 3.39 KB
/
Copy pathtestea09.sh
File metadata and controls
executable file
·217 lines (189 loc) · 3.39 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/bash
# Scritp para la prueba del ejercicio01 de la Práctica 1 de Inf. Ind.
# Curso 18-19
GPP=g++
# Limitamos procesos hijos, por si se descontrolan
ulimit -v 3000000 -t 5
if [ $# -lt 1 ]
then
echo "$0: Falta primer argumento con fichero fuente testear"
exit 1
fi
FICHERO_CPP=$1
EJECUTA=ejecutable$$
TMPF=tempfile$$
TMPOK=tempfileOK$$
TMPIN=tempfileIN$$
rojo() { echo -e "$(tput setaf 1)$@$(tput setaf 9)"; }
verde() { echo -e "$(tput setaf 2)$@$(tput setaf 9)"; }
amarillo() { echo -e "$(tput setaf 3)$@$(tput setaf 9)"; }
azul() { echo -e "$(tput setaf 4)$@$(tput setaf 9)"; }
magenta() { echo -e "$(tput setaf 5)$@$(tput setaf 9)"; }
cian() { echo -e "$(tput setaf 6)$@$(tput setaf 9)"; }
if [ ! -r $FICHERO_CPP ]
then
echo "$0: No puedo acceder al fichero $FICHERO_CPP"
exit 2
fi
CMD="$GPP --std=c++14 -Wall -o $EJECUTA $FICHERO_CPP"
magenta "\nPasamos a compilar en fuente ==============="
echo $CMD
$CMD
if [ $? -ne 0 ]
then
echo "$0: Falló la compilación"
exit 2
fi
$GPP --std=c++14 -Wall -Werror -o $EJECUTA $FICHERO_CPP &>/dev/null
if [ $? -ne 0 ]
then
amarillo "Compilación con Warnings"
fi
magenta "\nComenzamos las pruebas ==========="
PRUEBAS=0
ERRORES=0
ejecutaOK() {
let PRUEBAS++
./$EJECUTA <$TMPIN >$TMPF 2>/dev/null
if [ $? -eq 0 ]
then
verde "CORRECTO: código devuelto es 0"
else
rojo "Error: La ejecución debe ser CORRECTO pero devuelve !=0"
let ERRORES++
fi
let PRUEBAS++
diff --ignore-trailing-space -q $TMPOK $TMPF &>/dev/null
if [ $? -eq 0 ]
then
verde "CORRECTO: lo volcado por salida estándar es correcto"
else
rojo "ERROR: la salida estándar debería ser"
cat $TMPOK
rojo "Pero lo volcado es"
cat $TMPF
let ERRORES++
fi
}
# #########################################
cian "\n* Entrada 0 directamente"
cat > $TMPIN <<_EOF_
0
_EOF_
cat > $TMPOK <<_EOF_
0 0x0
_EOF_
ejecutaOK
cian "\n* Números potencia de 2"
cat > $TMPIN <<_EOF_
1
2
4
8
16
32
1024
0
_EOF_
cat > $TMPOK <<_EOF_
1 0x1
10 0x2
100 0x4
1000 0x8
10000 0x10
100000 0x20
10000000000 0x400
0 0x0
_EOF_
ejecutaOK
cian "\n* Números de 2 bits"
cat > $TMPIN <<_EOF_
3
6
12
5
10
9
18
33
1032
0
_EOF_
cat > $TMPOK <<_EOF_
11 0x3
110 0x6
1100 0xc
101 0x5
1010 0xa
1001 0x9
10010 0x12
100001 0x21
10000001000 0x408
0 0x0
_EOF_
ejecutaOK
cian "\n* Números de 3 bits"
cat > $TMPIN <<_EOF_
7
14
11
13
273
0
_EOF_
cat > $TMPOK <<_EOF_
111 0x7
1110 0xe
1011 0xb
1101 0xd
100010001 0x111
0 0x0
_EOF_
ejecutaOK
cian "\n* Números de muchos bits"
cat > $TMPIN <<_EOF_
61
65535
437
0
_EOF_
cat > $TMPOK <<_EOF_
111101 0x3d
1111111111111111 0xffff
110110101 0x1b5
0 0x0
_EOF_
ejecutaOK
# #########################################
cian "\n* Entrada incorrecta"
let PRUEBAS++
./$EJECUTA &>/dev/null <<_EOF_
4
xx
_EOF_
Devuelto=$?
if [ $Devuelto -eq 134 ]
then
rojo "ERROR: el programa fue abortado"
let ERRORES++
else
if [ $Devuelto -ne 0 ]
then
verde "CORRECTO: código devuelto es != 0"
else
rojo "Error: La ejecución debe ser INCORRECTA pero devuelve 0"
let ERRORES++
fi
fi
# #########################################
magenta "\nPruebas terminadas ============"
if [ $ERRORES -gt 0 ]
then
rojo "Realizadas $PRUEBAS pruebas con $ERRORES errores\n"
else
verde "Realizadas $PRUEBAS pruebas con $ERRORES errores :-)\n"
fi
rm $EJECUTA
rm $TMPF
rm $TMPOK
rm $TMPIN