Add dict tests
This commit is contained in:
@@ -9,18 +9,28 @@ vtype_string* string_duplicate(const vtype_string* x) { return 0; }
|
||||
vtype_list* list_duplicate (const vtype_list* x) { return 0; }
|
||||
vtype_map* map_duplicate (const vtype_map* x) { return 0; }
|
||||
vtype_set* vset_duplicate (const vtype_set* x) { return 0; }
|
||||
vtype_dict* dict_duplicate (const vtype_dict* x) { return 0; }
|
||||
|
||||
void string_free(vtype_string* x) {}
|
||||
void list_free (vtype_list* x) {}
|
||||
void map_free (vtype_map* x) {}
|
||||
void vset_free (vtype_set* x) {}
|
||||
void dict_free (vtype_dict* x) {}
|
||||
|
||||
int string_compare(const vtype_string* s0, const vtype_string* s1) { return random_int8(); }
|
||||
int list_compare (const vtype_list* s0, const vtype_list* s1) { return random_int8(); }
|
||||
int map_compare (const vtype_map* s0, const vtype_map* s1) { return random_int8(); }
|
||||
int vset_compare (const vtype_set* s0, const vtype_set* s1) { return random_int8(); }
|
||||
int dict_compare (const vtype_dict* s0, const vtype_dict* s1) { return random_int8(); }
|
||||
|
||||
extern void string_copy_init(vtype_string* x, const vtype_string* s) { memset(x, 0, sizeof(*x)); }
|
||||
extern void list_copy_init (vtype_list* x, const vtype_list* s) { memset(x, 0, sizeof(*x)); }
|
||||
extern void map_copy_init (vtype_map* x, const vtype_map* s) { memset(x, 0, sizeof(*x)); }
|
||||
extern void vset_copy_init (vtype_set* x, const vtype_set* s) { memset(x, 0, sizeof(*x)); }
|
||||
hash_t string_hash(const vtype_string* s) { return 0; }
|
||||
hash_t list_hash (const vtype_list* s) { return 0; }
|
||||
hash_t map_hash (const vtype_map* s) { return 0; }
|
||||
hash_t vset_hash (const vtype_set* s) { return 0; }
|
||||
hash_t dict_hash (const vtype_dict* s) { return 0; }
|
||||
|
||||
void string_copy_init(vtype_string* x, const vtype_string* s) { memset(x, 0, sizeof(*x)); }
|
||||
void list_copy_init (vtype_list* x, const vtype_list* s) { memset(x, 0, sizeof(*x)); }
|
||||
void map_copy_init (vtype_map* x, const vtype_map* s) { memset(x, 0, sizeof(*x)); }
|
||||
void vset_copy_init (vtype_set* x, const vtype_set* s) { memset(x, 0, sizeof(*x)); }
|
||||
void dict_copy_init (vtype_dict* x, const vtype_dict* s) { memset(x, 0, sizeof(*x)); }
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/* This software is licensed by the MIT License, see LICENSE file */
|
||||
/* Copyright © 2022 Gregory Lirent */
|
||||
|
||||
#include "plug.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
test_init(argc, argv);
|
||||
|
||||
dict_t x;
|
||||
|
||||
dict_init(&x);
|
||||
|
||||
visual_push(&x, random_uint8()%17 + 16);
|
||||
visual_remove(&x);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/* This software is licensed by the MIT License, see LICENSE file */
|
||||
/* Copyright © 2022 Gregory Lirent */
|
||||
|
||||
#include "../../../include/extra/dict.h"
|
||||
|
||||
#include "../../include/random.h"
|
||||
#include "../../include/test.h"
|
||||
#include "../../include/time.h"
|
||||
|
||||
void dict_push_random(dict_t* x, bool silent, unsigned int hpos);
|
||||
void dict_remove_random(dict_t* x, bool silent, unsigned int hpos);
|
||||
|
||||
void dict_print(dict_t* x, const char* prefix, unsigned int hpos);
|
||||
void dict_info(const dict_t* x, unsigned int hpos);
|
||||
|
||||
void visual_push(dict_t* x, size_t n);
|
||||
void visual_remove(dict_t* x);
|
||||
@@ -0,0 +1,47 @@
|
||||
/* This software is licensed by the MIT License, see LICENSE file */
|
||||
/* Copyright © 2022 Gregory Lirent */
|
||||
|
||||
#include "../plug.h"
|
||||
|
||||
static int node_print_callback(const void* k, vtype kt, void* v, vtype vt, void* _) {
|
||||
print_container_value(0, k, kt, 0, *(unsigned int*)_);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dict_print(dict_t* x, const char* prefix, unsigned int hpos) {
|
||||
print_container_values_prefix("Dict", prefix, 0);
|
||||
dict_foreach(x, &hpos, node_print_callback);
|
||||
put_separator(0);
|
||||
}
|
||||
|
||||
void dict_info(const dict_t* x, unsigned int hpos) {
|
||||
print_container_info("Dict", "nodes", 0, dict_size(x), -1, 0);
|
||||
put_separator(0);
|
||||
}
|
||||
|
||||
void visual_push(dict_t* x, size_t n) {
|
||||
while (n--) {
|
||||
fputs("\e[s", stdout);
|
||||
|
||||
dict_push_random(x, 0, 0);
|
||||
|
||||
dict_info(x, 0);
|
||||
dict_print(x, 0, 0);
|
||||
|
||||
psleep(100000);
|
||||
fputs("\e[u\e[J", stdout);
|
||||
}
|
||||
}
|
||||
|
||||
void visual_remove(dict_t* x) {
|
||||
while (x->size) {
|
||||
fputs("\e[s", stdout);
|
||||
dict_remove_random(x, 0, 0);
|
||||
|
||||
dict_info(x, 0);
|
||||
dict_print(x, 0, 0);
|
||||
|
||||
psleep(100000);
|
||||
fputs("\e[u\e[J", stdout);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/* This software is licensed by the MIT License, see LICENSE file */
|
||||
/* Copyright © 2022 Gregory Lirent */
|
||||
|
||||
#include "../../../../src/__internal/include.h"
|
||||
#include "../../../include/random.h"
|
||||
|
||||
vtype_string* string_duplicate(const vtype_string* x) { return 0; }
|
||||
vtype_array* array_duplicate (const vtype_array* x) { return 0; }
|
||||
vtype_list* list_duplicate (const vtype_list* x) { return 0; }
|
||||
vtype_map* map_duplicate (const vtype_map* x) { return 0; }
|
||||
vtype_set* vset_duplicate (const vtype_set* x) { return 0; }
|
||||
|
||||
void string_free(vtype_string* x) {}
|
||||
void array_free (vtype_array* x) {}
|
||||
void list_free (vtype_list* x) {}
|
||||
void map_free (vtype_map* x) {}
|
||||
void vset_free (vtype_set* x) {}
|
||||
|
||||
int string_compare(const vtype_string* s0, const vtype_string* s1) { return random_int8(); }
|
||||
int array_compare (const vtype_array* s0, const vtype_array* s1) { return random_int8(); }
|
||||
int list_compare (const vtype_list* s0, const vtype_list* s1) { return random_int8(); }
|
||||
int map_compare (const vtype_map* s0, const vtype_map* s1) { return random_int8(); }
|
||||
int vset_compare (const vtype_set* s0, const vtype_set* s1) { return random_int8(); }
|
||||
|
||||
hash_t string_hash(const vtype_string* s) { return 0; }
|
||||
hash_t array_hash (const vtype_array* s) { return 0; }
|
||||
hash_t list_hash (const vtype_list* s) { return 0; }
|
||||
hash_t map_hash (const vtype_map* s) { return 0; }
|
||||
hash_t vset_hash (const vtype_set* s) { return 0; }
|
||||
@@ -0,0 +1,53 @@
|
||||
/* This software is licensed by the MIT License, see LICENSE file */
|
||||
/* Copyright © 2022 Gregory Lirent */
|
||||
|
||||
#include "../plug.h"
|
||||
|
||||
static int remove_callback(const void* k, vtype kt, void* v, vtype vt, void* _) {
|
||||
struct { size_t n; dict_t* x; unsigned int hp; } *d = _;
|
||||
|
||||
if (!d->n--) {
|
||||
print_container_value(0, k, kt, 0, d->hp);
|
||||
|
||||
if (libcdsb_dict_get(d->x, k, kt, 0, 0, 1) == 0) {
|
||||
printf("\e[%dG\e[32;1mSUCCESS\e[m\n", d->hp+1);
|
||||
} else printf("\e[%dG\e[31;1mFAILURE\e[m\n", d->hp+1);
|
||||
|
||||
return -2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dict_push_random(dict_t* x, _Bool silent, unsigned int hpos) {
|
||||
|
||||
value_t k = random_value();
|
||||
value_t v = random_value();
|
||||
|
||||
if (!silent) {
|
||||
printf("\e[%dG\e[36mUpdate value in dict with key:\e[m\n", hpos+1);
|
||||
print_container_value(0, k.value, k.type, 1, hpos);
|
||||
}
|
||||
|
||||
if (libcdsb_dict_update(x, k.value, k.type, v.value, v.type)) {
|
||||
if (!silent) printf("\e[%dG\e[33;1mCHANGE\e[m\n", hpos+1);
|
||||
} else if (!silent) printf("\e[%dG\e[32;1mINSERT\e[m\n", hpos+1);
|
||||
|
||||
if (!silent) put_separator(0);
|
||||
}
|
||||
|
||||
|
||||
void dict_remove_random(dict_t* x, _Bool silent, unsigned int hpos) {
|
||||
struct { size_t n; dict_t* x; unsigned int hp; } d = { .n = dict_size(x), .x = x, .hp = hpos };
|
||||
|
||||
if (!silent)
|
||||
printf("\e[%dG\e[36mTry to remove value from dict by key:\e[m\n", hpos+1);
|
||||
|
||||
if (d.n) {
|
||||
d.n = random_uint32()%d.n;
|
||||
dict_foreach(x, &d, remove_callback);
|
||||
} else if (!silent) {
|
||||
printf("\e[%dG\e[32;1m\nFAILURE\e[m\n", hpos+1);
|
||||
}
|
||||
|
||||
if (!silent) put_separator(hpos);
|
||||
}
|
||||
@@ -8,13 +8,22 @@ vtype_string* string_duplicate(const vtype_string* x) { return 0; }
|
||||
vtype_array* array_duplicate (const vtype_array* x) { return 0; }
|
||||
vtype_map* map_duplicate (const vtype_map* x) { return 0; }
|
||||
vtype_set* vset_duplicate (const vtype_set* x) { return 0; }
|
||||
vtype_dict* dict_duplicate (const vtype_dict* x) { return 0; }
|
||||
|
||||
void string_free(vtype_string* x) {}
|
||||
void array_free (vtype_array* x) {}
|
||||
void map_free (vtype_map* x) {}
|
||||
void vset_free (vtype_set* x) {}
|
||||
void dict_free (vtype_dict* x) {}
|
||||
|
||||
int string_compare(const vtype_string* s0, const vtype_string* s1) { return random_int8(); }
|
||||
int array_compare (const vtype_array* s0, const vtype_array* s1) { return random_int8(); }
|
||||
int map_compare (const vtype_map* s0, const vtype_map* s1) { return random_int8(); }
|
||||
int vset_compare (const vtype_set* s0, const vtype_set* s1) { return random_int8(); }
|
||||
int dict_compare (const vtype_dict* s0, const vtype_dict* s1) { return random_int8(); }
|
||||
|
||||
hash_t string_hash(const vtype_string* s) { return 0; }
|
||||
hash_t array_hash (const vtype_array* s) { return 0; }
|
||||
hash_t map_hash (const vtype_map* s) { return 0; }
|
||||
hash_t vset_hash (const vtype_set* s) { return 0; }
|
||||
hash_t dict_hash (const vtype_dict* s) { return 0; }
|
||||
|
||||
@@ -8,13 +8,22 @@ vtype_string* string_duplicate(const vtype_string* x) { return 0; }
|
||||
vtype_array* array_duplicate (const vtype_array* x) { return 0; }
|
||||
vtype_list* list_duplicate (const vtype_list* x) { return 0; }
|
||||
vtype_set* vset_duplicate (const vtype_set* x) { return 0; }
|
||||
vtype_dict* dict_duplicate (const vtype_dict* x) { return 0; }
|
||||
|
||||
void string_free(vtype_string* x) {}
|
||||
void array_free (vtype_array* x) {}
|
||||
void list_free (vtype_list* x) {}
|
||||
void vset_free (vtype_set* x) {}
|
||||
void dict_free (vtype_dict* x) {}
|
||||
|
||||
int string_compare(const vtype_string* s0, const vtype_string* s1) { return random_int8(); }
|
||||
int array_compare (const vtype_array* s0, const vtype_array* s1) { return random_int8(); }
|
||||
int list_compare (const vtype_list* s0, const vtype_list* s1) { return random_int8(); }
|
||||
int vset_compare (const vtype_set* s0, const vtype_set* s1) { return random_int8(); }
|
||||
int dict_compare (const vtype_dict* s0, const vtype_dict* s1) { return random_int8(); }
|
||||
|
||||
hash_t string_hash(const vtype_string* s) { return 0; }
|
||||
hash_t array_hash (const vtype_array* s) { return 0; }
|
||||
hash_t list_hash (const vtype_list* s) { return 0; }
|
||||
hash_t vset_hash (const vtype_set* s) { return 0; }
|
||||
hash_t dict_hash (const vtype_dict* s) { return 0; }
|
||||
|
||||
@@ -8,13 +8,22 @@ vtype_string* string_duplicate(const vtype_string* x) { return 0; }
|
||||
vtype_array* array_duplicate (const vtype_array* x) { return 0; }
|
||||
vtype_list* list_duplicate (const vtype_list* x) { return 0; }
|
||||
vtype_map* map_duplicate (const vtype_map* x) { return 0; }
|
||||
vtype_dict* dict_duplicate (const vtype_dict* x) { return 0; }
|
||||
|
||||
void string_free(vtype_string* x) {}
|
||||
void array_free (vtype_array* x) {}
|
||||
void list_free (vtype_list* x) {}
|
||||
void map_free (vtype_map* x) {}
|
||||
void dict_free (vtype_dict* x) {}
|
||||
|
||||
int string_compare(const vtype_string* s0, const vtype_string* s1) { return random_int8(); }
|
||||
int array_compare (const vtype_array* s0, const vtype_array* s1) { return random_int8(); }
|
||||
int list_compare (const vtype_list* s0, const vtype_list* s1) { return random_int8(); }
|
||||
int map_compare (const vtype_map* s0, const vtype_map* s1) { return random_int8(); }
|
||||
int dict_compare (const vtype_dict* s0, const vtype_dict* s1) { return random_int8(); }
|
||||
|
||||
hash_t string_hash(const vtype_string* s) { return 0; }
|
||||
hash_t array_hash (const vtype_array* s) { return 0; }
|
||||
hash_t list_hash (const vtype_list* s) { return 0; }
|
||||
hash_t map_hash (const vtype_map* s) { return 0; }
|
||||
hash_t dict_hash (const vtype_dict* s) { return 0; }
|
||||
|
||||
@@ -8,13 +8,22 @@ vtype_array* array_duplicate (const vtype_array* x) { return 0; }
|
||||
vtype_list* list_duplicate (const vtype_list* x) { return 0; }
|
||||
vtype_map* map_duplicate (const vtype_map* x) { return 0; }
|
||||
vtype_set* vset_duplicate (const vtype_set* x) { return 0; }
|
||||
vtype_dict* dict_duplicate (const vtype_dict* x) { return 0; }
|
||||
|
||||
void array_free (vtype_array* x) {}
|
||||
void list_free (vtype_list* x) {}
|
||||
void map_free (vtype_map* x) {}
|
||||
void vset_free (vtype_set* x) {}
|
||||
void dict_free (vtype_dict* x) {}
|
||||
|
||||
int array_compare (const vtype_array* s0, const vtype_array* s1) { return random_int8(); }
|
||||
int list_compare (const vtype_list* s0, const vtype_list* s1) { return random_int8(); }
|
||||
int map_compare (const vtype_map* s0, const vtype_map* s1) { return random_int8(); }
|
||||
int vset_compare (const vtype_set* s0, const vtype_set* s1) { return random_int8(); }
|
||||
int dict_compare (const vtype_dict* s0, const vtype_dict* s1) { return random_int8(); }
|
||||
|
||||
hash_t array_hash (const vtype_array* s) { return 0; }
|
||||
hash_t list_hash (const vtype_list* s) { return 0; }
|
||||
hash_t map_hash (const vtype_map* s) { return 0; }
|
||||
hash_t vset_hash (const vtype_set* s) { return 0; }
|
||||
hash_t dict_hash (const vtype_dict* s) { return 0; }
|
||||
|
||||
Reference in New Issue
Block a user