]> git.xolatile.top Git - soikk-pearson_verify.git/commitdiff
Fixed bug with file2. Changed error behaviour. Updated README to reflect change.
authorSoikk <enriquedelacalhacar@gmail.com>
Sun, 20 Oct 2024 20:36:49 +0000 (22:36 +0200)
committerSoikk <enriquedelacalhacar@gmail.com>
Sun, 20 Oct 2024 20:36:49 +0000 (22:36 +0200)
README.md
verify.c

index 11c823e231e38e0e490190392167c8ac9ace24a7..d9ad8dbabc5af5327e6d6ba887931fb790c6b31c 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
 # Pearson verify
 This program is meant to be used to verify the ouput of the pearson section of [dv1674_a2](https://github.com/sm13294/dv1674_a2).\
 \
-This program compares 64 bit floating point numbers stored in a separate line each from \<file1\> and \<file2\>. If all the pairs of numbers are the same up to the 15th decimal place, 0 will be returned. If not, this program will check if all numbers are the same up to the 11th decimal place, and if so 1 will be returned. If [stop] is 1, this program will stop as soon as this happens. If any numbers are not the same up to the 11th decimal place, 2 will be returned. If [stop] is 2, this program will stop as soon as this happens. If there is an error while executing this program, -1 will be returned.
+This program compares 64 bit floating point numbers stored in a separate line each from \<file1\> and \<file2\>. If all the pairs of numbers are the same up to the 15th decimal place, 0 will be returned. If not, this program will check if all numbers are the same up to the 11th decimal place, and if so 1 will be returned. If [stop] is 1, this program will stop as soon as this happens. If any numbers are not the same up to the 11th decimal place, 2 will be returned. If [stop] is 2, this program will stop as soon as this happens. If there is an error while executing this program, -1 will be returned, unless the error lies within the files' structures, in which case 2 will be returned, as it means there was a significant difference in the outputs. Compile with -DDEBUG (make debug) or define DEBUG in the program to print debug information.
index b2bdd912db7c535636a8ca443788a8a7d1272925..29bdf905f9082ff257fb36fda71be35b2d18b3ee 100644 (file)
--- a/verify.c
+++ b/verify.c
@@ -8,7 +8,7 @@
 
 int main(int argc, char *argv[]){
 
-       int ret = 0;
+       int ret = -1;
        int stop = 0;
        FILE *f1 = NULL;
        FILE *f2 = NULL;
@@ -26,10 +26,13 @@ int main(int argc, char *argv[]){
                        "\tas this happens. If any numbers are not the same up to the 11th decimal\n"
                        "\tplace, 2 will be returned. If [stop] is 2, this program will stop as soon\n"
                        "\tas this happens. If there is an error while executing this program, -1 will\n"
-                       "\tbe returned. Compile with -DDEBUG (make debug) or define DEBUG in the program\n"
+                       "\tbe returned, unless the error lies within the files' structures, in which\n"
+                       "\tcase 2 will be returned, as it means there was a significant difference in\n"
+                       "\tthe outputs. Compile with -DDEBUG (make debug) or define DEBUG in the program\n"
                        "\tto print debug information.\n"
                );
-               return -1;
+               ret = -1;
+               goto end;
        }
 
        if(argc > 3){
@@ -39,12 +42,14 @@ int main(int argc, char *argv[]){
        f1 = fopen(argv[1], "rb");
        if(!f1){
                fprintf(stderr, "ERROR: Cannot open file '%s'.\n", argv[1]);
-               return -1;
+               ret = -1;
+               goto end;
        }
        f2 = fopen(argv[2], "rb");
-       if(!f1){
+       if(!f2){
                fprintf(stderr, "ERROR: Cannot open file '%s'.\n", argv[2]);
-               return -1;
+               ret = -1;
+               goto end;
        }
 
        while(!feof(f1) && !feof(f2)){
@@ -52,11 +57,13 @@ int main(int argc, char *argv[]){
        
                if(fscanf(f1, "%lg\n", &d1) != 1){
                        fprintf(stderr, "ERROR: Cannot read number from file '%s' at line %lu.\n", argv[1], line);
-                       return -1;
+                       ret = 2;
+                       goto close_end;
                }
                if(fscanf(f2, "%lg\n", &d2) != 1){
                        fprintf(stderr, "ERROR: Cannot read number from file '%s' at line %lu.\n", argv[1], line);
-                       return -1;
+                       ret = 2;
+                       goto close_end;
                }
                
                double error = fabs(d1-d2);
@@ -67,7 +74,7 @@ int main(int argc, char *argv[]){
                                ret = 2;
                        }
                        if(stop > 0 && stop == ret){
-                               goto end;
+                               goto close_end;
                        }
                }
                line++;
@@ -75,13 +82,14 @@ int main(int argc, char *argv[]){
 
        if((feof(f1) && !feof(f2)) || (!feof(f1) && feof(f2))){
                fprintf(stderr, "ERROR: Different number of lines in files '%s' and '%s'.\n", argv[1], argv[2]);
-               return -1;
+               ret = 2;
        }
 
-end:
+close_end:
        fclose(f1);
        fclose(f2);
 
+end:
 #ifdef DEBUG
        printf("%lu lines read\n", line);
        printf("Return value: %d\n", ret);