add some tests in permutation dir

This commit is contained in:
2023-11-24 09:54:41 +01:00
parent 79890b7017
commit 8f5a85bd4d
14 changed files with 1608 additions and 0 deletions
@@ -0,0 +1,60 @@
NAME_TEST=is_good
CC=gcc
ROOT_DIR=$(PWD)
YTESTDIR=$(PWD)/../../../../ytest_t
INCLUDE_DIR=$(PWD)/../../../src
CFLAGS=-I$(INCLUDE_DIR) -I$(YTESTDIR)/include_ytest/include
LDFLAGS=-L$(YTESTDIR) -lytest
#SRC_DIR=$(ROOT_DIR)/src
#SRC=$(wildcard */*/*.c)
SRC=$(wildcard **/**/*.c)
#HEADS=$(OBJS:.o=.h)
TEST_DIR=$(PWD)
EXECSRC=$(NAME_TEST).c
EXEC=launch_$(NAME_TEST)_m
PERMDIR=$(PWD)/../../..
PERMSRC_O=$(PERMDIR)/src/permutation_t/permutation_t.o
TOPTARGETS := all clean
DEPS=$(PERMDIR) $(YTESTDIR)
$(TOPTARGETS): $(DEPS)
$(DEPS):
$(MAKE) -C $@ $(MAKECMDGOALS)
#PERMSRC_O=$(PERMSRC:.c=.o)
#SETTSRC_O=$(PWD)/../src/set_theoric_t/set_theoric_t.o
#SETTSRC_O=$(SETTSRC:.c=.o)
#TOOLSRC=$(TOOLDIR)/src/tools_t/tools_t.c
#TOOLSRC_O=$(TOOLSRC:.c=.o)
OBJ=$(SRC:.c=.o) $(PERMSRC_O)
LIB_YTEST=$(YTESTDIR)/libytest.so
all: $(EXEC) $(LIB_YTEST)
$(EXEC): $(EXECSRC) $(OBJ)
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
.PHONY: clean mrproper
clean:
rm -f $(OBJ)
mrproper: clean
rm -f $(EXEC)
run: $(EXEC)
$(EXEC) -h
@@ -0,0 +1,20 @@
#!/bin/bash
if [ "$#" -le 0 ] ; then
echo "Usage: $0 \"compile flags or prepossession \" " >&2
echo " we can add more option for example '-D DEBUG=1' to have debug print, '-D HK' to have gtest like prompt, od '-g' to gbd" >&2
echo "for example: $0 \"-D DEBUG=1 -D HK -g\""
fi
ddot=../..
tdot=../../..
src=$PWD/$tdot/src
ytestdir=$PWD/$ddot/$ddot/ytest_t
#echo "gcc -o launch_is_good_c $1 -L../../$src/ $2 -lytest -I../../$src/include_ytest/include $src/permutation_t/permutation_t.c $src/set_theoric_t/set_theoric_t.c -I$src "
echo "gcc -o launch_is_good_c is_good.c -L$ytestdir $1 -lytest -I$ytestdir/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 is_good.c -L$ytestdir $1 -lytest -I$ytestdir/include_ytest/include $src/permutation_t/permutation_t.c $src/set_theoric_t/set_theoric_t.c -I$src
@@ -0,0 +1,6 @@
#!/bin/bash
objdump -d -M intel $1 > $1_intel.asm
# AT&T syntax
objdump -d $1 > $1_.asm
@@ -0,0 +1,149 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
// for sleep !
#ifdef __linux__
#include <unistd.h>
#elif _WIN32
#include <windows.h>
#endif
#include "ftest/ftest.h"
#include "fmock/fmock.h"
#include "permutation_t/permutation_t.h"
TEST(size_permutation)
{
PERMUTATION_TYPE_CHAR *p = CREATE_PERMUTATION_TYPE_CHAR(3);
PRINTF(" size = %lu \n",p->size);
EXPECT_EQ(p->size, 3);
}
TEST(permutation_t_float_trans)
{
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.1;
p->perm[5]=0.1;
PERMUTATION_TYPE_SIZE_T *translate_p = TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_FLOAT(p);
size_t expect[]={0,2,1,3,4,4};
for(size_t i= 0; i<translate_p->size; ++i){
EXPECT_EQ(translate_p->perm[i], expect[i]);
}
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(){
PERMUTATION_TYPE_CHAR *p_char = CREATE_PERMUTATION_TYPE_CHAR(6);
p_char->perm[0]='B';
p_char->perm[1]='A';
p_char->perm[2]='Y';
p_char->perm[3]='C';
p_char->perm[4]='B';
p_char->perm[5]='Z';
PERMUTATION_TYPE_SIZE_T *tr_p_char = TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_CHAR(p_char);
for(int i = 0; i < tr_p_char->size; ++i) PRINTF(" [%d ]%ld ,",i,tr_p_char->perm[i]);
PRINTF("p_char == %s\n",p_char->perm);
}
#if 0
#endif
int main(int argc, char **argv){
//run_all_tests();
//run_all_tests_parallel(4);
run_all_tests_args(argc, argv);
//purge_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;
}
@@ -0,0 +1,65 @@
NAME_TEST=is_good
CC=gcc
ROOT_DIR=$(PWD)
INCLUDE_DIR=$(ROOT_DIR)/src
YTESTDIR=$(PWD)/../../ytest_t
CFLAGS=-I$(INCLUDE_DIR) -I../include_ytest/include
LDFLAGS=-L$(YTESTDIR) -lytest
#SRC_DIR=$(ROOT_DIR)/src
#SRC=$(wildcard */*/*.c)
SRCDIR=$(PWD)/../src
#SRC=$(wildcard **/**/*.c)
#OBJ=$(SRC:.c=.o)
#HEADS=$(OBJS:.o=.h)
TEST_DIR=$(PWD)
EXECSRC=$(NAME_TEST).c
EXEC=launch_$(NAME_TEST)_m
PERMSRC=$(SRCDIR)/permutation_t/permutation_t.c
PERMSRC_O=$(PERMSRC:.c=.o)
SETTSRC=$(SRCDIR)/set_theoric_t/set_theoric_t.c
SETTSRC_O=$(SETTSRC:.c=.o)
#TOOLSRC=../ytools_t/src/tools_t/tools_t.c
#TOOLSRC_O=$(TOOLSRC:.c=.o)
TOOLDIR=$(PWD)/../../ytools
TOOLSRC_O=$(TOOLDIR)/src/tools_t/tools_t.o
LIB_YTEST=$(YTESTDIR)/libytest.so
DEPS=$(YTESTDIR) $(TOOLDIR)
all: $(EXEC) $(LIB_YTEST)
$(EXEC): $(EXECSRC) $(OBJ)
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
$(PERMSRC_O): $(PERMSRC) $(SETTSRC_O)
$(CC) -o $@ -c $< $(CFLAGS)
$(SETTSRC_O) : $(SETTSRC) $(TOOLSRC_O)
$(CC) -o $@ -c $< $(CFLAGS)
#$(TOOLSRC_O): $(TOOLSRC)
# $(CC) -o $@ -c $< $(CFLAGS)
.PHONY: clean mrproper
clean:
rm -f $(OBJ)
mrproper: clean
rm -f $(EXEC)
run: $(EXEC)
$(EXEC) -h
@@ -0,0 +1,3 @@
#!/bin/bash
LD_LIBRARY_PATH=../../../.. ./launch_is_good_c $1