Update tests

This commit is contained in:
Gregory Lirent 2022-08-24 12:32:06 +03:00
parent 804769d85c
commit f78d7f7ed9
11 changed files with 69 additions and 64 deletions

View File

@ -51,6 +51,8 @@ tests: $(addprefix $(BUILD_PATH)/global-,$(notdir $(basename $(wildcard ./src/gl
########################################################################################################################
CFLAGS:=$(CFLAGS) ../modules/libunic/bin/libunic.a
$(BUILD_PATH)/obj/%.o: ./src/%.c | $(BUILD_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS)
@ -72,7 +74,7 @@ $(BUILD_PATH)/obj/global-%.o: ./src/global/src/%.c | $(BUILD_PATH)/obj/
$(BUILD_PATH)/array-%: ./src/array/%.c $(OBJECTS_ARRAY) | $(BUILD_PATH)/
$(CC) $^ -o $@ $(CFLAGS) -g3 -Wall
$(BUILD_PATH)/string-%: ./src/string/%.c $(OBJECTS_STRING) | $(BUILD_PATH)/
$(CC) $^ -o $@ ../modules/libunic/bin/libunic.a $(CFLAGS) -g3 -Wall
$(CC) $^ -o $@ $(CFLAGS) -g3 -Wall
$(BUILD_PATH)/list-%: ./src/list/%.c $(OBJECTS_LIST) | $(BUILD_PATH)/
$(CC) $^ -o $@ $(CFLAGS) -g3 -Wall
$(BUILD_PATH)/map-%: ./src/map/%.c $(OBJECTS_MAP) | $(BUILD_PATH)/
@ -82,7 +84,7 @@ $(BUILD_PATH)/set-%: ./src/set/%.c $(OBJECTS_SET) | $(BUILD_PATH)/
$(BUILD_PATH)/dict-%: ./src/dict/%.c $(OBJECTS_DICT) | $(BUILD_PATH)/
$(CC) $^ -o $@ $(CFLAGS) -g3 -Wall
$(BUILD_PATH)/global-%: ./src/global/%.c $(OBJECTS_GLOBAL) | $(BUILD_PATH)/
$(CC) $^ ../bin/debug/libcdsb.a ../modules/libunic/bin/libunic.a -o $@ $(CFLAGS) -g3 -Wall
$(CC) $^ ../bin/debug/libcdsb.a -o $@ $(CFLAGS) -g3 -Wall
########################################################################################################################

View File

@ -2,7 +2,7 @@
/* Copyright © 2022 Gregory Lirent */
#include <string.h>
#include "../../../include/extra/vtype.h"
#include "../../../include/vtype.h"
#include "../../../include/array.h"
#include "../../include/random.h"

View File

@ -2,16 +2,14 @@
/* Copyright © 2022 Gregory Lirent */
#include <string.h>
#include "../../../../include/extra/vtype.h"
#include "../../../../include/vtype.h"
#include "../../../include/random.h"
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) {}
@ -29,7 +27,6 @@ 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)); }

View File

