debug permutation_t: translate set theoric
This commit is contained in:
@@ -41,15 +41,22 @@ long diff_timespec_nanoseconds(struct timespec time_stop, struct timespec time_s
|
|||||||
void gotoxy(int x, int y);
|
void gotoxy(int x, int y);
|
||||||
//void get_cursor_position(int *col, int *rows);
|
//void get_cursor_position(int *col, int *rows);
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
|
||||||
#define debug_print(fmt, ...) \
|
#define debug_print(fmt, ...) \
|
||||||
do { if (DEBUG) fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
|
do { /*if (DEBUG)*/ fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
|
||||||
__LINE__, __func__, __VA_ARGS__); } while (0)
|
__LINE__, __func__, __VA_ARGS__); } while (0)
|
||||||
|
|
||||||
#define PRINT_DEBUG_(fmt, ...) \
|
#define PRINT_DEBUG_(fmt, ...) \
|
||||||
do { if (DEBUG) fprintf(F_ERR, "%s:%d:%s(): " fmt, __FILE__, \
|
do { /*if (DEBUG)*/ fprintf(F_ERR, "%s:%d:%s(): " fmt, __FILE__, \
|
||||||
__LINE__, __func__, __VA_ARGS__); } while (0)
|
__LINE__, __func__, __VA_ARGS__); } while (0)
|
||||||
|
|
||||||
|
#else
|
||||||
|
#define debug_print(fmt, ...) {}
|
||||||
|
|
||||||
|
#define PRINT_DEBUG_(fmt, ...) {}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#define error_print(fmt, ...) \
|
#define error_print(fmt, ...) \
|
||||||
fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
|
fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
|
||||||
|
|||||||
BIN
Binary file not shown.
@@ -13,7 +13,7 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
gcc -o launch_is_good_c $1 -L$PWD/../ $2 -lytest -I../include_ytest/include src/permutation_t/permutation_t.o src/set_theoric_t/set_theoric_t.o -I./src
|
gcc -o launch_is_good_c $1 -L$PWD/../ $2 -lytest -I../include_ytest/include src/permutation_t/permutation_t.c src/set_theoric_t/set_theoric_t.c -I./src
|
||||||
#gcc -o launch_is_good_c $1 $2 -lytest -I../include_ytest src/permutation_t/permutation_t.o src/set_theoric_t/set_theoric_t.o -I./src
|
#gcc -o launch_is_good_c $1 $2 -lytest -I../include_ytest src/permutation_t/permutation_t.o src/set_theoric_t/set_theoric_t.o -I./src
|
||||||
|
|
||||||
export LD_LIBRARY_PATH=$PWD/../:LD_LIBRARY_PATH
|
export LD_LIBRARY_PATH=$PWD/../:LD_LIBRARY_PATH
|
||||||
|
|||||||
@@ -12,13 +12,11 @@
|
|||||||
#include "ftest/ftest.h"
|
#include "ftest/ftest.h"
|
||||||
#include "fmock/fmock.h"
|
#include "fmock/fmock.h"
|
||||||
|
|
||||||
#if 1
|
|
||||||
|
|
||||||
#include "permutation_t/permutation_t.h"
|
#include "permutation_t/permutation_t.h"
|
||||||
|
|
||||||
|
|
||||||
TEST(size_permutation2){
|
TEST(size_permutation2){
|
||||||
sleep(4);
|
|
||||||
PRINTF("another size_permutation2 again\n");
|
PRINTF("another size_permutation2 again\n");
|
||||||
ASSERT_TRUE(false);
|
ASSERT_TRUE(false);
|
||||||
}
|
}
|
||||||
@@ -29,10 +27,86 @@ TEST(size_permutation)
|
|||||||
|
|
||||||
PRINTF(" size = %lu \n",p->size);
|
PRINTF(" size = %lu \n",p->size);
|
||||||
EXPECT_EQ(p->size, 3);
|
EXPECT_EQ(p->size, 3);
|
||||||
|
|
||||||
PRINTF("test size_permutation2\n");
|
PRINTF("test size_permutation2\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
TEST(permutation_t_float_trans)
|
||||||
|
{
|
||||||
|
int n =8;
|
||||||
|
PERMUTATION_TYPE_FLOAT *p = CREATE_PERMUTATION_TYPE_FLOAT(n);
|
||||||
|
|
||||||
|
PRINTF(" size = %lu \n",p->size);
|
||||||
|
EXPECT_EQ(p->size, n);
|
||||||
|
|
||||||
|
p->perm[0]=0.001;
|
||||||
|
p->perm[1]=0.01;
|
||||||
|
p->perm[2]=0.00101;
|
||||||
|
p->perm[3]=0.02;
|
||||||
|
p->perm[4]=0.1;
|
||||||
|
p->perm[5]=0.1;
|
||||||
|
|
||||||
|
PERMUTATION_TYPE_SIZE_T *translate_p = TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_FLOAT(p);
|
||||||
|
|
||||||
|
for(int i = 0; i < translate_p->size; ++i) PRINTF(" ([%d] %ld) ,",i,translate_p->perm[i]);
|
||||||
|
PRINTF("\n");
|
||||||
|
for(int i = 0; i < p->size; ++i) PRINTF(" (%d: %f) ,",i,p->perm[i]);
|
||||||
|
PRINTF("\n");
|
||||||
|
|
||||||
|
|
||||||
|
// sleep(n);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(not_permutation_)
|
||||||
|
{
|
||||||
|
int n =8;
|
||||||
|
PERMUTATION_TYPE_FLOAT *p = CREATE_PERMUTATION_TYPE_FLOAT(n);
|
||||||
|
|
||||||
|
PRINTF(" size = %lu \n",p->size);
|
||||||
|
EXPECT_EQ(p->size, n);
|
||||||
|
|
||||||
|
p->perm[0]=0.001;
|
||||||
|
p->perm[1]=0.01;
|
||||||
|
p->perm[2]=0.00101;
|
||||||
|
p->perm[3]=0.02;
|
||||||
|
p->perm[4]=0.1;
|
||||||
|
p->perm[5]=0.1;
|
||||||
|
|
||||||
|
EXPECT_FALSE(IS_PERMUTATION_TYPE_FLOAT(p));
|
||||||
|
|
||||||
|
|
||||||
|
// sleep(n);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TEST(is_permutation_)
|
||||||
|
{
|
||||||
|
int n =6;
|
||||||
|
PERMUTATION_TYPE_FLOAT *p = CREATE_PERMUTATION_TYPE_FLOAT(n);
|
||||||
|
|
||||||
|
PRINTF(" size = %lu \n",p->size);
|
||||||
|
EXPECT_EQ(p->size, n);
|
||||||
|
|
||||||
|
p->perm[0]=0.001;
|
||||||
|
p->perm[1]=0.01;
|
||||||
|
p->perm[2]=0.00101;
|
||||||
|
p->perm[3]=0.02;
|
||||||
|
p->perm[4]=0.2;
|
||||||
|
p->perm[5]=0.1;
|
||||||
|
|
||||||
|
EXPECT_TRUE(IS_PERMUTATION_TYPE_FLOAT(p));
|
||||||
|
|
||||||
|
|
||||||
|
// sleep(n);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST(size_permutation2){
|
TEST(size_permutation2){
|
||||||
PRINTF("another size_permutation2 again false\n");
|
PRINTF("another size_permutation2 again false\n");
|
||||||
@@ -135,6 +209,7 @@ TEST(){
|
|||||||
PRINTF("p_char == %s\n",p_char->perm);
|
PRINTF("p_char == %s\n",p_char->perm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
TEST(lessThan){
|
TEST(lessThan){
|
||||||
long int a=1,b=2;
|
long int a=1,b=2;
|
||||||
EXPECT_LT(a,b);
|
EXPECT_LT(a,b);
|
||||||
@@ -142,6 +217,7 @@ TEST(lessThan){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
TEST(sleep){sleep(2);}
|
TEST(sleep){sleep(2);}
|
||||||
TEST(sleep){sleep(2);}
|
TEST(sleep){sleep(2);}
|
||||||
TEST(sleep){sleep(2);}
|
TEST(sleep){sleep(2);}
|
||||||
@@ -170,7 +246,6 @@ TEST(sleep){sleep(1);}
|
|||||||
TEST(sleep){sleep(1);}
|
TEST(sleep){sleep(1);}
|
||||||
TEST(sleep){sleep(1);}
|
TEST(sleep){sleep(1);}
|
||||||
|
|
||||||
|
|
||||||
TEST(sleep){sleep(1);}
|
TEST(sleep){sleep(1);}
|
||||||
TEST(sleep){sleep(1);}
|
TEST(sleep){sleep(1);}
|
||||||
TEST(sleep){sleep(1);}
|
TEST(sleep){sleep(1);}
|
||||||
@@ -185,6 +260,7 @@ TEST(sleep){sleep(1);}
|
|||||||
TEST(sleep){sleep(1);}
|
TEST(sleep){sleep(1);}
|
||||||
TEST(sleep){sleep(1);}
|
TEST(sleep){sleep(1);}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
MOCK_FUNC(int, f_mock, (), ())
|
MOCK_FUNC(int, f_mock, (), ())
|
||||||
|
|
||||||
@@ -358,6 +434,7 @@ TEST(f7_mock_test){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
|
|
||||||
|
|||||||
@@ -7,14 +7,21 @@
|
|||||||
type j;\
|
type j;\
|
||||||
size_t *count_array_i = calloc(size, sizeof(size_t));\
|
size_t *count_array_i = calloc(size, sizeof(size_t));\
|
||||||
if(count_array_i == NULL){\
|
if(count_array_i == NULL){\
|
||||||
printf("can't alloc count_array_i\n"); return false;}\
|
printf("can't alloc count_array_i\n"); \
|
||||||
|
return false;\
|
||||||
|
}\
|
||||||
for(size_t i = 0; i < size; ++i){\
|
for(size_t i = 0; i < size; ++i){\
|
||||||
j = p->perm[i];\
|
j = p->perm[i];\
|
||||||
if((COMPARE_N_##type(&j, (type*)&size) >= 0) || count_array_i[j]){\
|
if((COMPARE_N_##type(&j, (type*)&size) >= 0) || count_array_i[j]){\
|
||||||
free(count_array_i); return false; }\
|
free(count_array_i); \
|
||||||
++count_array_i[j];}\
|
return false;\
|
||||||
|
}\
|
||||||
|
++count_array_i[j];\
|
||||||
|
}\
|
||||||
free(count_array_i);\
|
free(count_array_i);\
|
||||||
return true; }\
|
return true; \
|
||||||
|
}\
|
||||||
|
|
||||||
|
|
||||||
GENERATE_PERMUTATION_FUNCTIONS_UNSIGNED(TYPE_U_CHAR)
|
GENERATE_PERMUTATION_FUNCTIONS_UNSIGNED(TYPE_U_CHAR)
|
||||||
GENERATE_PERMUTATION_FUNCTIONS_UNSIGNED(TYPE_U_INT)
|
GENERATE_PERMUTATION_FUNCTIONS_UNSIGNED(TYPE_U_INT)
|
||||||
@@ -40,24 +47,15 @@ GENERATE_PERMUTATION_FUNCTIONS_UNSIGNED(TYPE_SIZE_T)
|
|||||||
type *sorted_perm = malloc(size * sizeof(type));\
|
type *sorted_perm = malloc(size * sizeof(type));\
|
||||||
COPY_ARRAY_##type(sorted_perm,(const type*)p->perm, size);\
|
COPY_ARRAY_##type(sorted_perm,(const type*)p->perm, size);\
|
||||||
qsort(sorted_perm, size, sizeof(type), COMPARE_N_##type);\
|
qsort(sorted_perm, size, sizeof(type), COMPARE_N_##type);\
|
||||||
size_t *rec_index_visited = malloc(size * sizeof(size_t));\
|
for(size_t i=0; i< size; ++i)\
|
||||||
size_t cur_rec = 0; bool found_rec;\
|
PRINT_DEBUG_("sorted_perm[%ld] : %s \n",i, type##_TO_STR(sorted_perm[i]));\
|
||||||
for(size_t i = 0; i < size; ++i){\
|
for(size_t j = 0; j < size; ++j){\
|
||||||
for(size_t j = 0; j < size; ++j){\
|
for(size_t i = 0; i < size; ++i){\
|
||||||
if(COMPARE_N_##type(&(p->perm[j]), &(sorted_perm[i])) == 0){\
|
if(COMPARE_N_##type(&(p->perm[j]), &(sorted_perm[i])) == 0){\
|
||||||
found_rec = false;\
|
t_p->perm[j]=i; break;\
|
||||||
for(size_t k = 0; k < cur_rec; ++k){\
|
|
||||||
if(rec_index_visited[k] == j){\
|
|
||||||
found_rec == true; break; } } \
|
|
||||||
if(found_rec == false){\
|
|
||||||
/*t_p->perm[i] = j;*/\
|
|
||||||
t_p->perm[j] = i;\
|
|
||||||
rec_index_visited[cur_rec++] = j; \
|
|
||||||
break; }\
|
|
||||||
}\
|
}\
|
||||||
}\
|
}\
|
||||||
}\
|
}\
|
||||||
free(rec_index_visited);\
|
|
||||||
free(sorted_perm);\
|
free(sorted_perm);\
|
||||||
return t_p; \
|
return t_p; \
|
||||||
}\
|
}\
|
||||||
@@ -94,6 +92,8 @@ GENERATE_PERMUTATION_FUNCTIONS(TYPE_STRING)
|
|||||||
*it is equivalent of 1,3,2,0 in set_theoric(4)=0,1,2,3
|
*it is equivalent of 1,3,2,0 in set_theoric(4)=0,1,2,3
|
||||||
this function calculate the permutation equivalent in set_theoric
|
this function calculate the permutation equivalent in set_theoric
|
||||||
2,4,2,5 is translate to 0,1,0,2
|
2,4,2,5 is translate to 0,1,0,2
|
||||||
|
2,4,7,5 is translate to 0,1,3,2
|
||||||
|
PERMUTATION_TYPE_SIZE_T * TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(const PERMUTATION_##type *p );
|
||||||
* */
|
* */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,12 +13,14 @@
|
|||||||
#define GENERATE_PERMUTATION(type)\
|
#define GENERATE_PERMUTATION(type)\
|
||||||
struct PERMUTATION_##type{\
|
struct PERMUTATION_##type{\
|
||||||
size_t size;\
|
size_t size;\
|
||||||
|
size_t rank;\
|
||||||
type * perm; \
|
type * perm; \
|
||||||
};\
|
};\
|
||||||
\
|
\
|
||||||
typedef struct PERMUTATION_##type PERMUTATION_##type;\
|
typedef struct PERMUTATION_##type PERMUTATION_##type;\
|
||||||
PERMUTATION_##type * CREATE_PERMUTATION_##type(size_t size);\
|
PERMUTATION_##type * CREATE_PERMUTATION_##type(size_t size);\
|
||||||
PERMUTATION_TYPE_SIZE_T * TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(const PERMUTATION_##type *p );\
|
PERMUTATION_TYPE_SIZE_T * TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(const PERMUTATION_##type *p );\
|
||||||
|
bool IS_PERMUTATION_##type(const PERMUTATION_##type *p );\
|
||||||
|
|
||||||
|
|
||||||
GENERATE_PERMUTATION(TYPE_SIZE_T)
|
GENERATE_PERMUTATION(TYPE_SIZE_T)
|
||||||
|
|||||||
@@ -41,15 +41,22 @@ long diff_timespec_nanoseconds(struct timespec time_stop, struct timespec time_s
|
|||||||
void gotoxy(int x, int y);
|
void gotoxy(int x, int y);
|
||||||
//void get_cursor_position(int *col, int *rows);
|
//void get_cursor_position(int *col, int *rows);
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
|
||||||
#define debug_print(fmt, ...) \
|
#define debug_print(fmt, ...) \
|
||||||
do { if (DEBUG) fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
|
do { /*if (DEBUG)*/ fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
|
||||||
__LINE__, __func__, __VA_ARGS__); } while (0)
|
__LINE__, __func__, __VA_ARGS__); } while (0)
|
||||||
|
|
||||||
#define PRINT_DEBUG_(fmt, ...) \
|
#define PRINT_DEBUG_(fmt, ...) \
|
||||||
do { if (DEBUG) fprintf(F_ERR, "%s:%d:%s(): " fmt, __FILE__, \
|
do { /*if (DEBUG)*/ fprintf(F_ERR, "%s:%d:%s(): " fmt, __FILE__, \
|
||||||
__LINE__, __func__, __VA_ARGS__); } while (0)
|
__LINE__, __func__, __VA_ARGS__); } while (0)
|
||||||
|
|
||||||
|
#else
|
||||||
|
#define debug_print(fmt, ...) {}
|
||||||
|
|
||||||
|
#define PRINT_DEBUG_(fmt, ...) {}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#define error_print(fmt, ...) \
|
#define error_print(fmt, ...) \
|
||||||
fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
|
fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
|
||||||
|
|||||||
Reference in New Issue
Block a user