diff options
author | sanine <sanine.not@pm.me> | 2022-11-27 20:03:27 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-11-27 20:03:27 -0600 |
commit | 6ca18697f9eb332c38f0b46b823089ce80347580 (patch) | |
tree | 267d074f74ebfa54f1c90fd3361e6b2dbf793613 /src/util.test.c | |
parent | 21e8b8ad389dda55d92af4af1fd22aac657074b4 (diff) |
add dynamic array functions
Diffstat (limited to 'src/util.test.c')
-rw-r--r-- | src/util.test.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/util.test.c b/src/util.test.c new file mode 100644 index 0000000..c2f8462 --- /dev/null +++ b/src/util.test.c @@ -0,0 +1,57 @@ +#include <stdlib.h> + +#include <kalmia.h> +#include "util.h" +#include "test/test.h" + +void next_array_element(); + +void suite_util() +{ + lily_run_test(next_array_element); +} + +void next_array_element() +{ + int *arr = NULL; + size_t count = 0; + size_t max = 0; + + int *next = kai_next_array_element((void**) &arr, &count, &max, sizeof(int)); + lily_assert_not_null(arr); + lily_assert_not_null(next); + + lily_assert_ptr_equal(arr+0, next); + lily_assert_int_equal(count, 1); + lily_assert_int_equal(max, 1); + *next = 2; + + next = kai_next_array_element((void**) &arr, &count, &max, sizeof(int)); + + lily_assert_not_null(next); + lily_assert_ptr_equal(arr+1, next); + lily_assert_int_equal(count, 2); + lily_assert_int_equal(max, 2); + *next = 1; + + next = kai_next_array_element((void**) &arr, &count, &max, sizeof(int)); + + lily_assert_not_null(next); + lily_assert_ptr_equal(arr+2, next); + lily_assert_int_equal(count, 3); + lily_assert_int_equal(max, 4); + *next = 3; + + next = kai_next_array_element((void**) &arr, &count, &max, sizeof(int)); + + lily_assert_not_null(next); + lily_assert_ptr_equal(arr+3, next); + lily_assert_int_equal(count, 4); + lily_assert_int_equal(max, 4); + *next = 4; + + int expected[] = { 2, 1, 3, 4 }; + lily_assert_memory_equal(expected, arr, 4 * sizeof(int)); + + free(arr); +} |