@ -31,7 +31,7 @@ void array_push_random(arr_t* x, _Bool silent, unsigned int hpos) {
printf("\e[%dG\e[36mTry to push value to back of the array:\e[m\n", hpos+1);
}
r = libcdsb_array_push(x, _.v.value, _.v.type) >= 0;
r = libcdsb_array_insert(x, _.v.value, _.v.type) >= 0;
} else {
ssize_t i = array_size(x);

View File

@ -4,13 +4,11 @@
#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) {}

View File

@ -1,7 +1,7 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "../../../include/extra/string.h"
#include "../../../include/string.h"
#include "../../../include/array.h"
#include "../../../include/list.h"
#include "../../../include/set.h"

View File

@ -80,30 +80,34 @@ static arr_t random_array(bool embd) {
size_t n = random_uint16()%((!embd)?MAX_ELEMENTS:100);
value_t v = (!embd) ? random_value2() : real_random_value(1);
void (*callback)(void*);
switch (v.type) {
default: callback = nullptr; break;
case VTYPE_STRING: callback = (void*)string_free; break;
case VTYPE_ARRAY: callback = (void*)array_free; break;
case VTYPE_LIST: callback = (void*)list_free; break;
case VTYPE_MAP: callback = (void*)map_free; break;
case VTYPE_SET: callback = (void*)vset_free; break;
case VTYPE_DICT: callback = (void*)dict_free; break;
}
array_init(&x, v.type);
while(n--) {
libcdsb_array_push(&x, v.value, v.type);
libcdsb_array_insert(&x, v.value, v.type);
if (callback) callback(v.value);
switch (v.type) {
default: break;
case VTYPE_STRING: string_free((void*)v.value); break;
case VTYPE_ARRAY: array_free((void*)v.value); break;
case VTYPE_LIST: list_free((void*)v.value); break;
case VTYPE_MAP: map_free((void*)v.value); break;
case VTYPE_SET: vset_free((void*)v.value); break;
case VTYPE_DICT: dict_free((void*)v.value); break;
}
v = random_value_by_type(v.type, 1);
}
if (callback) callback(v.value);
switch (v.type) {
default: break;
case VTYPE_STRING: string_free((void*)v.value); break;
case VTYPE_ARRAY: array_free((void*)v.value); break;
case VTYPE_LIST: list_free((void*)v.value); break;
case VTYPE_MAP: map_free((void*)v.value); break;
case VTYPE_SET: vset_free((void*)v.value); break;
case VTYPE_DICT: dict_free((void*)v.value); break;
}
return x;
}
@ -113,30 +117,35 @@ static set_t random_set(bool embd) {
size_t n = random_uint16()%((!embd)?MAX_ELEMENTS:100);
value_t v = (!embd) ? random_value2() : real_random_value(1);
void (*callback)(void*);
switch (v.type) {
default: callback = nullptr; break;
case VTYPE_STRING: callback = (void*)string_free; break;
case VTYPE_ARRAY: callback = (void*)array_free; break;
case VTYPE_LIST: callback = (void*)list_free; break;
case VTYPE_MAP: callback = (void*)map_free; break;
case VTYPE_SET: callback = (void*)vset_free; break;
case VTYPE_DICT: callback = (void*)dict_free; break;
}
vset_init(&x, v.type);
while(n--) {
libcdsb_vset_insert(&x, v.value, v.type);
if (callback) callback(v.value);
switch (v.type) {
default: break;
case VTYPE_STRING: string_free((void*)v.value); break;
case VTYPE_ARRAY: array_free((void*)v.value); break;
case VTYPE_LIST: list_free((void*)v.value); break;
case VTYPE_MAP: map_free((void*)v.value); break;
case VTYPE_SET: vset_free((void*)v.value); break;
case VTYPE_DICT: dict_free((void*)v.value); break;
}
v = random_value_by_type(v.type, 1);
}
if (callback) callback(v.value);
switch (v.type) {
default: break;
case VTYPE_STRING: string_free((void*)v.value); break;
case VTYPE_ARRAY: array_free((void*)v.value); break;
case VTYPE_LIST: list_free((void*)v.value); break;
case VTYPE_MAP: map_free((void*)v.value); break;
case VTYPE_SET: vset_free((void*)v.value); break;
case VTYPE_DICT: dict_free((void*)v.value); break;
}
return x;
}
@ -149,7 +158,7 @@ static list_t random_list(bool embd) {
while(n--) {
v = (!embd) ? random_value2() : real_random_value(1);
libcdsb_list_update(&x, -1, v.value, v.type, 1);
libcdsb_list_insert(&x, -1, v.value, v.type, 1);
switch (v.type) {
default: break;
@ -170,18 +179,6 @@ static map_t random_map(bool embd) {
size_t n = random_uint16()%((!embd)?MAX_ELEMENTS:100);
value_t k = (!embd) ? random_value2() : real_random_value(1);
void (*callback)(void*);
switch (k.type) {
default: callback = nullptr; break;
case VTYPE_STRING: callback = (void*)string_free; break;
case VTYPE_ARRAY: callback = (void*)array_free; break;
case VTYPE_LIST: callback = (void*)list_free; break;
case VTYPE_MAP: callback = (void*)map_free; break;
case VTYPE_SET: callback = (void*)vset_free; break;
case VTYPE_DICT: callback = (void*)dict_free; break;
}
map_init(&x, k.type);
while(n--) {
@ -189,7 +186,15 @@ static map_t random_map(bool embd) {
libcdsb_map_update(&x, k.value, k.type, v.value, v.type);
if (callback) callback(k.value);
switch (k.type) {
default: break;
case VTYPE_STRING: string_free((void*)k.value); break;
case VTYPE_ARRAY: array_free((void*)k.value); break;
case VTYPE_LIST: list_free((void*)k.value); break;
case VTYPE_MAP: map_free((void*)k.value); break;
case VTYPE_SET: vset_free((void*)k.value); break;
case VTYPE_DICT: dict_free((void*)k.value); break;
}
switch (v.type) {
default: break;
@ -204,7 +209,16 @@ static map_t random_map(bool embd) {
k = random_value_by_type(k.type, 1);
}
if (callback) callback(k.value);
switch (k.type) {
default: break;
case VTYPE_STRING: string_free((void*)k.value); break;
case VTYPE_ARRAY: array_free((void*)k.value); break;
case VTYPE_LIST: list_free((void*)k.value); break;
case VTYPE_MAP: map_free((void*)k.value); break;
case VTYPE_SET: vset_free((void*)k.value); break;
case VTYPE_DICT: dict_free((void*)k.value); break;
}
return x;
}

View File

@ -4,13 +4,11 @@
#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_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) {}

View File

@ -26,12 +26,12 @@ void list_push_random(list_t* x, _Bool silent, unsigned int hpos) {
if (!silent) {
printf("\e[%dG\e[36mTry to push value to back of the list:\e[m\n", hpos+1);
}
r = libcdsb_list_update(x, -1, v.value, v.type, 1);
r = libcdsb_list_insert(x, -1, v.value, v.type, 1);
} else if (random_boolean()) {
if (!silent) {
printf("\e[%dG\e[36mTry to push value to front of the list:\e[m\n", hpos+1);
}
r = libcdsb_list_update(x, -1, v.value, v.type, 1);
r = libcdsb_list_insert(x, -1, v.value, v.type, 1);
} else {
ssize_t i = list_size(x);
i = random_uint64()% (i ? i : 1);
@ -41,7 +41,7 @@ void list_push_random(list_t* x, _Bool silent, unsigned int hpos) {
printf("\e[%dG\e[36mTry to change value with index \e[32;1m%ld\e[36m in the list:\e[m\n", hpos+1, i);
}
r = libcdsb_list_update(x, i, v.value, v.type, 0);
r = libcdsb_list_insert(x, i, v.value, v.type, 0);
}
if (!silent) {

View File

@ -4,13 +4,11 @@
#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_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) {}

View File

@ -4,13 +4,11 @@
#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_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) {}