Add copy array with allocation and finish writing array tests
This commit is contained in:
@@ -122,3 +122,108 @@ TestFuncResult test_i32_array_pop(void) {
|
||||
|
||||
return wapp_tester_result(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_copy_capped(void) {
|
||||
bool result;
|
||||
|
||||
I32Array src = wapp_i32_array(1, 2, 3, 4, 5);
|
||||
I32Array dst1 = wapp_i32_array(1, 2, 3, 4, 5, 6);
|
||||
I32Array dst2 = wapp_i32_array(1, 2);
|
||||
|
||||
u64 expected_count = 5;
|
||||
wapp_i32_array_copy_capped(&src, &dst1);
|
||||
result = dst1.count == expected_count;
|
||||
for (u64 i = 0; i < expected_count; ++i) {
|
||||
result = result && (*wapp_i32_array_get(&src, i) == *wapp_i32_array_get(&dst1, i));
|
||||
}
|
||||
|
||||
expected_count = 4;
|
||||
wapp_i32_array_copy_capped(&src, &dst2);
|
||||
result = result && dst2.count == expected_count;
|
||||
for (u64 i = 0; i < expected_count; ++i) {
|
||||
result = result && (*wapp_i32_array_get(&src, i) == *wapp_i32_array_get(&dst2, i));
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_alloc_capacity(void) {
|
||||
bool result;
|
||||
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(MB(4));
|
||||
u64 capacity = 32;
|
||||
I32Array *array = wapp_i32_array_alloc_capacity(&allocator, capacity);
|
||||
|
||||
result = array && array->capacity == capacity;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_append_alloc(void) {
|
||||
bool result;
|
||||
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(MB(4));
|
||||
I32Array array1 = wapp_i32_array(1, 2, 3, 4, 5, 6, 7, 8);
|
||||
I32Array array2 = wapp_i32_array(1, 2);
|
||||
|
||||
I32Array *arr_ptr = wapp_i32_array_append_alloc(&allocator, &array1, 10);
|
||||
result = arr_ptr == &array1;
|
||||
|
||||
for (u64 i = 0; i < 4; ++i) {
|
||||
arr_ptr = wapp_i32_array_append_alloc(&allocator, &array2, (i32)i);
|
||||
}
|
||||
result = result && arr_ptr != &array2;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_extend_alloc(void) {
|
||||
bool result;
|
||||
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(MB(4));
|
||||
I32Array array1 = wapp_i32_array(1, 2, 3, 4, 5, 6, 7, 8);
|
||||
I32Array array2 = wapp_i32_array(1, 2);
|
||||
I32Array array3 = wapp_i32_array(1, 2, 3, 4);
|
||||
|
||||
I32Array *arr_ptr = wapp_i32_array_extend_alloc(&allocator, &array1, &array3);
|
||||
result = arr_ptr == &array1;
|
||||
|
||||
arr_ptr = wapp_i32_array_extend_alloc(&allocator, &array2, &array3);
|
||||
result = result && arr_ptr != &array2;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_copy_alloc(void) {
|
||||
bool result;
|
||||
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(MB(4));
|
||||
I32Array src = wapp_i32_array(1, 2, 3, 4, 5);
|
||||
I32Array dst1 = wapp_i32_array(1, 2, 3, 4, 5, 6);
|
||||
I32Array dst2 = wapp_i32_array(1, 2);
|
||||
I32Array *array_ptr = NULL;
|
||||
|
||||
u64 expected_count = 5;
|
||||
array_ptr = wapp_i32_array_copy_alloc(&allocator, &src, &dst1);
|
||||
result = array_ptr->count == expected_count && array_ptr == &dst1;
|
||||
for (u64 i = 0; i < expected_count; ++i) {
|
||||
result = result && (*wapp_i32_array_get(&src, i) == *wapp_i32_array_get(array_ptr, i));
|
||||
}
|
||||
|
||||
expected_count = 5;
|
||||
array_ptr = wapp_i32_array_copy_alloc(&allocator, &src, &dst2);
|
||||
result = result && array_ptr->count == expected_count && array_ptr != &dst2;
|
||||
for (u64 i = 0; i < expected_count; ++i) {
|
||||
result = result && (*wapp_i32_array_get(&src, i) == *wapp_i32_array_get(array_ptr, i));
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
}
|
||||
|
@@ -15,6 +15,11 @@ TestFuncResult test_i32_array_append_capped(void);
|
||||
TestFuncResult test_i32_array_extend_capped(void);
|
||||
TestFuncResult test_i32_array_clear(void);
|
||||
TestFuncResult test_i32_array_pop(void);
|
||||
TestFuncResult test_i32_array_copy_capped(void);
|
||||
TestFuncResult test_i32_array_alloc_capacity(void);
|
||||
TestFuncResult test_i32_array_append_alloc(void);
|
||||
TestFuncResult test_i32_array_extend_alloc(void);
|
||||
TestFuncResult test_i32_array_copy_alloc(void);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
@@ -26,6 +26,11 @@ int main(void) {
|
||||
test_i32_array_extend_capped,
|
||||
test_i32_array_clear,
|
||||
test_i32_array_pop,
|
||||
test_i32_array_copy_capped,
|
||||
test_i32_array_alloc_capacity,
|
||||
test_i32_array_append_alloc,
|
||||
test_i32_array_extend_alloc,
|
||||
test_i32_array_copy_alloc,
|
||||
test_str8_lit,
|
||||
test_str8_lit_ro,
|
||||
test_str8_buf,
|
||||
|
Reference in New Issue
Block a user