Files
wizapp-stdlib/tests/array/test_i32_array.cc
T
abdelrahman a998f6b981
Release / release (push) Successful in 8s
Standardize naming conventions (#12)
## Summary

Standardize naming conventions across the entire wizapp-stdlib codebase by replacing inconsistent prefixes and snake_case with a unified `wp` prefix + CamelCase scheme.

## Changes

### Naming convention applied

| Pattern | Before | After |
|---|---|---|
| Public functions | `wapp_module_function` | `wpModuleFunction` |
| Public types | `GenericXxx`, bare `Xxx` | `WpXxx` |
| Constants / enum values | `WAPP_XXX`, `SHELL_XXX` | `WP_XXX`, `WP_SHELL_XXX` |
| Internal functions | `_module_function` | `_moduleFunction` |
| Storage-class macros | `wapp_extern`, `wapp_intern` | `wp_extern`, `wp_intern` |

### Modules affected

All 20 modules were renamed: `arena`, `array`, `dbl_list`, `queue`, `str8`, `mem_allocator`, `mem_utils`, `mem_os`, `file`, `cpath`, `log`, `shell_commander`, `shell_termcolour`, `shell_utils`, `prng/xorshift`, `uuid`, `tester`, `aliases`, `assert`, `misc_utils`, `platform` — plus their test files.

### Backward compatibility

Added `src/oldnames.h` with `#define OLD_NAME NEW_NAME` for every renamed symbol, organized by module under Constants → Types → Functions sections. Existing code that includes this file will compile without changes.

Reviewed-on: #12
Co-authored-by: Abdelrahman <said.abdelrahman89@gmail.com>
Co-committed-by: Abdelrahman <said.abdelrahman89@gmail.com>
2026-06-26 17:17:27 +00:00

277 lines
6.7 KiB
C++

#include "test_i32_array.h"
#include "wapp.h"
WpTestFuncResult test_i32_array(void) {
b8 result;
WpI32Array array = wpArray(i32, 1, 2, 3, 4, 5, 6, 7);
result = wpArrayCount(array) == 7 && wpArrayCapacity(array) == 16;
i32 *item;
u64 count = wpArrayCount(array);
u64 index = 0;
b8 running = true;
while (running) {
item = wpArrayGet(i32, array, index);
result = result && item && (*item == (i32)(index + 1));
++index;
running = index < count;
}
return wpTesterResult(result);
}
WpTestFuncResult test_i32_array_with_capacity(void) {
b8 result;
WpI32Array array1 = wpArrayWithCapacity(i32, 64, WP_ARRAY_INIT_NONE);
result = wpArrayCount(array1) == 0 && wpArrayCapacity(array1) == 64;
WpI32Array array2 = wpArrayWithCapacity(i32, 64, WP_ARRAY_INIT_FILLED);
result = wpArrayCount(array2) == 64 && wpArrayCapacity(array2) == 64;
return wpTesterResult(result);
}
WpTestFuncResult test_i32_array_get(void) {
b8 result = true;
WpI32Array array = wpArray(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
i32 *item;
u64 count = wpArrayCount(array);
u64 index = 0;
b8 running = true;
while (running) {
item = wpArrayGet(i32, array, index);
result = result && item && (*item == (i32)index);
++index;
running = index < count;
}
return wpTesterResult(result);
}
WpTestFuncResult test_i32_array_set(void) {
b8 result = true;
WpI32Array array = wpArray(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
i32 *item;
u64 count = wpArrayCount(array);
u64 index = 0;
b8 running = true;
while (running) {
i32 num = (i32)(index * 2);
wpArraySet(i32, array, index, &num);
item = wpArrayGet(i32, array, index);
result = result && item && (*item == (i32)(index * 2));
++index;
running = index < count;
}
return wpTesterResult(result);
}
WpTestFuncResult test_i32_array_append_capped(void) {
b8 result;
WpI32Array array = wpArrayWithCapacity(i32, 64, WP_ARRAY_INIT_NONE);
i32 item1 = 10;
wpArrayAppendCapped(i32, array, &item1);
result = wpArrayCount(array) == 1;
i32 *item = wpArrayGet(i32, array, 0);
result = result && item && *item == 10;
array = wpArray(i32, 1);
i32 item2 = 10;
wpArrayAppendCapped(i32, array, &item2);
result = result && wpArrayCount(array) == 2;
return wpTesterResult(result);
}
WpTestFuncResult test_i32_array_extend_capped(void) {
b8 result;
WpI32Array array1 = wpArray(i32, 1, 2, 3, 4);
WpI32Array array2 = wpArray(i32, 10, 20);
result = wpArrayCount(array1) == 4 && wpArrayCount(array2) == 2;
wpArrayExtendCapped(i32, array1, array2);
result = result && wpArrayCount(array1) == 6;
return wpTesterResult(result);
}
WpTestFuncResult test_i32_array_copy_capped(void) {
b8 result;
WpI32Array src = wpArray(i32, 1, 2, 3, 4, 5);
WpI32Array dst1 = wpArray(i32, 1, 2, 3, 4, 5, 6);
WpI32Array dst2 = wpArray(i32, 1, 2);
u64 expected_count = 5;
wpArrayCopyCapped(i32, dst1, src);
result = wpArrayCount(dst1) == expected_count;
u64 index = 0;
b8 running = true;
while (running) {
result = result && (*wpArrayGet(i32, src, index) == *wpArrayGet(i32, dst1, index));
++index;
running = index < expected_count;
}
expected_count = 4;
wpArrayCopyCapped(i32, dst2, src);
result = result && wpArrayCount(dst2) == expected_count;
index = 0;
running = true;
while (running) {
result = result && (*wpArrayGet(i32, src, index) == *wpArrayGet(i32, dst2, index));
++index;
running = index < expected_count;
}
return wpTesterResult(result);
}
WpTestFuncResult test_i32_array_alloc_capacity(void) {
b8 result;
WpAllocator allocator = wpMemArenaAllocatorInit(MiB(4));
u64 capacity = 32;
WpI32Array array = wpArrayAllocCapacity(i32, &allocator, capacity, WP_ARRAY_INIT_NONE);
result = array && wpArrayCapacity(array) == capacity;
wpMemArenaAllocatorDestroy(&allocator);
return wpTesterResult(result);
}
WpTestFuncResult test_i32_array_append_alloc(void) {
b8 result;
WpAllocator allocator = wpMemArenaAllocatorInit(MiB(4));
WpI32Array array1 = wpArray(i32, 1, 2, 3, 4, 5, 6, 7, 8);
WpI32Array array2 = wpArray(i32, 1, 2);
i32 num = 10;
WpI32Array arr_ptr = wpArrayAppendAlloc(i32, &allocator, array1, &num, WP_ARRAY_INIT_NONE);
result = arr_ptr == array1;
u64 count = 4;
u64 index = 0;
b8 running = true;
while (running) {
num = (i32)index;
arr_ptr = wpArrayAppendAlloc(i32, &allocator, array2, &num, WP_ARRAY_INIT_NONE);
++index;
running = index < count;
}
result = result && arr_ptr != array2;
wpMemArenaAllocatorDestroy(&allocator);
return wpTesterResult(result);
}
WpTestFuncResult test_i32_array_extend_alloc(void) {
b8 result;
WpAllocator allocator = wpMemArenaAllocatorInit(MiB(4));
WpI32Array array1 = wpArray(i32, 1, 2, 3, 4, 5, 6, 7, 8);
WpI32Array array2 = wpArray(i32, 1, 2);
WpI32Array array3 = wpArray(i32, 1, 2, 3, 4);
WpI32Array array = wpArrayExtendAlloc(i32, &allocator, array1, array3, WP_ARRAY_INIT_NONE);
result = array == array1;
array = wpArrayExtendAlloc(i32, &allocator, array2, array3, WP_ARRAY_INIT_NONE);
result = result && array != array2;
wpMemArenaAllocatorDestroy(&allocator);
return wpTesterResult(result);
}
WpTestFuncResult test_i32_array_copy_alloc(void) {
b8 result;
WpAllocator allocator = wpMemArenaAllocatorInit(MiB(4));
WpI32Array src = wpArray(i32, 1, 2, 3, 4, 5);
WpI32Array dst1 = wpArray(i32, 1, 2, 3, 4, 5, 6);
WpI32Array dst2 = wpArray(i32, 1, 2);
WpI32Array array = nullptr;
u64 expected_count = 5;
array = wpArrayCopyAlloc(i32, &allocator, dst1, src, WP_ARRAY_INIT_NONE);
result = wpArrayCount(array) == expected_count && array == dst1;
u64 index = 0;
b8 running = true;
while (running) {
result = result && (*wpArrayGet(i32, src, index) == *wpArrayGet(i32, array, index));
++index;
running = index < expected_count;
}
expected_count = 5;
array = wpArrayCopyAlloc(i32, &allocator, dst2, src, WP_ARRAY_INIT_NONE);
result = result && wpArrayCount(array) == expected_count && array != dst2;
index = 0;
running = true;
while (running) {
result = result && (*wpArrayGet(i32, src, index) == *wpArrayGet(i32, array, index));
++index;
running = index < expected_count;
}
wpMemArenaAllocatorDestroy(&allocator);
return wpTesterResult(result);
}
WpTestFuncResult test_i32_array_clear(void) {
b8 result;
WpI32Array array = wpArray(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
result = wpArrayCount(array) == 9;
wpArrayClear(i32, array);
result = result && wpArrayCount(array) == 0;
return wpTesterResult(result);
}
WpTestFuncResult test_i32_array_pop(void) {
b8 result;
WpI32Array array1 = wpArray(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
WpI32Array array2 = wpArrayWithCapacity(i32, 32, WP_ARRAY_INIT_NONE);
i32 item1 = wpArrayPop(i32, array1);
i32 item2 = wpArrayPop(i32, array2);
result = item1 == 8 && item2 == 0;
return wpTesterResult(result);
}