36 lines
1.0 KiB
C
36 lines
1.0 KiB
C
|
#include "util.h"
|
||
|
#include "unit.h"
|
||
|
|
||
|
#define TEST_LEN 32768
|
||
|
|
||
|
int tests_dynarr_insert(int argc, char **argv) {
|
||
|
size_dynarr_t increm = dynarr_initi(size_dynarr_t);
|
||
|
|
||
|
for (size_t i = 0; i < TEST_LEN; i += 2)
|
||
|
dynarr_push(increm, i);
|
||
|
for (size_t i = 1; i < TEST_LEN; i += 2)
|
||
|
dynarr_insert(increm, i, i);
|
||
|
chi_assert("arr.len == TEST_LEN", increm.len == TEST_LEN);
|
||
|
for (size_t i = 0; i < TEST_LEN; i++)
|
||
|
chi_assert("arr[i] == i", *dynarr_get(increm, i) == i);
|
||
|
|
||
|
dynarr_destroy(increm);
|
||
|
|
||
|
int_dynarr_t randins = dynarr_initi(int_dynarr_t);
|
||
|
|
||
|
long long parity = 0, check = 0;
|
||
|
|
||
|
for (size_t i = 0; i < TEST_LEN; i++) {
|
||
|
int gen = rand() % 10;
|
||
|
parity += gen;
|
||
|
dynarr_insert(randins, (rand() % (randins.len + 1)), gen);
|
||
|
}
|
||
|
chi_assert("arr.len == TEST_LEN", randins.len == TEST_LEN);
|
||
|
for (size_t i = 0; i < TEST_LEN; i++)
|
||
|
check += *dynarr_get(randins, i);
|
||
|
chi_assert("parity == check", parity == check);
|
||
|
|
||
|
dynarr_destroy(randins);
|
||
|
return 0;
|
||
|
}
|