Update map tests

This commit is contained in:
Gregory Lirent 2022-06-10 21:17:07 +03:00
parent 41c220b507
commit d57f5ed2c6
3 changed files with 41 additions and 41 deletions

View File

@ -10,7 +10,6 @@
void map_push_random(map_t* x, _Bool silent, unsigned int hpos); void map_push_random(map_t* x, _Bool silent, unsigned int hpos);
void map_remove_random(map_t* x, _Bool silent, unsigned int hpos); void map_remove_random(map_t* x, _Bool silent, unsigned int hpos);
void rbtree_print(const mnode_t* s, vtype t, const char* ind, bool br);
void map_print(map_t* x, const char* prefix, unsigned int hpos); void map_print(map_t* x, const char* prefix, unsigned int hpos);
void map_info(const map_t* x, unsigned int hpos); void map_info(const map_t* x, unsigned int hpos);
void map_rbtree_print(map_t *x, const char* prefix, unsigned int hpos); void map_rbtree_print(map_t *x, const char* prefix, unsigned int hpos);

View File

@ -8,6 +8,39 @@ static int node_print_callback(const void* k, vtype kt, void* v, vtype vt, void*
return 0; return 0;
} }
static void rbtree_print(const mnode_t* s, vtype t, const char* ind, bool br, unsigned int hpos) {
if (!ind) {
ind = "\e[36m";
br = 1;
}
size_t n = strlen(ind);
char x[n + 10];
if (mnode_is_empty(s)) return;
memcpy(x, ind, n);
memcpy(x + n, " \0 ", 9);
printf("\e[%dG%s", hpos+1, ind);
if (br) {
fputs("\e[m\e[36;1mR\e[m\e[36m────\e[m", stdout);
} else {
fputs("\e[m\e[36;1mL\e[m\e[36m────\e[m", stdout);
memcpy(x + n, "", 3);
x[n + 5] = ' ';
}
fputs((s->colored) ? "\e[31;1m" : "\e[37m", stdout);
printf("%s\e[m \e[36m:\e[m ", vnode_stringify(&s->key, t));
printf("\e[31m%s\e[m", vnode_stringify(&s->value, s->type));
printf(" \e[36m(\e[m\e[32;1m%s\e[m\e[36m)\e[m\n", vtype_name(s->type));
rbtree_print(s->left, t, x, false, hpos);
rbtree_print(s->right, t, x, true, hpos);
}
void map_print(map_t* x, const char* prefix, unsigned int hpos) { void map_print(map_t* x, const char* prefix, unsigned int hpos) {
print_container_values_prefix("Map", prefix, 0); print_container_values_prefix("Map", prefix, 0);
map_foreach(x, &hpos, node_print_callback); map_foreach(x, &hpos, node_print_callback);
@ -21,41 +54,9 @@ void map_info(const map_t* x, unsigned int hpos) {
void map_rbtree_print(map_t *x, const char* prefix, unsigned int hpos) { void map_rbtree_print(map_t *x, const char* prefix, unsigned int hpos) {
print_container_values_prefix("Map", prefix, 0); print_container_values_prefix("Map", prefix, 0);
rbtree_print(x->root, x->type, 0, 0); rbtree_print(x->root, x->type, 0, 0, hpos);
} }
void rbtree_print(const mnode_t* s, vtype t, const char* ind, bool br) {
if (!ind) {
ind = "\e[36m";
br = 1;
}
size_t n = strlen(ind);
char x[n + 10];
if (mnode_is_empty(s)) return;
memcpy(x, ind, n);
memcpy(x + n, " \0 ", 9);
fputs(ind, stdout);
if (br) {
fputs("\e[m\e[36;1mR\e[m\e[36m────\e[m", stdout);
} else {
fputs("\e[m\e[36;1mL\e[m\e[36m────\e[m", stdout);
memcpy(x + n, "", 3);
x[n + 5] = ' ';
}
fputs((s->colored) ? "\e[31;1m" : "\e[37m", stdout);
printf("%s\e[m \e[36m:\e[m ", vnode_stringify(&s->key, t));
printf("\e[31m%s\e[m", vnode_stringify(&s->value, s->type));
printf(" \e[36m(\e[m\e[32;1m%s\e[m\e[36m)\e[m\n", vtype_name(s->type));
rbtree_print(s->left, t, x, false);
rbtree_print(s->right, t, x, true);
}
void visual_push(map_t* x, size_t n) { void visual_push(map_t* x, size_t n) {
while (n--) { while (n--) {
@ -64,7 +65,7 @@ void visual_push(map_t* x, size_t n) {
map_push_random(x, 0, 0); map_push_random(x, 0, 0);
map_info(x, 0); map_info(x, 0);
rbtree_print(x->root, x->type, 0, 0); map_rbtree_print(x, 0, 0);
psleep(100000); psleep(100000);
fputs("\e[u\e[J", stdout); fputs("\e[u\e[J", stdout);
@ -76,7 +77,7 @@ void visual_remove(map_t* x) {
fputs("\e[s", stdout); fputs("\e[s", stdout);
map_remove_random(x, 0, 0); map_remove_random(x, 0, 0);
map_info(x, 0); map_info(x, 0);
rbtree_print(x->root, x->type, 0, 0); map_rbtree_print(x, 0, 0);
psleep(100000); psleep(100000);
fputs("\e[u\e[J", stdout); fputs("\e[u\e[J", stdout);
} }

View File

@ -9,9 +9,9 @@ static int remove_callback(const void* k, vtype kt, void* v, vtype vt, void* _)
if (!d->n--) { if (!d->n--) {
print_container_value(0, k, kt, 0, d->hp); print_container_value(0, k, kt, 0, d->hp);
if (libcdsb_map_find(d->x, k, kt, 0, 0, 1)) { if (libcdsb_map_find(d->x, k, kt, 0, 0, 1) == 0) {
printf("\e[%dG\e[32;1mSUCCESS\e[m", d->hp+1); printf("\e[%dG\e[32;1mSUCCESS\e[m\n", d->hp+1);
} else printf("\e[%dG\e[31;1mFAILURE\e[m", d->hp+1); } else printf("\e[%dG\e[31;1mFAILURE\e[m\n", d->hp+1);
return -2; return -2;
} }
@ -29,8 +29,8 @@ void map_push_random(map_t* x, _Bool silent, unsigned int hpos) {
} }
if (libcdsb_map_update(x, k.value, k.type, v.value, v.type)) { if (libcdsb_map_update(x, k.value, k.type, v.value, v.type)) {
if (!silent) printf("\e[%dG\\e[33;1mCHANGE\e[m", hpos+1); if (!silent) printf("\e[%dG\e[33;1mCHANGE\e[m\n", hpos+1);
} else if (!silent) printf("\e[%dG\\e[32;1mINSERT\e[m", hpos+1); } else if (!silent) printf("\e[%dG\e[32;1mINSERT\e[m\n", hpos+1);
if (!silent) put_separator(0); if (!silent) put_separator(0);
} }