diff options
Diffstat (limited to 'tests/vec.c')
-rw-r--r-- | tests/vec.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/vec.c b/tests/vec.c index 8531b14..1ed5f72 100644 --- a/tests/vec.c +++ b/tests/vec.c @@ -14,6 +14,12 @@ #include <conts/vec.h> +/* used for sorting testing */ +static int int_comp(int *a, int *b) +{ + return *a - *b; +} + int main() { #if defined(COVERAGE) @@ -55,10 +61,32 @@ int main() * maybe fails?) */ ints_shrink(&ints, 1000000); + /* so the above is equivalent to */ + assert(ints_reserve(&ints, 1000000)); + assert(ints_len(&ints) == 1000000); + for (int i = 1000000 - 1; i >= 0; --i) { ints_remove(&ints, i); } assert(ints_len(&ints) == 0); + /* test out resetting as well */ + assert(ints_reserve(&ints, 10)); + assert(ints_len(&ints) == 10); + + ints_reset(&ints); + assert(ints_len(&ints) == 0); + + /* try out sorting and special accesses */ + ints_append(&ints, 3); + ints_append(&ints, 2); + ints_append(&ints, 1); + + ints_sort(&ints, int_comp); + + assert(*ints_back(&ints) == 3); + assert(*ints_pop(&ints) == 3); + assert(*ints_back(&ints) == 2); + ints_destroy(&ints); } |