diff options
Diffstat (limited to 'tests/vector.c')
-rw-r--r-- | tests/vector.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/vector.c b/tests/vector.c index 11568fe..f27715b 100644 --- a/tests/vector.c +++ b/tests/vector.c @@ -166,6 +166,53 @@ out: } static int +test_vector_capacity(void) { + int rc = -1; + + const struct Vector *v = NULL; + + test_start("vector_capacity()"); + { + testing("we get whatever the capacity is"); + + if (vector_new(sizeof(long), &v)) { + logerr("vector_new()"); + goto out; + } + + assert(vector_capacity(v) == VECTOR_DEFAULT_CAPACITY); + assert(v->capacity == VECTOR_DEFAULT_CAPACITY); + + printf("\n"); + const long value = 123; + for (size_t i = 0U; i < VECTOR_DEFAULT_CAPACITY; i++) { + assert(vector_push_back(v, &value) == 0); + } + const size_t new_capacity = next_capacity(v); + + if (vector_push_back(v, &value)) { + logerr("vector_push_back()"); + goto out; + } + + assert(vector_capacity(v) == new_capacity); + assert(v->capacity == new_capacity); + assert(vector_capacity(v) != VECTOR_DEFAULT_CAPACITY); + + vector_free(&v); + + test_ok(); + } + + rc = 0; +out: + if (v != NULL) { + vector_free(&v); + } + return rc; +} + +static int test_vector_count(void) { int rc = -1; @@ -573,6 +620,11 @@ main(void) { goto out; } + if (test_vector_capacity()) { + logerr("test_vector_capacity()"); + goto out; + } + if (test_vector_count()) { logerr("test_vector_count()"); goto out; |