add count of how many tests pass and fail

This commit is contained in:
Chris Cromer 2018-11-11 18:45:53 -03:00
parent 02a0926252
commit 16cf47155e
Signed by: cromer
GPG Key ID: 39CC813FF3C8708A

View File

@ -1,3 +1,18 @@
/*
* Copyright 2018 Christopher Cromer
* Copyright 2018 Rodolfo Cuevas
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -35,6 +50,9 @@ int main(int argc, char **argv) {
int n = 50000;
int i;
int gen;
int pass = 1;
int passed = 0;
int failed = 0;
test_case = malloc(sizeof(int) * n);
qarray = malloc(sizeof(int) * n);
@ -49,12 +67,17 @@ int main(int argc, char **argv) {
fflush(stdout);
for (i = 0; i < 5000000; i++) {
gen = gen_rand(-1000, 1000);
if (gen < -1000 || gen > 1000) {
if ((gen < -1000 || gen > 1000) && pass) {
fprintf(stdout, "fail\n");
return 1;
failed++;
pass = 0;
}
}
fprintf(stdout, "pass\n");
if (pass) {
fprintf(stdout, "pass\n");
passed++;
}
pass = 1;
// Prepare for sort tests
for (i = 0; i < n; i++) {
@ -69,12 +92,25 @@ int main(int argc, char **argv) {
fflush(stdout);
bubble_sort(test_array, n);
for (i = 0; i < n; i++) {
if (test_array[i] != qarray[i]) {
if (test_array[i] != qarray[i] && pass) {
fprintf(stdout, "fail\n");
return 1;
failed++;
pass = 0;
}
}
fprintf(stdout, "pass\n");
if (pass) {
fprintf(stdout, "pass\n");
passed++;
}
pass = 1;
return 0;
fprintf(stdout, "%d tests passed\n", passed);
fprintf(stdout, "%d tests failed\n", failed);
if (failed == 0) {
return 0;
}
else {
return 1;
}
}