try to add assert_eq and bool tests

This commit is contained in:
2023-08-15 02:39:06 +02:00
parent 0a9337e675
commit 5c870ed113
13 changed files with 17321 additions and 27 deletions
+4461
View File
File diff suppressed because it is too large Load Diff
+11928
View File
File diff suppressed because it is too large Load Diff
BIN
View File
Binary file not shown.
+211
View File
@@ -0,0 +1,211 @@
In file included from ./src/permutation_t/permutation_t.h:5,
from src/permutation_t/permutation_t.c:1:
./src/set_theoric_t/set_theoric_t.h:13:18: warning: parameter names (without types) in function declaration
13 | typedef struct SET_THEORIC_##type SET_THEORIC_##type; \
| ^~~~~~~~~~~~
./src/set_theoric_t/set_theoric_t.h:17:1: note: in expansion of macro GENERATE_UNSIGNED_SET_THEORIC
17 | GENERATE_UNSIGNED_SET_THEORIC(TYPE_U_CHAR)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./src/set_theoric_t/set_theoric_t.h:13:18: warning: parameter names (without types) in function declaration
13 | typedef struct SET_THEORIC_##type SET_THEORIC_##type; \
| ^~~~~~~~~~~~
./src/set_theoric_t/set_theoric_t.h:18:1: note: in expansion of macro GENERATE_UNSIGNED_SET_THEORIC
18 | GENERATE_UNSIGNED_SET_THEORIC(TYPE_U_INT)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./src/set_theoric_t/set_theoric_t.h:13:18: warning: parameter names (without types) in function declaration
13 | typedef struct SET_THEORIC_##type SET_THEORIC_##type; \
| ^~~~~~~~~~~~
./src/set_theoric_t/set_theoric_t.h:19:1: note: in expansion of macro GENERATE_UNSIGNED_SET_THEORIC
19 | GENERATE_UNSIGNED_SET_THEORIC(TYPE_U_L_INT)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./src/set_theoric_t/set_theoric_t.h:13:18: warning: parameter names (without types) in function declaration
13 | typedef struct SET_THEORIC_##type SET_THEORIC_##type; \
| ^~~~~~~~~~~~
./src/set_theoric_t/set_theoric_t.h:20:1: note: in expansion of macro GENERATE_UNSIGNED_SET_THEORIC
20 | GENERATE_UNSIGNED_SET_THEORIC(TYPE_SIZE_T)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c: In function IS_PERMUTATION_TYPE_CHAR:
src/permutation_t/permutation_t.c:60:75: warning: passing argument 1 of TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_CHAR discards const qualifier from pointer target type [-Wdiscarded-qualifiers]
60 | PERMUTATION_TYPE_SIZE_T *t_p = TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(p);\
| ^
src/permutation_t/permutation_t.c:67:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
67 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_CHAR)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c:33:88: note: expected PERMUTATION_TYPE_CHAR * but argument is of type const PERMUTATION_TYPE_CHAR *
33 | PERMUTATION_TYPE_SIZE_T * TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(PERMUTATION_##type *p ){\
| ~~~~~~~~~~~~~~~~~~~~^
src/permutation_t/permutation_t.c:67:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
67 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_CHAR)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c: In function IS_PERMUTATION_TYPE_U_CHAR:
src/permutation_t/permutation_t.c:60:75: warning: passing argument 1 of TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_U_CHAR discards const qualifier from pointer target type [-Wdiscarded-qualifiers]
60 | PERMUTATION_TYPE_SIZE_T *t_p = TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(p);\
| ^
src/permutation_t/permutation_t.c:68:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
68 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_U_CHAR)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c:33:88: note: expected PERMUTATION_TYPE_U_CHAR * but argument is of type const PERMUTATION_TYPE_U_CHAR *
33 | PERMUTATION_TYPE_SIZE_T * TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(PERMUTATION_##type *p ){\
| ~~~~~~~~~~~~~~~~~~~~^
src/permutation_t/permutation_t.c:68:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
68 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_U_CHAR)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c: In function IS_PERMUTATION_TYPE_INT:
src/permutation_t/permutation_t.c:60:75: warning: passing argument 1 of TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_INT discards const qualifier from pointer target type [-Wdiscarded-qualifiers]
60 | PERMUTATION_TYPE_SIZE_T *t_p = TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(p);\
| ^
src/permutation_t/permutation_t.c:69:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
69 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_INT)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c:33:88: note: expected PERMUTATION_TYPE_INT * but argument is of type const PERMUTATION_TYPE_INT *
33 | PERMUTATION_TYPE_SIZE_T * TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(PERMUTATION_##type *p ){\
| ~~~~~~~~~~~~~~~~~~~~^
src/permutation_t/permutation_t.c:69:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
69 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_INT)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c: In function IS_PERMUTATION_TYPE_U_INT:
src/permutation_t/permutation_t.c:60:75: warning: passing argument 1 of TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_U_INT discards const qualifier from pointer target type [-Wdiscarded-qualifiers]
60 | PERMUTATION_TYPE_SIZE_T *t_p = TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(p);\
| ^
src/permutation_t/permutation_t.c:70:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
70 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_U_INT)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c:33:88: note: expected PERMUTATION_TYPE_U_INT * but argument is of type const PERMUTATION_TYPE_U_INT *
33 | PERMUTATION_TYPE_SIZE_T * TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(PERMUTATION_##type *p ){\
| ~~~~~~~~~~~~~~~~~~~~^
src/permutation_t/permutation_t.c:70:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
70 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_U_INT)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c: In function IS_PERMUTATION_TYPE_L_INT:
src/permutation_t/permutation_t.c:60:75: warning: passing argument 1 of TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_L_INT discards const qualifier from pointer target type [-Wdiscarded-qualifiers]
60 | PERMUTATION_TYPE_SIZE_T *t_p = TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(p);\
| ^
src/permutation_t/permutation_t.c:71:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
71 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_L_INT)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c:33:88: note: expected PERMUTATION_TYPE_L_INT * but argument is of type const PERMUTATION_TYPE_L_INT *
33 | PERMUTATION_TYPE_SIZE_T * TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(PERMUTATION_##type *p ){\
| ~~~~~~~~~~~~~~~~~~~~^
src/permutation_t/permutation_t.c:71:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
71 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_L_INT)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c: In function IS_PERMUTATION_TYPE_U_L_INT:
src/permutation_t/permutation_t.c:60:75: warning: passing argument 1 of TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_U_L_INT discards const qualifier from pointer target type [-Wdiscarded-qualifiers]
60 | PERMUTATION_TYPE_SIZE_T *t_p = TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(p);\
| ^
src/permutation_t/permutation_t.c:72:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
72 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_U_L_INT)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c:33:88: note: expected PERMUTATION_TYPE_U_L_INT * but argument is of type const PERMUTATION_TYPE_U_L_INT *
33 | PERMUTATION_TYPE_SIZE_T * TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(PERMUTATION_##type *p ){\
| ~~~~~~~~~~~~~~~~~~~~^
src/permutation_t/permutation_t.c:72:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
72 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_U_L_INT)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c: In function IS_PERMUTATION_TYPE_SIZE_T:
src/permutation_t/permutation_t.c:60:75: warning: passing argument 1 of TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_SIZE_T discards const qualifier from pointer target type [-Wdiscarded-qualifiers]
60 | PERMUTATION_TYPE_SIZE_T *t_p = TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(p);\
| ^
src/permutation_t/permutation_t.c:73:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
73 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_SIZE_T)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c:33:88: note: expected PERMUTATION_TYPE_SIZE_T * but argument is of type const PERMUTATION_TYPE_SIZE_T *
33 | PERMUTATION_TYPE_SIZE_T * TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(PERMUTATION_##type *p ){\
| ~~~~~~~~~~~~~~~~~~~~^
src/permutation_t/permutation_t.c:73:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
73 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_SIZE_T)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c: In function IS_PERMUTATION_TYPE_FLOAT:
src/permutation_t/permutation_t.c:60:75: warning: passing argument 1 of TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_FLOAT discards const qualifier from pointer target type [-Wdiscarded-qualifiers]
60 | PERMUTATION_TYPE_SIZE_T *t_p = TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(p);\
| ^
src/permutation_t/permutation_t.c:74:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
74 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_FLOAT)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c:33:88: note: expected PERMUTATION_TYPE_FLOAT * but argument is of type const PERMUTATION_TYPE_FLOAT *
33 | PERMUTATION_TYPE_SIZE_T * TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(PERMUTATION_##type *p ){\
| ~~~~~~~~~~~~~~~~~~~~^
src/permutation_t/permutation_t.c:74:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
74 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_FLOAT)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c: In function IS_PERMUTATION_TYPE_DOUBLE:
src/permutation_t/permutation_t.c:60:75: warning: passing argument 1 of TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_DOUBLE discards const qualifier from pointer target type [-Wdiscarded-qualifiers]
60 | PERMUTATION_TYPE_SIZE_T *t_p = TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(p);\
| ^
src/permutation_t/permutation_t.c:75:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
75 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_DOUBLE)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c:33:88: note: expected PERMUTATION_TYPE_DOUBLE * but argument is of type const PERMUTATION_TYPE_DOUBLE *
33 | PERMUTATION_TYPE_SIZE_T * TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(PERMUTATION_##type *p ){\
| ~~~~~~~~~~~~~~~~~~~~^
src/permutation_t/permutation_t.c:75:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
75 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_DOUBLE)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c: In function IS_PERMUTATION_TYPE_L_DOUBLE:
src/permutation_t/permutation_t.c:60:75: warning: passing argument 1 of TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_L_DOUBLE discards const qualifier from pointer target type [-Wdiscarded-qualifiers]
60 | PERMUTATION_TYPE_SIZE_T *t_p = TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(p);\
| ^
src/permutation_t/permutation_t.c:76:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
76 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_L_DOUBLE)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c:33:88: note: expected PERMUTATION_TYPE_L_DOUBLE * but argument is of type const PERMUTATION_TYPE_L_DOUBLE *
33 | PERMUTATION_TYPE_SIZE_T * TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(PERMUTATION_##type *p ){\
| ~~~~~~~~~~~~~~~~~~~~^
src/permutation_t/permutation_t.c:76:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
76 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_L_DOUBLE)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c: In function TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_STRING:
src/permutation_t/permutation_t.c:39:37: warning: passing argument 2 of COPY_ARRAY_TYPE_STRING from incompatible pointer type [-Wincompatible-pointer-types]
39 | COPY_ARRAY_##type(sorted_perm, p->perm, size);\
| ~^~~~~~
| |
| char **
src/permutation_t/permutation_t.c:77:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
77 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_STRING)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ./src/permutation_t/permutation_t.h:4,
from src/permutation_t/permutation_t.c:1:
./src/tools_t/tools_t.h:29:49: note: expected const char ** but argument is of type char **
29 | void COPY_ARRAY_##type(type* dst, const type* src, size_t size);\
| ~~~~~~~~~~~~^~~
./src/tools_t/tools_t.h:46:1: note: in expansion of macro GENERATE_ALL
46 | GENERATE_ALL(TYPE_STRING)
| ^~~~~~~~~~~~
src/permutation_t/permutation_t.c: In function IS_PERMUTATION_TYPE_STRING:
src/permutation_t/permutation_t.c:60:75: warning: passing argument 1 of TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_STRING discards const qualifier from pointer target type [-Wdiscarded-qualifiers]
60 | PERMUTATION_TYPE_SIZE_T *t_p = TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(p);\
| ^
src/permutation_t/permutation_t.c:77:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
77 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_STRING)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/permutation_t/permutation_t.c:33:88: note: expected PERMUTATION_TYPE_STRING * but argument is of type const PERMUTATION_TYPE_STRING *
33 | PERMUTATION_TYPE_SIZE_T * TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(PERMUTATION_##type *p ){\
| ~~~~~~~~~~~~~~~~~~~~^
src/permutation_t/permutation_t.c:77:1: note: in expansion of macro GENERATE_PERMUTATION_FUNCTIONS
77 | GENERATE_PERMUTATION_FUNCTIONS(TYPE_STRING)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/set_theoric_t/set_theoric_t.c:2:
./src/set_theoric_t/set_theoric_t.h:13:18: warning: parameter names (without types) in function declaration
13 | typedef struct SET_THEORIC_##type SET_THEORIC_##type; \
| ^~~~~~~~~~~~
./src/set_theoric_t/set_theoric_t.h:17:1: note: in expansion of macro GENERATE_UNSIGNED_SET_THEORIC
17 | GENERATE_UNSIGNED_SET_THEORIC(TYPE_U_CHAR)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./src/set_theoric_t/set_theoric_t.h:13:18: warning: parameter names (without types) in function declaration
13 | typedef struct SET_THEORIC_##type SET_THEORIC_##type; \
| ^~~~~~~~~~~~
./src/set_theoric_t/set_theoric_t.h:18:1: note: in expansion of macro GENERATE_UNSIGNED_SET_THEORIC
18 | GENERATE_UNSIGNED_SET_THEORIC(TYPE_U_INT)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./src/set_theoric_t/set_theoric_t.h:13:18: warning: parameter names (without types) in function declaration
13 | typedef struct SET_THEORIC_##type SET_THEORIC_##type; \
| ^~~~~~~~~~~~
./src/set_theoric_t/set_theoric_t.h:19:1: note: in expansion of macro GENERATE_UNSIGNED_SET_THEORIC
19 | GENERATE_UNSIGNED_SET_THEORIC(TYPE_U_L_INT)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./src/set_theoric_t/set_theoric_t.h:13:18: warning: parameter names (without types) in function declaration
13 | typedef struct SET_THEORIC_##type SET_THEORIC_##type; \
| ^~~~~~~~~~~~
./src/set_theoric_t/set_theoric_t.h:20:1: note: in expansion of macro GENERATE_UNSIGNED_SET_THEORIC
20 | GENERATE_UNSIGNED_SET_THEORIC(TYPE_SIZE_T)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+10 -7
View File
@@ -1,22 +1,25 @@
#include "src/set_theoric_t/set_theoric_t.h" #include "src/set_theoric_t/set_theoric_t.h"
#define GENERATE_UNSIGNED_SET_THEORIC(type)\ #define GENERATE_SET_THEORIC(type) \
SET_THEORIC_##type * CREATE_SET_THEORIC_##type(size_t id){ \ SET_THEORIC_##type * CREATE_SET_THEORIC_##type(size_t id){ \
if(id == 0) return NULL; \ if(id == 0) return NULL; \
SET_THEORIC_##type *ret_set = malloc(sizeof(SET_THEORIC_##type)); \ SET_THEORIC_##type *ret_set = malloc(sizeof(SET_THEORIC_##type)); \
ret_set->id = id; \ ret_set->id = id; \
ret_set->set = malloc(id*sizeof(type)); \ ret_set->set = malloc(id*sizeof(type)); \
for(type i = 0; i < id; ++i) ret_set->set[i]=i; \ for(type i = 0; i < id; ++i) ret_set->set[i]=i; \
return ret_set; }\ return ret_set; \
} \
\ \
bool IS_SET_THEORIC_##type(SET_THEORIC_##type *st){ \ bool IS_SET_THEORIC_##type(SET_THEORIC_##type *st){ \
for(type i = 0; i < st->id; ++i){ \ for(type i = 0; i < st->id; ++i){ \
if(st->set[i] != i) return false; \ if(st->set[i] != i) return false; \
return true; } }\ return true; \
} \
} \
GENERATE_UNSIGNED_SET_THEORIC(TYPE_U_CHAR) GENERATE_SET_THEORIC(TYPE_U_CHAR)
GENERATE_UNSIGNED_SET_THEORIC(TYPE_U_INT) GENERATE_SET_THEORIC(TYPE_U_INT)
GENERATE_UNSIGNED_SET_THEORIC(TYPE_U_L_INT) GENERATE_SET_THEORIC(TYPE_U_L_INT)
GENERATE_UNSIGNED_SET_THEORIC(TYPE_SIZE_T) GENERATE_SET_THEORIC(TYPE_SIZE_T)
+2 -1
View File
@@ -8,7 +8,8 @@
#define GENERATE_UNSIGNED_SET_THEORIC(type) \ #define GENERATE_UNSIGNED_SET_THEORIC(type) \
struct SET_THEORIC_##type{ \ struct SET_THEORIC_##type{ \
type id; \ type id; \
type *set;};\ type *set; \
}; \
typedef struct SET_THEORIC_##type SET_THEORIC_##type; \ typedef struct SET_THEORIC_##type SET_THEORIC_##type; \
SET_THEORIC_##type * CREATE_SET_THEORIC_##type(TYPE_##type); \ SET_THEORIC_##type * CREATE_SET_THEORIC_##type(TYPE_##type); \
bool IS_SET_THEORIC_##type(SET_THEORIC_##type *st); \ bool IS_SET_THEORIC_##type(SET_THEORIC_##type *st); \
+66 -2
View File
@@ -1,13 +1,77 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h>
#include "src/permutation_t/permutation_t.h" #include "src/test_t/test_t.h"
//#include "src/permutation_t/permutation_t.h"
TEST(size_permutation2){
printf("another size_permutation2 again\n");
ASSERT_TRUE(false);
}
int main(){ TEST(size_permutation)
{
/*
PERMUTATION_TYPE_CHAR *p = CREATE_PERMUTATION_TYPE_CHAR(3); PERMUTATION_TYPE_CHAR *p = CREATE_PERMUTATION_TYPE_CHAR(3);
printf(" size = %u \n",p->size); printf(" size = %u \n",p->size);
if(p->size == 3) print_OK_with_msg_endl(" FF yeah GOOD test size passed ");
else print_KO_with_msg_endl("NOT GOOD test size not passed ");
*/
printf("test size_permutation2\n");
}
TEST(size_permutation2){
printf("another size_permutation2 again false\n");
bool val_bool = false;
ASSERT_TRUE(val_bool);
}
TEST(size_permutation2)
{
printf("test size_permutation2\n");
bool val_bool = true;
ASSERT_FALSE(val_bool);
/*
PERMUTATION_TYPE_CHAR *p = CREATE_PERMUTATION_TYPE_CHAR(3);
printf(" size = %u \n",p->size);
if(p->size == 3) print_OK_with_msg_endl(" FF yeah GOOD test size passed ");
else print_KO_with_msg_endl("NOT GOOD test size not passed ");
*/
}
TEST(size_permutation2){
printf("another size_permutation2 float\n");
ASSERT_TRUE(true);
float a = 1.1;
float b = 1.1;
ASSERT_EQ_TYPE_FLOAT(a,b);
b=1.10001;
ASSERT_EQ_TYPE_FLOAT(a,b);
ASSERT_EQ_TYPE_FLOAT(1.2,b);
}
TEST(){
unsigned char c = 'a';
printf("another size_permutation2, a = %c\n",c);
ASSERT_FALSE(true);
ASSERT_TRUE(true);
ASSERT_TRUE(true);
}
//END_TEST(size_permutation)
//INIT()
int main(){
//p_fonction_l=malloc(sizeof(p_fonction_l));
//init_test();
run_all_tests();
//run_some_tests(8, 1, 2, 2, 3, 3, 0, 4, 1);
//run_some_tests(8, 5, 7, 1, 1, 1, 1, 1, 1);
//run_some_tests_one_by_one(3, 1, 2, 2);
//run_all_tests_exept(2, 1, 3);
return 0; return 0;
} }
+310
View File
@@ -0,0 +1,310 @@
#include "src/test_t/test_t.h"
#define DEFAULT_K "\033[0m" //Resets the text to default color
#define GREEN_K "\033[0;32m"
#define RED_K "\033[0;31m"
#define HK_EQ "[==========]"
#define HK_TR "[----------]"
#define HK_RN "[RUN ]"
#define HK_DN "[ DONE]"
#define HK_OK "[ OK ]"
#define HK_FL "[ FAILED ]"
#define INCR_PASS_CNT ++count_passed; ++count_passed_local;
#define INCR_FAIL_CNT ++count_failed; ++count_failed_local;
struct failed_lists{
char *name;
struct failed_lists *next;
} *failed_l = NULL;
void append_failed_list(const char *name_failed){
static struct failed_lists *failed_static = NULL;
if(failed_static == NULL){
failed_l = malloc(sizeof(struct failed_lists));
failed_l->name = malloc(strlen(name_failed));
strcpy(failed_l->name, name_failed);
failed_l->next = NULL;
failed_static = failed_l;
}
else{
struct failed_lists *tmp = malloc(sizeof(struct failed_lists));
tmp->name = malloc(strlen(name_failed));
strcpy(tmp->name, name_failed);
tmp->next = NULL;
failed_static->next = tmp;
failed_static = tmp;
}
}
size_t count_tests = 0;
size_t count_passed = 0;
size_t count_passed_local = 0;
size_t count_failed = 0;
size_t count_failed_local = 0;
struct func f_beging;
void vprintf_colored(char *color, char *format, ...) {
va_list args;
printf("%s",color);
va_start(args, format);
vprintf(format, args);
va_end(args);
printf(DEFAULT_K);
}
void printHK_color(char *color, char *HK, char * format, ...){
printf("%s%s%s",color, HK, DEFAULT_K);
va_list args;
va_start(args, format);
vprintf(format, args);
va_end(args);
}
#define ASSERT_EXPECT_FROM(expect, not_expect) \
bool assert_##expect##_from(bool val, const char * var_name, const char *func_name){ \
if(val == expect) { \
INCR_PASS_CNT; \
printHK_color(GREEN_K,HK_TR," 1 test passed from %s \n\n",func_name); \
return true; \
}else { \
INCR_FAIL_CNT; \
printHK_color(RED_K,HK_TR," 1 test failed from %s \n",func_name); \
append_failed_list(func_name); \
printf("Value of: %s\nActual: %s\nExpected: %s\n\n",#not_expect, #expect, var_name); \
return false; \
} \
}
ASSERT_EXPECT_FROM(true,false)
ASSERT_EXPECT_FROM(false,true)
#define ASSERT_EQ_TYPE(type)\
bool assert_eq_##type(type var1, type var2, \
const char *var1_name, const char *var2_name, const char *func_name){ \
if(COMPARE_N_##type(&var1, &var2) == 0){ \
INCR_PASS_CNT; \
printHK_color(GREEN_K,HK_TR," 1 test passed from %s \n\n",func_name); \
return true; \
}else { \
INCR_FAIL_CNT; \
printHK_color(RED_K,HK_TR," 1 test failed from %s \n",func_name); \
append_failed_list(func_name); \
printf("Expected equality of these values:\n %s\n\tWhich is: %s\n %s\n\tWhich is: %s\n\n"\
,var1_name, type##_TO_STR(var1), var2_name, type##_TO_STR(var1)); \
return false; \
} \
}
ASSERT_EQ_TYPE(TYPE_CHAR)
ASSERT_EQ_TYPE(TYPE_U_CHAR)
ASSERT_EQ_TYPE(TYPE_INT)
ASSERT_EQ_TYPE(TYPE_U_INT)
ASSERT_EQ_TYPE(TYPE_L_INT)
ASSERT_EQ_TYPE(TYPE_U_L_INT)
ASSERT_EQ_TYPE(TYPE_SIZE_T)
ASSERT_EQ_TYPE(TYPE_FLOAT)
ASSERT_EQ_TYPE(TYPE_DOUBLE)
ASSERT_EQ_TYPE(TYPE_L_DOUBLE)
ASSERT_EQ_TYPE(TYPE_STRING)
void
append_func(void (*run)(void), char *name){
static struct func *f_static = NULL;
if(f_static == NULL){
f_static = &f_beging;
f_static->name = malloc(strlen(name));
strcpy(f_static->name,name);
f_static->run = run;
f_static->next = NULL;
}
else{
struct func *tmp = malloc(sizeof(struct func));
tmp->run = run;
tmp->name = malloc(strlen(name));
strcpy(tmp->name,name);
tmp->next = NULL;
f_static->next = tmp;
f_static = tmp;
}
++count_tests;
}
void begin_execute_func(char *fun_ame){
vprintf_colored(GREEN_K,HK_RN);
printf(" %s\n", fun_ame);
count_passed_local = 0;
count_failed_local = 0;
}
void end_execute_func(char *fun_ame){
if(count_passed_local){
printHK_color(GREEN_K,HK_DN," %lu tests passed from %s\n",count_passed_local,fun_ame);
}
if(count_failed_local){
printHK_color(RED_K, HK_DN, " %lu tests failed from %s\n",count_failed_local,fun_ame);
}
}
void head_run(size_t nbtest){
printHK_color(GREEN_K, HK_EQ," Running %lu tests.\n",nbtest);
}
void list_failed_test(struct failed_lists *failed_lst){
printHK_color(RED_K, HK_FL," %s\n",failed_lst->name);
if(failed_lst->next) list_failed_test(failed_lst->next);
}
void
stat_end_run(){
if(failed_l != NULL){
printHK_color(RED_K, HK_FL," %lu tests, listed below:\n",count_failed);
list_failed_test(failed_l);
}
}
bool is_in_array(size_t *array, size_t sz, size_t num){
bool found = false;
for(size_t i = 0; i < sz; ++i){
if(array[i] == num){
found = true;
break;
}
}
return found;
}
void execute_all(struct func *fun){
struct func *tmp = fun;
//printHK_color(GREEN_K, HK_EQ," Running %lu tests.\n",count_tests);
while(tmp){
begin_execute_func(tmp->name);
tmp->run();
end_execute_func(tmp->name);
tmp = tmp->next;
}
}
void execute_one_test(struct func *fun, size_t num){
size_t cur = 0;
struct func *tmp = fun;
while(tmp){
if(cur++ == num){
begin_execute_func(fun->name);
fun->run();
end_execute_func(fun->name);
}
tmp = tmp->next;
}
}
void execute_some_tests_ordered(struct func *fun, size_t cnt, size_t *array )
{
struct func *tmp = fun;
size_t cur = 0, index = 0;
while(tmp){
if((cur < cnt) && (index++ == array[cur])){
begin_execute_func(tmp->name);
tmp->run();
end_execute_func(tmp->name);
++cur;
}
tmp = tmp->next;
}
}
void
run_some_tests(size_t cnt, ...)
{
head_run(cnt);
va_list args;
va_start(args, cnt);
for(size_t i=0; i < cnt; ++i){
execute_one_test(&f_beging, va_arg(args, size_t));
}
va_end(args);
stat_end_run();
}
void
run_some_tests_ordered(size_t cnt, ... )
{
head_run(cnt);
va_list args;
va_start(args, cnt);
size_t *array=malloc(cnt*sizeof(size_t));
for(size_t i=0; i < cnt; ++i){
array[i] = va_arg(args, size_t);
}
execute_some_tests_ordered(&f_beging, cnt, array);
va_end(args);
stat_end_run();
}
void execute_all_tests_exept(struct func *fun, size_t cnt, size_t *array )
{
struct func *tmp = fun;
size_t cur = 0;
while(tmp){
if(!is_in_array(array, cnt, cur++)){
begin_execute_func(tmp->name);
tmp->run();
end_execute_func(tmp->name);
}
tmp = tmp->next;
}
}
void
run_all_tests_exept(size_t cnt, ... )
{
if(count_tests >= cnt)
head_run(count_tests - cnt);
va_list args;
va_start(args, cnt);
size_t *array=malloc(cnt*sizeof(size_t));
for(size_t i=0; i < cnt; ++i){
array[i] = va_arg(args, size_t);
}
execute_all_tests_exept(&f_beging, cnt, array);
va_end(args);
stat_end_run();
}
void
run_all_tests()
{
head_run(count_tests);
execute_all(&f_beging);
stat_end_run();
}
void
clear_all_func(struct func **fun)
{
if(*fun != NULL)
{
clear_all_func(&((*fun)->next));
free(*fun);
*fun = NULL;
}
}
+129
View File
@@ -0,0 +1,129 @@
#include "src/test_t/test_t.h"
#define CHANGE_TO_DEFAULT_COLOR_IN_TERMINAL printf("\033[0m"); //Resets the text to default color
#define CHANGE_COLOR_TO_GREEN_IN_TERMINAL printf("\033[0;32m"); // Green
#define CHANGE_COLOR_TO_RED_IN_TERMINAL printf("\033[0;31m"); // Red
#define PRINT_HOOK_WITH_EQ_SYMBOLE \
printf("["); for(size_t i = 0; i< SIZE_OK; ++i) printf("="); printf("]");
//static function_list *p_f_l;
function_list *p_f_l;
void
print_OK()
{
CHANGE_COLOR_TO_GREEN_IN_TERMINAL
PRINT_HOOK_WITH_EQ_SYMBOLE
CHANGE_TO_DEFAULT_COLOR_IN_TERMINAL
printf("OK ");
}
void
print_KO()
{
CHANGE_COLOR_TO_GREEN_IN_TERMINAL
PRINT_HOOK_WITH_EQ_SYMBOLE
CHANGE_TO_DEFAULT_COLOR_IN_TERMINAL
printf("KO ");
}
void
print_OK_with_msg(char *msg)
{
print_OK();
printf(" %s ",msg);
}
void
print_KO_with_msg(char *msg)
{
print_KO();
printf(" %s ",msg);
}
void
print_OK_with_msg_endl(char *msg)
{
print_OK();
printf(" %s\n",msg);
}
void
print_KO_with_msg_endl(char *msg)
{
print_KO();
printf(" %s\n", msg);
}
void
run_all_tests()
{
initiation_test();
execute_all_function_list();
clear_fonction_list(&p_f_l);
}
void
append_function_list(void (*f)(void), char *name_function)
{
printf("append %s test\n",name_function);
static size_t counter=0;
function_list * f_l=malloc(sizeof(function_list));
if(f_l)
{
if(f_l->name_function) free(f_l->name_function);
f_l->name_function = malloc(sizeof(char)*strlen(name_function) + 1);
strcpy(f_l->name_function, name_function);
f_l->function_top = f;
f_l->next = NULL;
}
else
{
printf("error allocation f_l\n");
return;
}
if(p_f_l != NULL)
{
function_list *tmp_f_l = p_f_l;
while(tmp_f_l->next)
tmp_f_l = tmp_f_l->next;
tmp_f_l->next = f_l;
}
else p_f_l = f_l;
}
void
execute_all_function_list()
{
printf("run functions tests\n");
function_list * tmp_f_l = p_f_l;
while(tmp_f_l)
{
printf("RUN %s \n",tmp_f_l->name_function);
tmp_f_l->function_top();
tmp_f_l = tmp_f_l->next;
}
}
void
clear_fonction_list(function_list **f_l)
{
if(*f_l != NULL)
{
clear_fonction_list(&((*f_l)->next));
free(*f_l);
*f_l = NULL;
}
}
void
initiation_test()
{
if(p_f_l != NULL)
{
free(p_f_l);
p_f_l=NULL;
}
}
+106
View File
@@ -0,0 +1,106 @@
#ifndef __TEST_C_H__
#define __TEST_C_H__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "src/tools_t/tools_t.h"
struct func {
char *name;
void (*run)(void);
struct func *next;
};
//void begin_f();
//struct func f_beging;
void vprintf_colored(char *color, char * format, ...);
void run_all_tests();
void execute_all(struct func *fun);
void append_func(void (*run)(void), char *name);
void clear_all_func();
void run_some_tests(size_t cnt, ... );
void run_all_tests_exept(size_t cnt, ... );
void run_some_tests_ordered(size_t cnt, ... );
bool assert_true_from(bool val, const char* var_name, const char * func_name);
bool assert_false_from(bool val, const char* var_name, const char * func_name);
#define GEN_ASSERT_EQ_TYPE_FUNC(type)\
bool assert_eq_##type(type var1, type var2, \
const char *var1_name, const char *var2_name, const char *func_name); \
GEN_ASSERT_EQ_TYPE_FUNC(TYPE_CHAR)
GEN_ASSERT_EQ_TYPE_FUNC(TYPE_U_CHAR)
GEN_ASSERT_EQ_TYPE_FUNC(TYPE_INT)
GEN_ASSERT_EQ_TYPE_FUNC(TYPE_U_INT)
GEN_ASSERT_EQ_TYPE_FUNC(TYPE_L_INT)
GEN_ASSERT_EQ_TYPE_FUNC(TYPE_U_L_INT)
GEN_ASSERT_EQ_TYPE_FUNC(TYPE_SIZE_T)
GEN_ASSERT_EQ_TYPE_FUNC(TYPE_FLOAT)
GEN_ASSERT_EQ_TYPE_FUNC(TYPE_DOUBLE)
GEN_ASSERT_EQ_TYPE_FUNC(TYPE_L_DOUBLE)
GEN_ASSERT_EQ_TYPE_FUNC(TYPE_STRING)
#define ASSERT_EQ_TYPE_CHAR(var1, var2) if(assert_eq_TYPE_CHAR(var1, var2, #var1, #var2, __func__) == false) return ;
#define ASSERT_EQ_TYPE_U_CHAR(var1, var2) if(assert_eq_TYPE_U_CHAR(var1, var2, #var1, #var2, __func__) == false) return ;
#define ASSERT_EQ_TYPE_INT(var1, var2) if(assert_eq_TYPE_INT(var1, var2, #var1, #var2, __func__) == false) return ;
#define ASSERT_EQ_TYPE_U_INT(var1, var2) if(assert_eq_TYPE_U_INT(var1, var2, #var1, #var2, __func__) == false) return ;
#define ASSERT_EQ_TYPE_L_INT(var1, var2) if(assert_eq_TYPE_L_INT(var1, var2, #var1, #var2, __func__) == false) return ;
#define ASSERT_EQ_TYPE_U_L_INT(var1, var2) if(assert_eq_TYPE_U_L_INT(var1, var2, #var1, #var2, __func__) == false) return ;
#define ASSERT_EQ_TYPE_SIZE_T(var1, var2) if(assert_eq_TYPE_SIZE_T(var1, var2, #var1, #var2, __func__) == false) return ;
#define ASSERT_EQ_TYPE_FLOAT(var1, var2) if(assert_eq_TYPE_FLOAT(var1, var2, #var1, #var2, __func__) == false) return ;
#define ASSERT_EQ_TYPE_DOUBLE(var1, var2) if(assert_eq_TYPE_DOUBLE(var1, var2, #var1, #var2, __func__) == false) return ;
#define ASSERT_EQ_TYPE_L_DOUBLE(var1, var2) if(assert_eq_TYPE_L_DOUBLE(var1, var2, #var1, #var2, __func__) == false) return ;
#define ASSERT_EQ_TYPE_STRING(var1, var2) if(assert_eq_TYPE_STRING(var1, var2, #var1, #var2, __func__) == false) return ;
#define CONCAT(x,y) x ## y
#define STRFY(x) # x
#define test_label test
#define FTEST_(count, name_f) \
void CONCAT(test_##name_f##____,count)(void); \
__attribute__((constructor)) \
void CONCAT(append_test_##name_f,count)(void){ \
append_func(CONCAT(test_##name_f##____,count),STRFY(name_f test count)); \
} \
void CONCAT(test_##name_f##____,count)(void)
#define FTEST__(count, name_f) \
void CONCAT(name_f##___,count)(void); \
__attribute__((constructor)) \
void CONCAT(append_test_##name_f,count)(void){ \
append_func(CONCAT(name_f##___,count),STRFY(name_f test count)); \
} \
void CONCAT(name_f##___,count)(void)
#define TEST(name_f)\
FTEST_(__COUNTER__,name_f)
//#define TEST(name_f) \
FTEST__(__COUNTER__,name_f)
#define ASSERT_TRUE(val)\
if(assert_true_from(val,#val,__func__) == false) return;
#define ASSERT_FALSE(val)\
if(assert_false_from(val,#val,__func__) == false) return;
#endif /* __TEST_C_H__ */
+55
View File
@@ -0,0 +1,55 @@
#ifndef __TEST_C_H__
#define __TEST_C_H__
#include <stdio.h>
#include <stdlib.h>
#include "src/tools_t/tools_t.h"
#define SIZE_OK 7
/*
size_t COUNT_OK = 0;
size_t COUNT_KO = 0;
size_t COUNT_TEST = 0;
*/
struct function_list{
char * name_function;
void(*function_top)(void);
struct function_list * next;
};
typedef struct function_list function_list;
void clear_fonction_list(function_list **f_l);
void append_function_list(void(*f)(void), char *name_function);
void execute_all_function_list();
void run_all_tests();
void initiation_test();
#define TEST(name_f) \
void test_##name_f(void); \
void append_test_##name_f(void){ \
append_function_list(test_##name_f,#name_f); \
} \
struct STRUCT_##name_f{ \
void (*append)(void); \
} instance_struct_test_##name_f = {append_test_##name_f}; \
void test_##name_f(void)
void print_OK();
void print_KO();
void print_OK_with_msg(char* msg);
void print_KO_with_msg(char *msg);
void print_OK_with_msg_endl(char* msg);
void print_KO_with_msg_endl(char *msg);
#endif /* __TEST_C_H__ */
+26 -1
View File
@@ -1,9 +1,34 @@
#include "src/tools_t/tools_t.h" #include "src/tools_t/tools_t.h"
#define GEN_TO_STR_N(type,size,format) \
TYPE_STRING type##_TO_STR(type var){ \
char *ret = malloc(size); \
sprintf(ret,format,var); \
ret[strlen(ret)]='\0'; \
return ret; }
GEN_TO_STR_N(TYPE_CHAR,2,"%c")
GEN_TO_STR_N(TYPE_U_CHAR,2,"%c")
GEN_TO_STR_N(TYPE_INT,22,"%d")
GEN_TO_STR_N(TYPE_U_INT,22,"%u")
GEN_TO_STR_N(TYPE_L_INT,22,"%ld")
GEN_TO_STR_N(TYPE_U_L_INT,22,"%lu")
GEN_TO_STR_N(TYPE_SIZE_T,22,"%lu")
GEN_TO_STR_N(TYPE_FLOAT,128,"%f")
GEN_TO_STR_N(TYPE_DOUBLE,256,"%lf")
GEN_TO_STR_N(TYPE_L_DOUBLE,256,"%Lf")
TYPE_STRING TYPE_STRING_TO_STR(TYPE_STRING var){
return var;
}
#define MIN_ABS_FLOAT 1
#define MULT_FLOAT_ERR 100000
#define GENERATE_FUNCTION_NUMERIC(type)\ #define GENERATE_FUNCTION_NUMERIC(type)\
int COMPARE_N_##type(const void *a, const void *b){ \ int COMPARE_N_##type(const void *a, const void *b){ \
if (*(type*)a == *(type*)b) return 0; \ if (abs((*(type*)a - *(type*)b) * MULT_FLOAT_ERR) < MIN_ABS_FLOAT ) return 0; \
if (*(type*)a > *(type*)b) return 1; \ if (*(type*)a > *(type*)b) return 1; \
return -1; }\ return -1; }\
\ \
+1
View File
@@ -31,6 +31,7 @@
size_t ARG_MAX_ARRAY_##type(const type *array, size_t size);\ size_t ARG_MAX_ARRAY_##type(const type *array, size_t size);\
type MIN_ARRAY_##type(const type *array, size_t size);\ type MIN_ARRAY_##type(const type *array, size_t size);\
size_t ARG_MIN_ARRAY_##type(const type *array, size_t size);\ size_t ARG_MIN_ARRAY_##type(const type *array, size_t size);\
TYPE_STRING type##_TO_STR(type var);\
GENERATE_ALL(TYPE_CHAR) GENERATE_ALL(TYPE_CHAR)