aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2020-10-23 11:16:51 +0200
committerMarc André Tanner <mat@brain-dump.org>2020-10-23 11:16:51 +0200
commit5da54cad7dd4f926c2299ba938ff91a5c24a15dc (patch)
tree1260d0701728826795538d68df3142590759fd93
parentc10d22e5b71273adb492ef220a779d7d4da7f751 (diff)
downloadvis-5da54cad7dd4f926c2299ba938ff91a5c24a15dc.tar.gz
vis-5da54cad7dd4f926c2299ba938ff91a5c24a15dc.tar.xz
test/core: add basic array_{peek,pop} test
-rw-r--r--core/array-test.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/core/array-test.c b/core/array-test.c
index 748277f..356e75d 100644
--- a/core/array-test.c
+++ b/core/array-test.c
@@ -26,6 +26,8 @@ static void test_small_objects(void) {
ok(array_length(&arr) == 0, "Initialization");
ok(!array_set(&arr, 0, NULL) && errno == EINVAL, "Set with invalid index");
ok(array_get(&arr, 0) == NULL && errno == EINVAL, "Get with invalid index");
+ ok(array_peek(&arr) == NULL && array_length(&arr) == 0, "Peek empty array");
+ ok(array_pop(&arr) == NULL && array_length(&arr) == 0, "Pop empty array");
for (size_t i = 0; i < len; i++) {
int *v;
@@ -46,6 +48,11 @@ static void test_small_objects(void) {
"Get array element: %zu = %d", i, *v);
}
+ int *v;
+ ok((v = array_peek(&arr)) && *v == values[0] && array_length(&arr) == len, "Peek populated array");
+ ok((v = array_pop(&arr)) && *v == values[0] && array_length(&arr) == len-1, "Pop populated array");
+ ok((v = array_peek(&arr)) && *v == values[1] && array_length(&arr) == len-1, "Peek after pop");
+
array_clear(&arr);
ok(array_length(&arr) == 0 && array_get(&arr, 0) == NULL && errno == EINVAL, "Clear");
@@ -63,8 +70,6 @@ static void test_small_objects(void) {
ok(!array_remove(&arr, array_length(&arr)) && errno == EINVAL, "Remove past end of array");
- int *v;
-
size_t len_before = array_length(&arr);
ok(array_remove(&arr, 2) && array_length(&arr) == len_before-1 &&
(v = array_get(&arr, 0)) && *v == values[0] &&