some fixes

This commit is contained in:
2023-06-08 15:59:52 +06:00
parent 080bbb28fd
commit 32ce7d3a70
11 changed files with 35 additions and 41 deletions

View File

@@ -29,6 +29,6 @@ void test_autoarrVsVector(){
_autoarrVsVector(64, 64);
_autoarrVsVector(32, 1024);
_autoarrVsVector(256, 256);
_autoarrVsVector(1024, 1024);
_autoarrVsVector(512, 4096);
);
}

View File

@@ -1,26 +1,31 @@
#include "tests.h"
#include "../src/HashFunctions/hash.h"
#include "../src/Autoarr/Autoarr.h"
#include "../src/random/random.h"
#define SPEED_TESTS 1000000
#define COLLISION_TESTS 64000
char data[]="iojihi2ojo8la14nhvi3311pi[jiugbja38mo0ih6gfty88tryf-drh0lanvj03";
#define SPEED_TESTS 100000
#define COLLISION_TESTS 16000
char data[]="iojihiojopijiugbjmoihftytryfdrh";
#define rng() splitmix64_next(&rng_state)
#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)); \
optime("speed test", SPEED_TESTS, \
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); \
Autoarr(hasht)* hashes=Autoarr_create(hasht,1,COLLISION_TESTS); \
splitmix64_state rng_state; \
splitmix64_construct(&rng_state, random_seedFromTime()); \
optime("collision test",1, \
u32 collisions=0; \
for(u64 i=0;i< COLLISION_TESTS;i++){ \
hasht h=hashb(hashf, (u8*)&i, sizeof(i)); \
u64 rn[8]; \
rn[0]=rng(); rn[1]=rng(); rn[2]=rng(); rn[3]=rng();\
rn[4]=rng(); rn[5]=rng(); rn[6]=rng(); rn[7]=rng();\
hasht h=hashb(hashf, rn, sizeof(rn)); \
bool col=false; \
Autoarr_foreach(hashes,e, \
if(e==h) { \
@@ -40,7 +45,7 @@ char data[]="iojihiojopijiugbjmoihftytryfdrh";
void test_hash_functions(){
optime("test_hash_functions",1,
kprintf("\e[96m--------[test_hash_functions]---------\n");
test_hashfunc(u32, hash_crc32);
test_hashfunc(u32, hash_sdbm32);
test_hashfunc(u32, hash_crc32);
);
}

View File

@@ -24,20 +24,20 @@ void test_type_system();
static inline void test_all(){
kprintf("\e[97mkerep tests are starting!\n");
optime(__func__, 1,
// test_type_system();
test_type_system();
test_allocators();
// test_kprint_colors();
// test_kprint();
// test_safethrow();
// test_rng_algorithms();
// test_cptr();
// test_string();
test_kprint_colors();
test_kprint();
test_safethrow();
test_rng_algorithms();
test_cptr();
test_string();
// test_searchtree();
// test_autoarr();
// test_autoarrVsVector();
// test_hash_functions();
test_autoarr();
test_autoarrVsVector();
// test_hash_functions(); /* long test */
// test_hashtable();
// test_dtsod();*/
// test_dtsod();
kprintf("\e[96m--------------------------------------\e[0m\n");
);
}