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));
}
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
void empty_file_test(void){
FILE *file1 = NULL;
int err = run("Test_files/empty_input.txt","actual_output.txt");
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");
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[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);
}
void file_test(void){
FILE *file1 = NULL;
FILE *file2 = NULL;
if (file1 == NULL){
CU_FAIL("expected_output opening fail");
return;
}
int err = run("Test_files/input.txt","actual_output.txt");
end = clock();
time = (double) (end - start) / CLOCKS_PER_SEC;
printf("Temps = %.2f secondes \n",time);
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;
}
int n = 0;
while (fgets(chaine2,50,file2) != NULL)
//printf("%s\n",chaine1);
//printf("%s\n",chaine2);
int main(){
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",file_test))