2022-06-02 22:23:01 +03:00
|
|
|
/* This software is licensed by the MIT License, see LICENSE file */
|
|
|
|
/* Copyright © 2022 Gregory Lirent */
|
|
|
|
|
2022-06-05 18:31:19 +03:00
|
|
|
#include "../../../include/extra/list.h"
|
2022-06-02 22:23:01 +03:00
|
|
|
|
|
|
|
#include "../../include/random.h"
|
|
|
|
#include "../../include/test.h"
|
|
|
|
#include "../../include/time.h"
|
|
|
|
|
2022-06-05 18:31:19 +03:00
|
|
|
#include "../../../src/__internal/vnode.h"
|
|
|
|
|
2022-06-02 22:23:01 +03:00
|
|
|
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; }
|
|
|
|
|
|
|
|
void string_free(vtype_string* x) {}
|
|
|
|
void array_free (vtype_array* 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 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(); }
|
2022-06-05 18:31:19 +03:00
|
|
|
|
|
|
|
|
|
|
|
static void list_push_random(vtype_list* x, vtype_bool front) {
|
|
|
|
|
|
|
|
if (!front) switch (random_uint8()%13) {
|
|
|
|
default:
|
|
|
|
case 0: list_push_back(x, random_boolean()); break;
|
|
|
|
case 1: list_push_back(x, random_uint8()); break;
|
|
|
|
case 2: list_push_back(x, random_uint16()); break;
|
|
|
|
case 3: list_push_back(x, random_uint32()); break;
|
|
|
|
case 4: list_push_back(x, random_uint64()); break;
|
|
|
|
case 5: list_push_back(x, random_int8()); break;
|
|
|
|
case 6: list_push_back(x, random_int16()); break;
|
|
|
|
case 7: list_push_back(x, random_int32()); break;
|
|
|
|
case 8: list_push_back(x, random_int64()); break;
|
|
|
|
case 9: list_push_back(x, (void*)((sizeof(void*) == 8) ? random_uint64() : random_uint32())); break;
|
|
|
|
case 10: list_push_back(x, random_float()); break;
|
|
|
|
case 11: list_push_back(x, random_double()); break;
|
|
|
|
case 12: list_push_back(x, random_ldouble()); break;
|
|
|
|
} else switch (random_uint8()%13) {
|
|
|
|
default:
|
|
|
|
case 0: list_push_front(x, random_boolean()); break;
|
|
|
|
case 1: list_push_front(x, random_uint8()); break;
|
|
|
|
case 2: list_push_front(x, random_uint16()); break;
|
|
|
|
case 3: list_push_front(x, random_uint32()); break;
|
|
|
|
case 4: list_push_front(x, random_uint64()); break;
|
|
|
|
case 5: list_push_front(x, random_int8()); break;
|
|
|
|
case 6: list_push_front(x, random_int16()); break;
|
|
|
|
case 7: list_push_front(x, random_int32()); break;
|
|
|
|
case 8: list_push_front(x, random_int64()); break;
|
|
|
|
case 9: list_push_front(x, (void*)((sizeof(void*) == 8) ? random_uint64() : random_uint32())); break;
|
|
|
|
case 10: list_push_front(x, random_float()); break;
|
|
|
|
case 11: list_push_front(x, random_double()); break;
|
|
|
|
case 12: list_push_front(x, random_ldouble()); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-07 21:24:17 +03:00
|
|
|
static int list_node_print(void* v, ssize_t i, vtype t, void* _) {
|
2022-06-06 22:07:35 +03:00
|
|
|
print_container_value(&i, v, t, 1);
|
2022-06-05 18:31:19 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void list_print(const vtype_list* x, const char* prefix) {
|
2022-06-06 22:07:35 +03:00
|
|
|
print_container_values_prefix("List", prefix);
|
2022-06-07 21:24:17 +03:00
|
|
|
list_foreach(x, 0, list_node_print);
|
2022-06-05 18:31:19 +03:00
|
|
|
put_separator();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void list_info(const vtype_list* x) {
|
2022-06-06 22:07:35 +03:00
|
|
|
print_container_info("List", "nodes", 0, list_size(x), -1);
|
2022-06-05 18:31:19 +03:00
|
|
|
put_separator();
|
|
|
|
}
|