From 8d73ece3f5bbf3bba2e7200143f1237fd5a53332 Mon Sep 17 00:00:00 2001
From: lpaucot_uclouvain <laurent.paucot@student.uclouvain.be>
Date: Wed, 18 Mar 2020 18:09:01 +0100
Subject: [PATCH] =?UTF-8?q?Test=20file=20ajout=C3=A9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 expected_output.txt |  3 +++
 input.txt           |  3 +++
 run.c               |  6 +++---
 test.c              | 38 +++++++++++++++++++++++++++++++++++++-
 4 files changed, 46 insertions(+), 4 deletions(-)
 create mode 100644 expected_output.txt
 create mode 100644 input.txt

diff --git a/expected_output.txt b/expected_output.txt
new file mode 100644
index 0000000..a3342e9
--- /dev/null
+++ b/expected_output.txt
@@ -0,0 +1,3 @@
+20414363521583006011 283 72135560146936417
+13
+100 2 5
diff --git a/input.txt b/input.txt
new file mode 100644
index 0000000..722daca
--- /dev/null
+++ b/input.txt
@@ -0,0 +1,3 @@
+20414363521583006011
+13
+100
diff --git a/run.c b/run.c
index b76eb5f..3f8fa05 100644
--- a/run.c
+++ b/run.c
@@ -52,7 +52,7 @@ int* prime_divs(int number){
         
     }
     result[j] = -1;
-    free(ptr);
+    //free(ptr);
     return result;
 
 }
@@ -75,7 +75,7 @@ int run (char *input,char *output){
     FILE *file1 = NULL;
     FILE *file2 = NULL;
 
-    char chaine[15];
+    char chaine[50];
 
     file1 = fopen(input,"r");
     if (file1 == NULL){return -1;}
@@ -86,7 +86,7 @@ int run (char *input,char *output){
         return -1;
     }
 
-    while (fgets(chaine,15,file1) != NULL){
+    while (fgets(chaine,50,file1) != NULL){
 
         int *pr_divs = prime_divs(atoi(chaine));
         fprintf(file2,"%s ",chaine);
diff --git a/test.c b/test.c
index 53ba9c0..2912045 100644
--- a/test.c
+++ b/test.c
@@ -17,6 +17,41 @@ void test_is_not_prime(void){
     CU_ASSERT_FALSE(is_prime(14));
 }
 
+void file_test(void){
+    FILE *file1 = NULL;
+    FILE *file2 = NULL;
+
+    file1 = fopen("expected_output.txt","r");
+    if (file1 == NULL){
+        CU_FAIL("expected_output opening fail");
+        return;
+    }
+
+    int err = run("input.txt","actual_output.txt");
+    if (err == -1){
+        CU_FAIL("method run failed");
+        return;
+    }
+
+    file2 = fopen("actual_output.txt","r");
+        if (file2 == NULL){
+        CU_FAIL("actual_output opening fail");
+        return;
+        }
+
+    char chaine1[500];
+    char chaine2[500];
+
+    while (fgets(chaine1,500,file1) != NULL && fgets(chaine2,500,file2) != NULL)
+    {
+        CU_ASSERT_STRING_EQUAL(chaine1,chaine2);
+    }
+
+    fclose(file1);
+    fclose(file2);
+    
+}
+
 int setup(void){
         return 0;
     }
@@ -46,7 +81,8 @@ int main(){
 
     if (NULL == CU_add_test(pSuite,"test_is_div",test_is_div) ||
         NULL == CU_add_test(pSuite, "test_is_prime",test_is_prime) ||
-        NULL == CU_add_test(pSuite, "test_is_not_prime",test_is_not_prime))
+        NULL == CU_add_test(pSuite, "test_is_not_prime",test_is_not_prime)) 
+        //|| NULL == CU_add_test(pSuite,"file_test",file_test))
     {
         CU_cleanup_registry();
         return CU_get_error();
-- 
GitLab