diff options
| -rw-r--r-- | core/array-test.c | 9 |
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] && |
