diff --git a/expected_output.txt b/expected_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..a3342e971d9487b1c9af1d933444ab5f94543b2f --- /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 0000000000000000000000000000000000000000..722dacaa2200416b6a6b91007100bd52bd94477d --- /dev/null +++ b/input.txt @@ -0,0 +1,3 @@ +20414363521583006011 +13 +100 diff --git a/run.c b/run.c index b76eb5fa9425d02bd8dec53952405ac3f4152960..3f8fa053e2edc6e4c32f64cdd7b062c89a95c97b 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 53ba9c08ff76a9bc2e305ee5b2a98e302b1003e3..2912045aa3cacdb3e995db8844e7ef9ef965940c 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();