summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-06-02 21:03:24 -0300
committerEuAndreh <eu@euandre.org>2024-06-02 21:03:24 -0300
commit537a8851a7be615abfd9f1e2bb8c26699e8086b2 (patch)
tree76d8ae04b275a1d581d0f008a130a338d3ee98bc /tests
parentsrc/hash.c: Add thread safe initialization of SipHash seed (diff)
downloadpindaiba-537a8851a7be615abfd9f1e2bb8c26699e8086b2.tar.gz
pindaiba-537a8851a7be615abfd9f1e2bb8c26699e8086b2.tar.xz
src/vector.h: Add vector_capacity()
Diffstat (limited to 'tests')
-rw-r--r--tests/vector.c52
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;