Browse Source

Minor changes to the README, mainwindow.cpp, pro, main.cpp for the unit tests

Rafael Arce Nazario 8 years ago
parent
commit
182b877583
4 changed files with 12 additions and 56 deletions
  1. 6
    6
      README.md
  2. 2
    0
      Testing.pro
  3. 3
    49
      UnitTests/main.cpp
  4. 1
    1
      mainwindow.cpp

+ 6
- 6
README.md View File

@@ -301,19 +301,19 @@ Este ejercicio **NO requiere programación**, debes hacer las pruebas **sin mira
301 301
 
302 302
 ###Ejercicio 3: Usar `assert` para realizar pruebas unitarias
303 303
 
304
-Hacer pruebas "a mano" cada vez que corres un programa es una tarea que resulta "cansona" bien rápido. En los ejercicios anteriores lo hiciste para unas pocas funciones simples. !Imagínate hacer lo mismo para un programa complejo completo como un buscador o un procesador de palabras!
304
+Hacer pruebas "a mano" cada vez que corres un programa es una tarea que resulta "cansona" bien rápido. En los ejercicios anteriores lo hiciste para unas pocas funciones simples. ¡Imagínate hacer lo mismo para un programa complejo completo como un navegador o un procesador de palabras!
305 305
 
306 306
 Las *pruebas unitarias* ayudan a los programadores a validar códigos y simplificar el proceso de depuración ("debugging") a la vez que evitan la tarea tediosa de hacer pruebas a mano en cada ejecución.
307 307
 
308 308
 ####Instrucciones:
309 309
 
310
-1. En el menú de QT, ve a `Build` y selecciona `Clean Project "Testing"`.
310
+1. En el menú de QtCreator, ve a `Build` y selecciona `Clean Project "Testing"`. Luego ve a `File` y selecciona `Close Project "Testing"`.
311 311
 
312
-2. Carga a Qt el proyecto `UnitTests`  haciendo doble "click" en el archivo `UnitTests.pro` en el directorio `Documents/eip/Testing` de tu computadora. También puedes ir a `http://bitbucket.org/eip-uprrp/testing` para descargar la carpeta `Testing` a tu computadora.
312
+2. Carga a QtCreator el proyecto `UnitTests` haciendo doble "click" en el archivo `UnitTests.pro` en el directorio `Documents/eip/Testing/UnitTests` de tu computadora. Si descargaste el directorio `Testing` a tu computadora durante el ejercicio 2, el directorio `UnitTests` estará bajo ese directorio.
313 313
 
314 314
 3. El proyecto solo contiene el archivo de código fuente `main.cpp`. Este archivo contiene cuatro funciones: `fact`, `isALetter`, `isValidTime`, y `gcd`, cuyos resultados son solo parcialmente correctos. 
315 315
 
316
-  Estudia la descripción de  cada una de las funciones que aparece como comentarios antes el código de la función para saber la tarea que se espera haga la función.
316
+  Estudia la documentación de cada función (los comentarios que aparecen previo a cada función) para que comprendas la tarea que se espera que haga cada función.
317 317
 
318 318
   Tu tarea es escribir pruebas unitarias para cada una de las funciones para identificar los resultados erróneos. ** No necesitas reescribir las funciones para corregirlas. **
319 319
 
@@ -669,9 +669,9 @@ Doing tests by hand each time you run a program is a tiresome task. In the previ
669 669
 
670 670
 ####Instructions:
671 671
 
672
-1. In the Qt menu, go to `Build` and select `Clean Project "Testing"`.
672
+1. In the QtCreator menu, go to `Build` and select `Clean Project "Testing"`. Then go to `File` and select `Close Project "Testing"`.
673 673
 
674
-2. Load the `UnitTests` project onto Qt by double clicking the `UnitTests.pro` file in the `Documents/eip/Testing` directory on your computer. You can also go to `http://bitbucket.org/eip-uprrp/testing` to download the `Testing` folder on your computer.
674
+2. Load the `UnitTests` project onto QtCreator by double clicking the `UnitTests.pro` file in the `Documents/eip/Testing` directory on your computer. If you downloaded the `Testing` directory in Exercise 2, the  `UnitTests` directory should inside `Testing`.
675 675
 
676 676
 3. The project only contains the source code file `main.cpp`. This file contains four functions: `fact`, `isALetter`, `isValidTime`, and `gcd`, whose results are only partially correct.
677 677
 

+ 2
- 0
Testing.pro View File

@@ -25,3 +25,5 @@ FORMS    += mainwindow.ui
25 25
 
26 26
 RESOURCES += \
27 27
     images.qrc
28
+
29
+DEFINES     += QT_NO_DEBUG_OUTPUT

+ 3
- 49
UnitTests/main.cpp View File

@@ -12,7 +12,7 @@ unsigned int fact(unsigned int n) {
12 12
 
13 13
     int result = 1;
14 14
 
15
-    for (int i = 1; i < n; i++)
15
+    for (unsigned int i = 1; i < n; i++)
16 16
         result = result * i;
17 17
 
18 18
     return result;
@@ -71,60 +71,14 @@ void test_fact() {
71 71
 }
72 72
 
73 73
 //
74
-// EXERCISE 3
74
+// EXERCISE 3: Write your test functions here!!!
75 75
 //
76 76
 
77 77
 
78
-//
79
-// Function test_isALetter():
80
-// This function is provided as an example unit test for the isALetter() function.
81
-//
82
-
83
-void test_isALetter() {
84
-    assert( isALetter('a') );
85
-    assert( isALetter('Z'));
86
-    assert( isALetter('2')==0);
87
-    assert( isALetter('$')==0);
88
-    assert( isALetter('^')==0);
89
-    cout << "Function isALetter() passed all the tests!!" << endl;
90
-}
91
-
92
-//
93
-// Function test_isValidTime():
94
-// This function is provided as an example unit test for the isValidTime() function.
95
-//
96
-
97
-void test_isValidTime() {
98
-    assert( isValidTime(0002) );
99
-    assert( isValidTime(1234) );
100
-    assert( isValidTime(4800)==0 );
101
-    assert( isValidTime(1278)==0 );
102
-    cout << "Function isValidTime() passed all the tests!!" << endl;
103
-}
104
-
105
-//
106
-// Function test_gcd():
107
-// This function is provided as an example unit test for the gcd() function.
108
-//
109
-
110
-void test_gcd() {
111
-    assert( gcd(1,1)==1 );
112
-    assert( gcd(2,2)==2 );
113
-    assert( gcd(3,2)==1 );
114
-    assert( gcd(12,9)==3 );
115
-    assert( gcd(12,6)==6 );
116
-    cout << "Function gcd() passed all the tests!!" << endl;
117
-}
118
-
119
-
120
-
121 78
 int main()
122 79
 {
123 80
     cout << "Go ahead and test!\n";
124 81
     test_fact();
125
- // test_gcd();
126
- // test_isALetter();
127
- // test_isValidTime();
128
-    
82
+ 
129 83
     return 0;
130 84
 }

+ 1
- 1
mainwindow.cpp View File

@@ -378,7 +378,7 @@ void MainWindow::RPSs(){
378 378
 #include <QTimer>
379 379
 
380 380
 void MainWindow::paintDice() {
381
-    qDebug() << this->timerCounter++;
381
+    this->timerCounter++;
382 382
     int a, b;
383 383
     a = rand()%6;
384 384
     b = rand()%6;