Add testing for i32 array to test array logic

This commit is contained in:
Abdelrahman Said 2025-04-21 17:47:33 +01:00
parent a359331df7
commit d3f1686d58
4 changed files with 157 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#define WAPP_CONTAINERS_C
#include "wapp_containers.h"
#include "array/array.c"
#include "dbl_list/dbl_list.c"
#endif // !WAPP_CONTAINERS_C

View File

@ -0,0 +1,124 @@
#include "test_i32_array.h"
#include "wapp.h"
#include <stdbool.h>
TestFuncResult test_i32_array(void) {
bool result;
I32Array array = wapp_i32_array(1, 2, 3, 4, 5, 6, 7);
result = array.count == 7 && array.capacity == 16;
i32 *item;
u64 count = array.count;
for (u64 i = 0; i < count; ++i) {
item = wapp_i32_array_get(&array, i);
result = result && item && (*item == (i32)(i + 1));
}
return wapp_tester_result(result);
}
TestFuncResult test_i32_array_with_capacity(void) {
bool result;
I32Array array = wapp_i32_array_with_capacity(64);
result = array.count == 0 && array.capacity == 64;
return wapp_tester_result(result);
}
TestFuncResult test_i32_array_get(void) {
bool result = true;
I32Array array = wapp_i32_array(0, 1, 2, 3, 4, 5, 6, 7, 8);
i32 *item;
u64 count = array.count;
for (u64 i = 0; i < count; ++i) {
item = wapp_i32_array_get(&array, i);
result = result && item && (*item == (i32)i);
}
return wapp_tester_result(result);
}
TestFuncResult test_i32_array_set(void) {
bool result = true;
I32Array array = wapp_i32_array(0, 1, 2, 3, 4, 5, 6, 7, 8);
i32 *item;
u64 count = array.count;
for (u64 i = 0; i < count; ++i) {
wapp_i32_array_set(&array, i, (i32)(i * 2));
item = wapp_i32_array_get(&array, i);
result = result && item && (*item == (i32)(i * 2));
}
return wapp_tester_result(result);
}
TestFuncResult test_i32_array_append_capped(void) {
bool result;
I32Array array = wapp_i32_array_with_capacity(64);
wapp_i32_array_append_capped(&array, 10);
result = array.count == 1;
i32 *item = wapp_i32_array_get(&array, 0);
result = result && item && *item == 10;
array = wapp_i32_array(1);
wapp_i32_array_append_capped(&array, 10);
wapp_i32_array_append_capped(&array, 20);
result = result && array.count == 2;
return wapp_tester_result(result);
}
TestFuncResult test_i32_array_extend_capped(void) {
bool result;
I32Array array1 = wapp_i32_array(1, 2, 3, 4);
I32Array array2 = wapp_i32_array(10, 20);
result = array1.count == 4 && array2.count == 2;
wapp_i32_array_extend_capped(&array1, &array2);
result = result && array1.count == 6;
wapp_i32_array_extend_capped(&array1, &array1);
result = result && array1.count == 6;
return wapp_tester_result(result);
}
TestFuncResult test_i32_array_clear(void) {
bool result;
I32Array array = wapp_i32_array(0, 1, 2, 3, 4, 5, 6, 7, 8);
result = array.count == 9;
wapp_i32_array_clear(&array);
result = result && array.count == 0;
return wapp_tester_result(result);
}
TestFuncResult test_i32_array_pop(void) {
bool result;
I32Array array1 = wapp_i32_array(0, 1, 2, 3, 4, 5, 6, 7, 8);
I32Array array2 = wapp_i32_array_with_capacity(32);
i32 item1 = wapp_i32_array_pop(&array1);
i32 item2 = wapp_i32_array_pop(&array2);
result = item1 == 8 && item2 == 0;
return wapp_tester_result(result);
}

View File

@ -0,0 +1,23 @@
#ifndef TEST_INT_ARRAY_H
#define TEST_INT_ARRAY_H
#include "wapp.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_i32_array(void);
TestFuncResult test_i32_array_with_capacity(void);
TestFuncResult test_i32_array_get(void);
TestFuncResult test_i32_array_set(void);
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);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_INT_ARRAY_H

View File

@ -2,6 +2,7 @@
#include "test_str8_list.h"
#include "test_allocator.h"
#include "test_arena.h"
#include "test_i32_array.h"
#include "test_cpath.h"
#include "test_shell_commander.h"
#include "wapp.h"
@ -17,6 +18,14 @@ int main(void) {
test_arena_realloc_smaller_size,
test_arena_clear,
test_arena_destroy,
test_i32_array,
test_i32_array_with_capacity,
test_i32_array_get,
test_i32_array_set,
test_i32_array_append_capped,
test_i32_array_extend_capped,
test_i32_array_clear,
test_i32_array_pop,
test_str8_lit,
test_str8_lit_ro,
test_str8_buf,