Newer
Older
#include "run.h"
#include <CUnit/CUnit.h>
#include <CUnit/TestRun.h>
#include <CUnit/CUError.h>
void test_is_div(void){
CU_ASSERT_TRUE(is_div(14,7));
}
void test_is_prime(void){
CU_ASSERT_TRUE(is_prime(13));
}
void test_is_not_prime(void){
CU_ASSERT_FALSE(is_prime(14));
}
int err = run("Test_files/empty_input.txt","actual_output.txt",4);
if (err == -1){
CU_FAIL("method run failed");
return;
}
file1 = fopen("actual_output.txt","r");
if (file1 == NULL){
CU_FAIL("actual_output opening fail");
return;
}
char chaine1[20];
CU_ASSERT_EQUAL(fgets(chaine1,20,file1),NULL);
fclose(file1);
}
void short_file_test(void){
FILE *file1 = NULL;
FILE *file2 = NULL;
file1 = fopen("Test_files/short_expected_output.txt","r");
if (file1 == NULL){
CU_FAIL("short_expected_output opening fail");
return;
}
int err = run("Test_files/short_input.txt","actual_output.txt",4);
file2 = fopen("actual_output.txt","r");
if (file2 == NULL){
CU_FAIL("actual_output opening fail");
return;
}
char chaine1[50];
char chaine2[50];
while (fgets(chaine1,50,file1) != NULL && fgets(chaine2,50,file2) != NULL)
{
//printf("%s\n",chaine1);
//printf("%s\n",chaine2);
CU_ASSERT_STRING_EQUAL(chaine1,chaine2);
}
fclose(file1);
fclose(file2);
}
if (file1 == NULL){
CU_FAIL("expected_output opening fail");
return;
}
int err = run("Test_files/input.txt","actual_output.txt",4);
end = clock();
time = (double) (end - start) / CLOCKS_PER_SEC;
printf("Temps pour 4 threads de calculs = %.2f secondes \n",time);
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
fclose(file1);
return;
}
file2 = fopen("actual_output.txt","r");
if (file2 == NULL){
CU_FAIL("actual_output opening fail");
fclose(file1);
return;
}
char chaine2[50];
int n = 0;
while (fgets(chaine2,50,file2) != NULL)
{
n++;
}
CU_ASSERT_EQUAL(n,100);
fclose(file1);
fclose(file2);
}
void file_test_N_1(void){
FILE *file1 = NULL;
FILE *file2 = NULL;
file1 = fopen("Test_files/expected_output.txt","r");
if (file1 == NULL){
CU_FAIL("expected_output opening fail");
clock_t start, end;
double time;
start = clock();
int err = run("Test_files/input.txt","actual_output.txt",1);
end = clock();
time = (double) (end - start) / CLOCKS_PER_SEC;
printf("Temps pour 1 thread de calcul = %.2f secondes \n",time);
if (err == -1){
CU_FAIL("method run failed");
fclose(file1);
return;
}
if (file2 == NULL){
CU_FAIL("actual_output opening fail");
int n = 0;
while (fgets(chaine2,50,file2) != NULL)
if (CUE_SUCCESS != CU_initialize_registry())
{
return CU_get_error();
}
if (NULL == pSuite)
{
CU_cleanup_registry();
return CU_get_error();
}
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,"empty_file_test",empty_file_test) ||
NULL == CU_add_test(pSuite,"short_file_test",short_file_test) ||
NULL == CU_add_test(pSuite,"file_test : N = 4",file_test_N_4) ||
NULL == CU_add_test(pSuite,"file_test N = 1",file_test_N_1))
{
CU_cleanup_registry();
return CU_get_error();
}
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
CU_basic_show_failures(CU_get_failure_list());
}
else
{
if (argc == 5 && strcmp("-N",argv[1])==0){
int err = run(argv[3],argv[4],atoi(argv[2]));
if (err == -1){return EXIT_FAILURE;}
}
else
{
if (argc == 3){
int err = run(argv[1],argv[2],4);
if (err == -1){return EXIT_FAILURE;}
}
else{
printf("Invalid type of number of arguments, please try again with the right format\n");
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}
return EXIT_SUCCESS;