breaking changes in type system

This commit is contained in:
2023-02-13 00:34:32 +06:00
parent 305854e721
commit 95fec8d166
48 changed files with 704 additions and 608 deletions

View File

@@ -8,33 +8,33 @@
char data[]="iojihiojopijiugbjmoihftytryfdrh";
#define test_hashfunc(hasht, hashf)({\
kprintf("\e[94mfunction: \e[92m" #hashf "\n");\
hasht h=0;\
optime("speed test", 1, ({\
for(u32 i=0; i<SPEED_TESTS; i++)\
h=hashf(h, data, sizeof(data));\
}));\
/*kprintf("\e[94mhash of \"\e[90m%s\e[94m\": \e[92m%x\n",data, h);*/\
Autoarr(hasht)* hashes=Autoarr_create(hasht,512,32768);\
optime("collision test",1,({\
u32 collisions=0;\
for(u64 i=0;i< COLLISION_TESTS;i++){\
hasht h=hashb(hashf, (u8*)&i, sizeof(i));\
bool col=false;\
Autoarr_foreach(hashes,e,({\
if(e==h) {\
col=true;\
break;\
}\
}));\
if(col) collisions++;\
else Autoarr_add(hashes,h);\
}\
kprintf("\e[93m%u \e[94mcollisions detected in %u hashes\n", collisions, COLLISION_TESTS);\
}));\
Autoarr_free(hashes, true);\
kprintf("\e[96m--------------------------------------\n");\
#define test_hashfunc(hasht, hashf)({ \
kprintf("\e[94mfunction: \e[92m" #hashf "\n"); \
hasht h=0; \
optime("speed test", 1, ({ \
for(u32 i=0; i<SPEED_TESTS; i++) \
h=hashf(h, data, sizeof(data)); \
})); \
/*kprintf("\e[94mhash of \"\e[90m%s\e[94m\": \e[92m%x\n",data, h);*/ \
Autoarr(hasht)* hashes=Autoarr_create(hasht,512,32768); \
optime("collision test",1,({ \
u32 collisions=0; \
for(u64 i=0;i< COLLISION_TESTS;i++){ \
hasht h=hashb(hashf, (u8*)&i, sizeof(i)); \
bool col=false; \
Autoarr_foreach(hashes,e,({ \
if(e==h) { \
col=true; \
break; \
} \
})); \
if(col) collisions++; \
else Autoarr_add(hashes,h); \
} \
kprintf("\e[93m%u \e[94mcollisions detected in %u hashes\n", collisions, COLLISION_TESTS); \
})); \
Autoarr_free(hashes, true); \
kprintf("\e[96m--------------------------------------\n"); \
})
void test_hash_functions(){

View File

@@ -5,11 +5,11 @@
#endif
#define testColor(COLOR) \
kprint_setColor(kp_bgBlack|kp_fg##COLOR);\
kprintf(#COLOR " ");\
kprint_setColor(kp_bg##COLOR|kp_fgGray);\
kprintf(#COLOR);\
kprint_setColor(kp_bgBlack|kp_fgBlack);\
kprint_setColor(kp_bgBlack|kp_fg##COLOR); \
kprintf(#COLOR " "); \
kprint_setColor(kp_bg##COLOR|kp_fgGray); \
kprintf(#COLOR); \
kprint_setColor(kp_bgBlack|kp_fgBlack); \
kprintf("\n");
void test_kprint_colors(){

View File

@@ -2,21 +2,21 @@
#include "../src/random/krandom.h"
#define test_alg(ALG, VALUE_SIZE, EXPECTED_FROM_ZERO){\
kprintf("\e[94mrng algorithm: \e[96m" #ALG "\n");\
void* s= ALG##_init(0);\
u##VALUE_SIZE r=ALG##_next(s);\
kprintf("\e[97m next from zero seed:");\
if(r!=EXPECTED_FROM_ZERO){\
kprintf("\e[91m " IFWIN("%llu\n","%lu\n"), (u64)r);\
throw(ERR_UNEXPECTEDVAL);\
}\
kprintf("\e[92m " IFWIN("%llu\n","%lu\n"), (u64)r);\
ALG##_free(s);\
s= ALG##_initFromTime();\
r=ALG##_next(s);\
ALG##_free(s);\
kprintf("\e[97m next from time seed:\e[92m " IFWIN("%llu\n","%lu\n"), (u64)r);\
#define test_alg(ALG, VALUE_SIZE, EXPECTED_FROM_ZERO){ \
kprintf("\e[94mrng algorithm: \e[96m" #ALG "\n"); \
void* s= ALG##_init(0); \
u##VALUE_SIZE r=ALG##_next(s); \
kprintf("\e[97m next from zero seed:"); \
if(r!=EXPECTED_FROM_ZERO){ \
kprintf("\e[91m " IFWIN("%llu\n","%lu\n"), (u64)r); \
throw(ERR_UNEXPECTEDVAL); \
} \
kprintf("\e[92m " IFWIN("%llu\n","%lu\n"), (u64)r); \
ALG##_free(s); \
s= ALG##_initFromTime(); \
r=ALG##_next(s); \
ALG##_free(s); \
kprintf("\e[97m next from time seed:\e[92m " IFWIN("%llu\n","%lu\n"), (u64)r); \
}
void test_rng_algorithms(){

View File

@@ -2,8 +2,8 @@
void test_type_system(){
for(ktid id=0; id<ktid_last; id++){
ktDescriptor d=ktDescriptor_get(id);
ktDescriptor* type=ktDescriptor_get(id);
kprintf("\e[37m{ id:%u name:%s size:%u freeMembers:%p toString:%p }\n",
d.id, d.name, d.size, d.freeMembers, d.toString);
type->id, type->name, type->size, type->freeMembers, type->toString);
}
}