98 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			98 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /* This software is licensed by the MIT License, see LICENSE file */
 | |
| /*                                Copyright © 2022 Gregory Lirent */
 | |
| 
 | |
| #include <string.h>
 | |
| #include "../../../include/extra/vtype.h"
 | |
| #include "../../../include/extra/array.h"
 | |
| 
 | |
| #include "../../include/random.h"
 | |
| #include "../../include/test.h"
 | |
| #include "../../include/time.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; }
 | |
| 
 | |
| void string_free(vtype_string* 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 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(); }
 | |
| 
 | |
| 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)); }
 | |
| 
 | |
| 
 | |
| static void array_push_random(vtype_array* x) {
 | |
|     switch (random_uint8()%13) {
 | |
|         default:
 | |
|         case  0: array_push(x, random_boolean()); break;
 | |
|         case  1: array_push(x, random_uint8());   break;
 | |
|         case  2: array_push(x, random_uint16());  break;
 | |
|         case  3: array_push(x, random_uint32());  break;
 | |
|         case  4: array_push(x, random_uint64());  break;
 | |
|         case  5: array_push(x, random_int8());    break;
 | |
|         case  6: array_push(x, random_int16());   break;
 | |
|         case  7: array_push(x, random_int32());   break;
 | |
|         case  8: array_push(x, random_int64());   break;
 | |
|         case  9: array_push(x, (void*)((sizeof(void*) == 8) ? random_uint64() : random_uint32())); break;
 | |
|         case 10: array_push(x, random_float());   break;
 | |
|         case 11: array_push(x, random_double());  break;
 | |
|         case 12: array_push(x, random_ldouble()); break;
 | |
|     }
 | |
| }
 | |
| 
 | |
| static void array_init_random(vtype_array* x) {
 | |
|     switch (random_uint8()%13) {
 | |
|         default:
 | |
|         case  0: array_init(x, VTYPE_BOOLEAN); break;
 | |
|         case  1: array_init(x, VTYPE_UINT8);   break;
 | |
|         case  2: array_init(x, VTYPE_UINT16);  break;
 | |
|         case  3: array_init(x, VTYPE_UINT32);  break;
 | |
|         case  4: array_init(x, VTYPE_UINT64);  break;
 | |
|         case  5: array_init(x, VTYPE_INT8);    break;
 | |
|         case  6: array_init(x, VTYPE_INT16);   break;
 | |
|         case  7: array_init(x, VTYPE_INT32);   break;
 | |
|         case  8: array_init(x, VTYPE_INT64);   break;
 | |
|         case  9: array_init(x, VTYPE_POINTER); break;
 | |
|         case 10: array_init(x, VTYPE_FLOAT);   break;
 | |
|         case 11: array_init(x, VTYPE_DOUBLE);  break;
 | |
|         case 12: array_init(x, VTYPE_LDOUBLE); break;
 | |
|     }
 | |
| }
 | |
| 
 | |
| static vtype_array array_random(unsigned int n) {
 | |
|     vtype_array x;
 | |
| 
 | |
|     array_init_random(&x);
 | |
| 
 | |
|     for (int i = 0; i < n; ++i) {
 | |
|         array_push_random(&x);
 | |
|     }
 | |
| 
 | |
|     return x;
 | |
| }
 | |
| 
 | |
| static int array_value_print(void* v, ssize_t i, vtype t, void* _) {
 | |
|     print_container_value(&i, v, t, false);
 | |
|     return 0;
 | |
| }
 | |
| 
 | |
| static void array_print(const vtype_array* x, const char* prefix) {
 | |
|     print_container_values_prefix("Array", prefix);
 | |
|     array_foreach(x, 0, array_value_print);
 | |
|     put_separator();
 | |
| }
 | |
| 
 | |
| static void array_info(const vtype_array* x) {
 | |
|     print_container_info("Array", 0, &x->type, array_size(x), array_nmemb(x));
 | |
|     put_separator();
 | |
| }
 |