Merge branch 'main' into 'network'

This commit is contained in:
2024-01-01 19:46:52 +06:00
117 changed files with 2676 additions and 1451 deletions

View File

@@ -1,13 +1,13 @@
#include "tests.h"
int main(){
if(!setlocale(LC_ALL, "C.UTF8"))
i32 main(){
if(setlocale(LC_CTYPE, "C.UTF-8")!=0)
kprintf("\e[93msetlocale failed\n");
ktDescriptors_beginInit();
ktDescriptors_initKerepTypes();
ktDescriptors_endInit();
kt_beginInit();
kt_initKerepTypes();
kt_endInit();
test_all();
ktDescriptors_free();
kt_free();
kprintf("\e[0m\n");
return 0;
}

View File

@@ -2,16 +2,16 @@
#include "../src/Autoarr/Autoarr.h"
#include <vector>
int64 _autoarrVsVector(uint16 blockCount, uint16 blockLength){
uint32 count=blockLength*blockCount;
kprintf("\e[94mblock count: %u block length: %u count: " IFWIN("%llu", "%lu") "\n", blockCount, blockLength, (uint64)count);
Autoarr_int64* ar=Autoarr_create(int64, blockCount, blockLength);
std::vector<int64> vec=std::vector<int64>();
i64 _autoarrVsVector(u16 blockCount, u16 blockLength){
u32 count=blockLength*blockCount;
kprintf("\e[94mblock count: %u block length: %u count: " IFWIN("%llu", "%lu") "\n", blockCount, blockLength, (u64)count);
Autoarr_i64* ar=Autoarr_create(i64, blockCount, blockLength);
std::vector<i64> vec=std::vector<i64>();
optime("Autoarr_add", count,
Autoarr_add(ar, op_i));
optime("vector_push_back", count,
vec.push_back(op_i));
int64 t=0;
i64 t=0;
optime("Autoarr_get", count,
t=Autoarr_get(ar, op_i));
optime("vector_get", count,
@@ -21,7 +21,7 @@ int64 _autoarrVsVector(uint16 blockCount, uint16 blockLength){
}
void test_autoarrVsVector(){
optime(__func__, 1, ({
optime(__func__, 1,
kprintf("\e[96m-------[test_autoarr_vs_vector]-------\n");
_autoarrVsVector(4, 16);
_autoarrVsVector(16, 64);
@@ -30,5 +30,5 @@ void test_autoarrVsVector(){
_autoarrVsVector(32, 1024);
_autoarrVsVector(256, 256);
_autoarrVsVector(1024, 1024);
}));
);
}

View File

@@ -1,8 +1,8 @@
#include "tests.h"
#include "../src/Autoarr/Autoarr.h"
static void printautoarr(Autoarr(uint16)* ar){
kprintf("\e[94mAutoarr(uint16): "
static void printautoarr(Autoarr(u16)* ar){
kprintf("\e[94mAutoarr(u16): "
IFWIN("%llu", "%lu")
"\n max_blocks_count: %u\n"
" blocks_count: %u\n"
@@ -10,7 +10,7 @@ static void printautoarr(Autoarr(uint16)* ar){
" block_length: %u\n"
" max_length: %u\n"
" length: %u\n",
sizeof(Autoarr(uint16)),
sizeof(Autoarr(u16)),
ar->max_blocks_count,
ar->blocks_count,
ar->max_block_length,
@@ -19,26 +19,26 @@ static void printautoarr(Autoarr(uint16)* ar){
Autoarr_length(ar));
}
static void fillar(Autoarr(uint16)* ar){
for (uint16 i=0;i<Autoarr_max_length(ar);i++)
static void fillar(Autoarr(u16)* ar){
for (u16 i=0;i<Autoarr_max_length(ar);i++)
Autoarr_add(ar,i);
}
static void resetar(Autoarr(uint16)* ar){
for (uint16 i=0;i<Autoarr_max_length(ar);i++)
static void resetar(Autoarr(u16)* ar){
for (u16 i=0;i<Autoarr_max_length(ar);i++)
Autoarr_set(ar,i,Autoarr_max_length(ar)-i-1);
}
static void printallval(Autoarr(uint16)* ar){
static void printallval(Autoarr(u16)* ar){
kprintf("\e[90m");
for (uint16 i=0;i<Autoarr_length(ar);i++)
for (u16 i=0;i<Autoarr_length(ar);i++)
kprintf("%u ",Autoarr_get(ar,i));
kprintf("\n");
}
void test_autoarr(){
optime("test_autoarr",1,({
optime("test_autoarr",1,
kprintf("\e[96m------------[test_autoarr]------------\n");
Autoarr(uint16)* ar=Autoarr_create(uint16,10,16);
Autoarr(u16)* ar=Autoarr_create(u16,10,16);
kprintf("\e[92mautoarr created\n");
fillar(ar);
kprintf("\e[92mautoarr filled up\n");
@@ -49,5 +49,5 @@ void test_autoarr(){
printallval(ar);
Autoarr_free(ar, true);
kprintf("\e[92mautoarr deleted\n");
}));
);
}

154
tests/test_cptr.c Normal file
View File

@@ -0,0 +1,154 @@
#include "tests.h"
const char* strings[]={
"",
"abab",
"ab_ab",
"abab_",
"_abab",
"_ab_ab_",
"_ab_ab",
"_abab_",
"_ab_ab_",
"str_not_containing_a_b",
""
};
#define test_startsWith(str, fragm) \
kprintf("\e[37m'"str"' starts with '"fragm"'"); \
if(cptr_startsWith(str,fragm)) kprintf("\e[92m true\n"); \
else { kprintf("\e[91m false\n"); throw(ERR_UNEXPECTEDVAL); }
#define test_DoesntStartWith(str, fragm) \
kprintf("\e[37m'"str"' doesnt start with '"fragm"'"); \
if(!cptr_startsWith(str,fragm)) kprintf("\e[92m true\n"); \
else { kprintf("\e[91m false\n"); throw(ERR_UNEXPECTEDVAL); }
#define test_endsWith(str, fragm) \
kprintf("\e[37m'"str"' ends with '"fragm"'"); \
if(cptr_endsWith(str,fragm)) kprintf("\e[92m true\n"); \
else { kprintf("\e[91m false\n"); throw(ERR_UNEXPECTEDVAL); }
#define test_DoesntEndWith(str, fragm) \
kprintf("\e[37m'"str"' doesnt end with '"fragm"'"); \
if(!cptr_endsWith(str,fragm)) kprintf("\e[92m true\n"); \
else { kprintf("\e[91m false\n"); throw(ERR_UNEXPECTEDVAL); }
#define test_seekChar(str, fragm, start, count, expected) \
kprintf("\e[37mseek "#fragm" in '"str"' startIndex "#start" count "#count); \
pos=cptr_seekChar(str, fragm, start, count); \
if(pos == expected) kprintf("\e[92m %i\n", pos); \
else { kprintf("\e[91m %i\n", pos); throw(ERR_UNEXPECTEDVAL); }
#define test_seekCharReverse(str, fragm, start, count, expected) \
kprintf("\e[37mseek reverse "#fragm" in '"str"' startIndex "#start" count "#count); \
pos=cptr_seekCharReverse(str, fragm, start, count); \
if(pos == expected) kprintf("\e[92m %i\n", pos); \
else { kprintf("\e[91m %i\n", pos); throw(ERR_UNEXPECTEDVAL); }
#define test_seek(str, fragm, start, count, expected) \
kprintf("\e[37mseek '"fragm"' in '"str"' startIndex "#start" count "#count); \
pos=cptr_seek(str, fragm, start, count); \
if(pos == expected) kprintf("\e[92m %i\n", pos); \
else { kprintf("\e[91m %i\n", pos); throw(ERR_UNEXPECTEDVAL); }
#define test_seekReverse(str, fragm, start, count, expected) \
kprintf("\e[37mseek reverse '"fragm"' in '"str"' startIndex "#start" count "#count); \
pos=cptr_seekReverse(str, fragm, start, count); \
if(pos == expected) kprintf("\e[92m %i\n", pos); \
else { kprintf("\e[91m %i\n", pos); throw(ERR_UNEXPECTEDVAL); }
const int strings_len=sizeof(strings)/sizeof(strings[0]);
void test_cptr(){
optime(__func__,1,
kprintf("\e[96m-------------[test_cptr]--------------\n");
// compare
kprintf("\e[94m--------------[compare]---------------\n");
for(int i=0; i<strings_len-1; i++){
// != next
kprintf("\e[37m'%s'!='%s'", strings[i], strings[i+1]);
bool not_eq= ! cptr_equals(strings[i],strings[i+1]);
if(not_eq) kprintf("\e[92m true\n");
else {
kprintf("\e[91m false\n");
throw(ERR_UNEXPECTEDVAL);
}
// == self
kprintf("\e[37m'%s'=='%s'", strings[i], strings[i]);
bool eq=cptr_equals(strings[i],strings[i]);
if(eq) kprintf("\e[92m true\n");
else {
kprintf("\e[91m false\n");
throw(ERR_UNEXPECTEDVAL);
}
}
kprintf("\e[94m-------------[startsWith]-------------\n");
test_startsWith("abab","ab");
test_startsWith("abab","abab");
test_DoesntStartWith("","");
test_DoesntStartWith("abab","ababc");
test_DoesntStartWith("abab","");
test_DoesntStartWith("","abab");
kprintf("\e[94m--------------[endsWith]--------------\n");
test_endsWith("cab","ab");
test_endsWith("abab","abab");
test_DoesntEndWith("","");
test_DoesntEndWith("abab","ababc");
test_DoesntEndWith("abab","");
test_DoesntEndWith("","abab");
i32 pos=-1;
kprintf("\e[94m--------------[seekChar]--------------\n");
test_seekChar("", '\0', 0, -1, -1)
test_seekChar("", 'u', 0, -1, -1)
test_seekChar("ab", '\0', 0, -1, -1)
test_seekChar("ab", 'u', 0, -1, -1)
test_seekChar("ab", 'a', 0, -1, 0)
test_seekChar("ab", 'b', 0, -1, 1)
test_seekChar("ab", '\0', 0, 2, -1)
test_seekChar("ab", 'b', 1, 2, 1)
test_seekChar("ab", 'b', 1, 1, 1)
kprintf("\e[94m----------[seekCharReverse]-----------\n");
test_seekCharReverse("", 'u', 0, -1, -1)
test_seekCharReverse("ab", 'u', 0, -1, -1)
test_seekCharReverse("ab", 'a', 0, -1, 0)
test_seekCharReverse("ab", 'b', 1, -1, 1)
test_seekCharReverse("ab", 'a', -1, -1, 0)
test_seekCharReverse("ab", 'b', -1, -1, 1)
test_seekCharReverse("ab", '\0', -1, -1, -1)
test_seekCharReverse("ab", '\0', 2, 2, -1)
test_seekCharReverse("ab", 'b', 1, 2, 1)
test_seekCharReverse("ab", 'b', 1, 1, 1)
kprintf("\e[94m----------------[seek]----------------\n");
test_seek("", "", 0, -1, -1)
test_seek("", "u", 0, -1, -1)
test_seek("ab", "", 0, -1, -1)
test_seek("ab", "u", 0, -1, -1)
test_seek("ab", "a", 0, -1, 0)
test_seek("ab", "b", 0, -1, 1)
test_seek("ab", "ab", 0, -1, 0)
test_seek("ab_ab", "ab", 0, -1, 0)
test_seek("ab_ab", "ab", 1, -1, 3)
test_seek("ab_ab", "ab", 1, 5, 3)
test_seek("ab_ab", "ab", 1, 4, -1)
kprintf("\e[94m------------[seekReverse]-------------\n");
test_seekReverse("", "u", 0, -1, -1)
test_seekReverse("ab", "u", 0, -1, -1)
test_seekReverse("ab", "a", 0, -1, 0)
test_seekReverse("ab", "b", 1, -1, 1)
test_seekReverse("ab", "a", -1, -1, 0)
test_seekReverse("ab", "b", -1, -1, 1)
test_seekReverse("ab", "", -1, -1, -1)
test_seekReverse("ab", "", 2, 2, -1)
test_seekReverse("ab", "b", 1, 2, 1)
test_seekReverse("ab", "b", 1, 1, 1)
// TODO cptr_replace
);
}

View File

@@ -7,59 +7,63 @@ const char text[]=
"message: {\n"
" bool: false;"
" int: -2515;"
" uint:#comment!\n 0u;"
" double: 965.557f;#another comment!\n"
" u:#comment!\n 0u;"
" f64: 965.557f;#another comment!\n"
" text: \"_$\\\"\\\\'''a ыыы000;2;=:%d;```\";\n"
" list: [10,20,30,0,0 ];"
"};"
"h: { };";
"h: { };"
"$dollar_list_single: { smth: \"-_-\"; };"
"$dollar_list_many: { i: 0; };"
"$dollar_list_many: { i: 1; };"
"$dollar_list_many: { i: 2; };";
void print_dtsod(Hashtable* dtsod){
kprintf("\e[92m");
Hashtable_foreach(dtsod, p,({
Hashtable_foreach(dtsod, p,
printkvp(p);
if(p.value.typeId==ktid_ptrName(Hashtable)){
kprintf(": {\n");
Hashtable* sub=p.value.VoidPtr;
Hashtable_foreach(sub, _p,({
Hashtable_foreach(sub, _p,
kprintf(" ");
printkvp(_p);
kprintf("\n");
}));
);
kprintf("}");
}
kprintf("\n");
}));
);
}
void test_dtsod(){
optime(__func__,1,({
optime(__func__,1,
kprintf("\e[96m-------------[test_dtsod]-------------\n");
Hashtable* dtsod;
char* s;
optime("deserialize",1,({
tryLast(DtsodV24_deserialize(text),r)
optime("deserialize",1,
tryLast(DtsodV24_deserialize(text),r,;)
dtsod=r.value.VoidPtr;
}));
);
print_dtsod(dtsod);
optime("serialize",1,({
tryLast(DtsodV24_serialize(dtsod),r)
optime("serialize",1,
tryLast(DtsodV24_serialize(dtsod),r,;)
s=r.value.VoidPtr;
}));
);
DtsodV24_free(dtsod);
kprintf("\e[92m%s",s);
optime("reserialize",10,({
tryLast(DtsodV24_deserialize(s),r)
optime("reserialize",10,
tryLast(DtsodV24_deserialize(s),r,;)
dtsod=r.value.VoidPtr;
free(s);
tryLast(DtsodV24_serialize(dtsod),rr)
tryLast(DtsodV24_serialize(dtsod),rr,;)
s=rr.value.VoidPtr;
DtsodV24_free(dtsod);
}));
);
free(s);
}));
);
}

View File

@@ -8,39 +8,39 @@
char data[]="iojihiojopijiugbjmoihftytryfdrh";
#define test_hashfunc(hasht, hashf)({\
kprintf("\e[94mfunction: \e[92m" #hashf "\n");\
hasht h=0;\
optime("speed test", 1, ({\
for(uint32 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,({\
uint32 collisions=0;\
for(uint64 i=0;i< COLLISION_TESTS;i++){\
hasht h=hashb(hashf, (uint8*)&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(){
optime("test_hash_functions",1,({
optime("test_hash_functions",1,
kprintf("\e[96m--------[test_hash_functions]---------\n");
test_hashfunc(uint32, hash_crc32);
test_hashfunc(uint32, hash_sdbm32);
}));
test_hashfunc(u32, hash_crc32);
test_hashfunc(u32, hash_sdbm32);
);
}

View File

@@ -15,16 +15,16 @@ void print_hashtable(Hashtable* ht){
void printrowgraph(Hashtable* ht){
kprintf("\e[94mrow length graph:\n");
uint16 lgs_l=1000;
uint32 lgs[lgs_l];
for(uint32 i=0; i<lgs_l; i++)
u16 lgs_l=1000;
u32 lgs[lgs_l];
for(u32 i=0; i<lgs_l; i++)
lgs[i]=0;
for(uint16 h=0;h<Hashtable_height(ht);h++){
for(u16 h=0;h<Hashtable_height(ht);h++){
Autoarr(KVPair)* ar=ht->rows[h];
uint32 l=Autoarr_length(ar);
u32 l=Autoarr_length(ar);
lgs[l]++;
}
for(uint32 i=0; i<lgs_l; i++)
for(u32 i=0; i<lgs_l; i++)
if(lgs[i]>0) {
char* str0=char_multiply(' ',i>=100?0:(i>=10?1:2));
char* str1=char_multiply(' ',lgs[i]>=100?0:(lgs[i]>=10?1:2));
@@ -36,7 +36,7 @@ void printrowgraph(Hashtable* ht){
}
}
char* genkey(uint32 i){
char* genkey(u32 i){
char* key=malloc(12);
IFMSC(
sprintf_s(key,12,"key_%u",i),
@@ -46,13 +46,13 @@ char* genkey(uint32 i){
}
void fill(Hashtable* ht){
for(uint32 i=0;i<100000;i++)
for(u32 i=0;i<100000;i++)
Hashtable_add(ht,genkey(i),UniUInt64(i));
}
Unitype gett(Hashtable* ht){
Unitype u;
for(uint32 i=0;i<100000;i++){
for(u32 i=0;i<100000;i++){
char* key=genkey(i);
u=Hashtable_get(ht,key);
free(key);
@@ -62,7 +62,7 @@ Unitype gett(Hashtable* ht){
void test_hashtable(){
optime("test_hashtable",1,({
optime("test_hashtable",1,
kprintf("\e[96m-----------[test_hashtable]-----------\n");
Hashtable* ht=Hashtable_create();
kprintf("\e[92mhashtable created\n");
@@ -73,5 +73,5 @@ void test_hashtable(){
print_hashtable(ht);
Hashtable_free(ht);
kprintf("\e[92mhashtable freed\n");
}));
);
}

View File

@@ -5,24 +5,24 @@
#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(){
/* IFWIN(
({
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
for(uint8 col=0; col<255; col++){
for(u8 col=0; col<255; col++){
SetConsoleTextAttribute(hConsole, col);
kprintf("%u ",col);
}
}),
({
for(uint8 col=0; col<255; col++)
for(u8 col=0; col<255; col++)
kprintf("\e[%um%u ", col, col);
})
);

View File

@@ -1,19 +1,21 @@
#include "tests.h"
#include "../src/Network/network.h"
void __test_knIPV4Address_fromStr(char* addrStr, uint8 a, uint8 b, uint8 c, uint8 d){
tryLast(knIPV4Address_fromStr(addrStr), maybeAddr){
knIPV4Address addr;
addr.u32=(uint32)maybeAddr.value.UInt64;
printf("\e[94mknIPV4Address_fromStr(\e[96m%s\e[94m) -> ", addrStr);
if(maybeAddr.value.UInt64!=knIPV4Address_fromBytes(a,b,c,d).u32){
printf("\e[91m%u.%u.%u.%u\n",
(uint8)addr.bytes[0], (uint8)addr.bytes[1], (uint8)addr.bytes[2], (uint8)addr.bytes[3]);
throw("knIPV4Address_fromStr returned wrong value");
}
else printf("\e[92m%u.%u.%u.%u\n",
(uint8)addr.bytes[0], (uint8)addr.bytes[1], (uint8)addr.bytes[2], (uint8)addr.bytes[3]);
void __test_knIPV4Address_fromStr(char* addrStr, u8 a, u8 b, u8 c, u8 d){
tryLast(knIPV4Address_fromStr(addrStr), maybeAddr, ;)
knIPV4Address addr;
addr.u32=(u32)maybeAddr.value.UInt64;
printf("\e[94mknIPV4Address_fromStr(\e[96m%s\e[94m) -> ", addrStr);
if(maybeAddr.value.UInt64!=knIPV4Address_fromBytes(a,b,c,d).u32){
printf("\e[91m%u.%u.%u.%u\n",
(u8)addr.bytes[0], (u8)addr.bytes[1], (u8)addr.bytes[2], (u8)addr.bytes[3]);
throw("knIPV4Address_fromStr returned wrong value");
}
else {
printf("\e[92m%u.%u.%u.%u\n",
(u8)addr.bytes[0], (u8)addr.bytes[1], (u8)addr.bytes[2], (u8)addr.bytes[3]);
}
}
#define test_knIPV4Address_fromStr(a,b,c,d) __test_knIPV4Address_fromStr(#a"."#b"."#c"."#d, a,b,c,d)

View File

@@ -2,25 +2,25 @@
#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);\
uint##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"), (uint64)r);\
throw(ERR_UNEXPECTEDVAL);\
}\
kprintf("\e[92m " IFWIN("%llu\n","%lu\n"), (uint64)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"), (uint64)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(){
optime("test_rng_algorithms",1,({
optime("test_rng_algorithms",1,
kprintf("\e[96m--------[test_rng_algorithms]---------\n");
// for ALG32
// xoroshiro64
@@ -41,5 +41,5 @@ void test_rng_algorithms(){
test_alg(xoshiro256starstar, 64, 11091344671253066420ULL)
// splitmix64
test_alg(splitmix64, 64, 16294208416658607535ULL)
}));
);
}

View File

@@ -15,7 +15,7 @@ Maybe throw_errcode(){
Maybe test_maybe(){
kprintf("\e[94mdont_throw returns \e[92m");
tryLast(dont_throw(),rez0)
tryLast(dont_throw(),rez0,;)
printMaybe(rez0);
kprintf("\n");
try(throw_error(),rez1,;)
@@ -30,7 +30,7 @@ Maybe a(){ try(b(),_,;) return MaybeNull; }
void test_safethrow(){
kprintf("\e[96m-----------[test_safethrow]-----------\n");
optime("test_safethrow", 1, ({
optime("test_safethrow", 1,
Maybe e=test_maybe();
kprintf("\e[94mthrow_error:\n\e[92m");
printMaybe(e);
@@ -39,5 +39,5 @@ void test_safethrow(){
e=a();
printMaybe(e);
Maybe_free(e);
}));
);
}

View File

@@ -9,13 +9,13 @@ void printstnode(STNode* node){
kprintf("\n");
// prints pointers to all existing branches
/* kprintf(" branches: %p\n", node->branches);
if(node->branches) for(uint8 i=0;i<8;i++){
if(node->branches) for(u8 i=0;i<8;i++){
kprintf(" \e[90m[%u]=%p\n",i,node->branches[i]);
if(node->branches[i])
for (uint8 ii = 0; ii < 8; ii++){
for (u8 ii = 0; ii < 8; ii++){
kprintf(" \e[90m[%u]=%p\n",ii,node->branches[i][ii]);
if(node->branches[i][ii])
for (uint8 iii = 0; iii < 4; iii++)
for (u8 iii = 0; iii < 4; iii++)
kprintf(" \e[90m[%u]=%p\n",iii,node->branches[i][ii][iii]);
}
@@ -23,7 +23,7 @@ void printstnode(STNode* node){
}
void test_searchtree(){
optime("test_searchtree",1,({
optime("test_searchtree",1,
kprintf("\e[96m-----------[test_searchtree]----------\n");
STNode* node=STNode_create();
kprintf("\e[92mnode created\n");
@@ -70,5 +70,5 @@ void test_searchtree(){
printstnode(node);
STNode_free(node);
kprintf("\e[92mnode deleted\n");
}));
);
}

View File

@@ -2,7 +2,7 @@
#include "../src/String/string.h"
void test_string(){
optime(__func__,1,({
optime(__func__,1,
kprintf("\e[96m-------------[test_string]------------\n");
char c[]="0123456789abcdef";
string s={.ptr=c, .length=cptr_length(c)};
@@ -10,5 +10,5 @@ void test_string(){
char* p=string_extract(s);
kprintf("\e[94mstring_extract() -> \e[92m\"%s\"\n",p);
free(p);
}));
);
}

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);
}
}

View File

@@ -6,6 +6,7 @@
extern "C" {
#endif
void test_cptr();
void test_string();
void test_safethrow();
void test_searchtree();
@@ -18,24 +19,27 @@ void test_rng_algorithms();
void test_kprint_colors();
void test_kprint();
void test_type_system();
void test_network();
inline void test_all(){
kprintf("\e[97mkerep tests are starting!\n");
optime(__func__, 1, ({
optime(__func__, 1,
test_cptr();
test_type_system();
test_string();
test_safethrow();
test_searchtree();
test_autoarr();
test_autoarrVsVector();
test_hash_functions();
test_hashtable();
test_dtsod();
test_rng_algorithms();
test_kprint_colors();
test_kprint();
test_hash_functions();
test_hashtable();
test_dtsod();
test_network();
kprintf("\e[96m--------------------------------------\e[0m\n");
}));
);
}
#define PRINT_SIZEOF(T) kprintf("\e[94m" #T " size: \e[96m" IFWIN("%llu", "%lu") "\n", sizeof(T))