summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2024-12-06 07:52:43 -0500
committerJonathan Bradley <jcb@pikum.xyz>2024-12-06 07:52:43 -0500
commit4b18e25ed6c4e506f8182e091fc355a7b013a788 (patch)
tree57d5de9e93a90896f19522c28ca93955408204f9 /test
parenteccc1feda80b036768afb7b29933756b83f2bb48 (diff)
pkarr: more tests
Diffstat (limited to 'test')
-rw-r--r--test/pkarr.c87
1 files changed, 85 insertions, 2 deletions
diff --git a/test/pkarr.c b/test/pkarr.c
index d8f682f..deac974 100644
--- a/test/pkarr.c
+++ b/test/pkarr.c
@@ -45,7 +45,7 @@ int main(int argc, char *argv[])
}
*/
- // init via append
+ // init via append, soft clear
{
test_spinup(&arr, &bkt);
arr.stride = sizeof(uint8_t);
@@ -58,6 +58,13 @@ int main(int argc, char *argv[])
if (arr.reserved == 0) exit(1);
if (arr.next != 1) exit(1);
+ pk_arr_clear(&arr);
+
+ if (arr.bkt == NULL) exit(1);
+ if (arr.data == NULL) exit(1);
+ if (arr.reserved == 0) exit(1);
+ if (arr.next != 0) exit(1);
+
test_teardown(&arr, &bkt);
}
@@ -87,7 +94,7 @@ int main(int argc, char *argv[])
test_teardown(&arr, &bkt);
}
- // complex struct
+ // complex movement
{
test_spinup(&arr, &bkt);
arr.stride = sizeof(struct some_complex_struct);
@@ -116,5 +123,81 @@ int main(int argc, char *argv[])
test_teardown(&arr, &bkt);
}
+ // resize (implicit reserve) + grow
+ {
+ test_spinup(&arr, &bkt);
+ arr.stride = sizeof(uint8_t);
+
+ pk_arr_resize(&arr, 17);
+ uint8_t *typed_buffer = (uint8_t *)arr.data;
+
+ if (arr.bkt == NULL) exit(1);
+ if (arr.data == NULL) exit(1);
+ if (arr.reserved != 17) exit(1);
+ if (arr.next != 17) exit(1);
+
+ for (i = 0; i < 17; ++i) {
+ typed_buffer[i] = (uint8_t)i;
+ }
+
+ uint8_t v = 17;
+ pk_arr_append(&arr, &v);
+
+ if (arr.bkt == NULL) exit(1);
+ if (arr.data == NULL) exit(1);
+ if (arr.reserved == 17) exit(1);
+ if (arr.next != 18) exit(1);
+
+ test_teardown(&arr, &bkt);
+ }
+
+ // remove_at back, middle, front
+ {
+ test_spinup(&arr, &bkt);
+ arr.stride = sizeof(uint64_t);
+
+ for (i = 0; i < 5; ++i) {
+ pk_arr_append(&arr, &i);
+ }
+
+ pk_arr_remove_at(&arr, 4); // back
+
+ if (arr.bkt == NULL) exit(1);
+ if (arr.data == NULL) exit(1);
+ if (arr.reserved == 0) exit(1);
+ if (arr.next != 4) exit(1);
+
+ uint64_t *vals = (uint64_t *)arr.data;
+ if (0 != vals[0]) exit(1);
+ if (1 != vals[1]) exit(1);
+ if (2 != vals[2]) exit(1);
+ if (3 != vals[3]) exit(1);
+
+ pk_arr_remove_at(&arr, 2); // middle
+
+ if (arr.bkt == NULL) exit(1);
+ if (arr.data == NULL) exit(1);
+ if (arr.reserved == 0) exit(1);
+ if (arr.next != 3) exit(1);
+
+ vals = (uint64_t *)arr.data;
+ if (0 != vals[0]) exit(1);
+ if (1 != vals[1]) exit(1);
+ if (3 != vals[2]) exit(1);
+
+ pk_arr_remove_at(&arr, 0); // front
+
+ if (arr.bkt == NULL) exit(1);
+ if (arr.data == NULL) exit(1);
+ if (arr.reserved == 0) exit(1);
+ if (arr.next != 2) exit(1);
+
+ vals = (uint64_t *)arr.data;
+ if (1 != vals[0]) exit(1);
+ if (3 != vals[1]) exit(1);
+
+ test_teardown(&arr, &bkt);
+ }
+
return 0;
}