Spider2/tests/dynarr_extensions.c

35 lines
1.2 KiB
C

#include "util.h"
#include "unit.h"
#define TEST_LEN 32768
int tests_dynarr_extensions(int argc, char **argv) {
int *cmp = xmalloc(TEST_LEN * sizeof(int));
for (size_t i = 0; i < TEST_LEN; i++)
cmp[i] = rand();
int_dynarr_t extend = dynarr_initi(int_dynarr_t);
dynarr_extend_fixed(extend, cmp, TEST_LEN);
chi_assert("extend.data != cmp", memcmp(extend.data, cmp, TEST_LEN * sizeof(int)) == 0);
chi_assert("extend.len != TEST_LEN", extend.len == TEST_LEN);
dynarr_destroy(extend);
int_dynarr_t push = dynarr_initi(int_dynarr_t);
for (size_t i = 0; i < TEST_LEN; i++)
dynarr_push(push, cmp[i]);
chi_assert("push.data != cmp", memcmp(push.data, cmp, TEST_LEN * sizeof(int)) == 0);
chi_assert("push.len != TEST_LEN", push.len == TEST_LEN);
dynarr_destroy(push);
int_dynarr_t both = dynarr_initi(int_dynarr_t);
dynarr_extend_fixed(both, cmp, TEST_LEN / 2);
for (size_t i = TEST_LEN / 2; i < TEST_LEN; i++)
dynarr_push(both, cmp[i]);
chi_assert("both.data != cmp", memcmp(both.data, cmp, TEST_LEN * sizeof(int)) == 0);
chi_assert("both.len != TEST_LEN", both.len == TEST_LEN);
dynarr_destroy(both);
xfree(cmp);
return 0;
}