diff options
Diffstat (limited to 'tests/vec.c')
-rw-r--r-- | tests/vec.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/tests/vec.c b/tests/vec.c index a84096c..8531b14 100644 --- a/tests/vec.c +++ b/tests/vec.c @@ -1,14 +1,33 @@ +#include <stdio.h> #include <assert.h> +#include "test.h" +/* required defs */ #define VEC_TYPE int #define VEC_NAME ints + +/* optional defs */ +#define VEC_MALLOC mallocc +#define VEC_CALLOC callocc +#define VEC_REALLOC reallocc +#define VEC_FREE free + #include <conts/vec.h> int main() { +#if defined(COVERAGE) + assert(!covsrv_init()); + atexit(covsrv_destroy); +#endif + struct ints ints = ints_create(0); for (int i = 0; i < 1000000; ++i) { - ints_append(&ints, i); + if (!ints_append(&ints, i)) { + fprintf(stderr, "failed appending %d to vec\n", i); + ints_destroy(&ints); + return -1; + } } assert(ints_len(&ints) == 1000000); @@ -23,6 +42,19 @@ int main() i++; } + /* TEN million !!1! */ + if (!ints_reserve(&ints, 10000000)) { + fprintf(stderr, "failed reserving vec\n"); + ints_destroy(&ints); + return -1; + } + + /* set size back to keep test runtime reasonable + * (is shrink necessary when we already have reserve? I + * guess it shows intention a bit better and just asserts instead of + * maybe fails?) */ + ints_shrink(&ints, 1000000); + for (int i = 1000000 - 1; i >= 0; --i) { ints_remove(&ints, i); } |