summaryrefslogtreecommitdiffstats
path: root/test/sorted_array_test.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-12-31 20:32:53 +0100
committerDavid Robillard <d@drobilla.net>2020-12-31 20:32:53 +0100
commit723cc76c44868e61bcff1d06a145f1482bfc15fd (patch)
tree7d67ec8b93d41901dba05e6738d1ceec7ad29b0e /test/sorted_array_test.c
parent5edd99c6619328b479ecf25c21997b133e7c6dee (diff)
downloadzix-723cc76c44868e61bcff1d06a145f1482bfc15fd.tar.gz
zix-723cc76c44868e61bcff1d06a145f1482bfc15fd.tar.bz2
zix-723cc76c44868e61bcff1d06a145f1482bfc15fd.zip
Improve SortedArray test coverage
Diffstat (limited to 'test/sorted_array_test.c')
-rw-r--r--test/sorted_array_test.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/test/sorted_array_test.c b/test/sorted_array_test.c
index fc92933..b39fa8d 100644
--- a/test/sorted_array_test.c
+++ b/test/sorted_array_test.c
@@ -74,6 +74,7 @@ stress(unsigned test_num, unsigned n_elems)
fprintf(stderr, "Insert failed\n");
return test_fail();
}
+
if (*(intptr_t*)zix_sorted_array_get_data(ti) != r) {
fprintf(stderr,
"Data corrupt (%" PRIdPTR " != %" PRIdPTR ")\n",
@@ -92,6 +93,7 @@ stress(unsigned test_num, unsigned n_elems)
fprintf(stderr, "Find failed\n");
return test_fail();
}
+
if (*(intptr_t*)zix_sorted_array_get_data(ti) != r) {
fprintf(stderr,
"Data corrupt (%" PRIdPTR " != %" PRIdPTR ")\n",
@@ -109,7 +111,8 @@ stress(unsigned test_num, unsigned n_elems)
for (ZixSortedArrayIter iter = zix_sorted_array_begin(t);
!zix_sorted_array_iter_is_end(t, iter);
iter = zix_sorted_array_iter_next(t, iter), ++i) {
- r = ith_elem(test_num, n_elems, i);
+ r = ith_elem(test_num, n_elems, i);
+
const intptr_t iter_data = *(intptr_t*)zix_sorted_array_get_data(iter);
if (iter_data < last) {
fprintf(stderr,
@@ -129,6 +132,30 @@ stress(unsigned test_num, unsigned n_elems)
return test_fail();
}
+ if (zix_sorted_array_index(t, zix_sorted_array_size(t))) {
+ fprintf(stderr, "Got element past end\n");
+ return test_fail();
+ }
+
+ srand(seed);
+
+ // Iterate over all elements by index
+ last = -1;
+ for (i = 0; i < zix_sorted_array_size(t); ++i) {
+ r = ith_elem(test_num, n_elems, i);
+
+ const intptr_t iter_data = *(intptr_t*)zix_sorted_array_index(t, i);
+ if (iter_data < last) {
+ fprintf(stderr,
+ "Iter corrupt (%" PRIdPTR " < %" PRIdPTR ")\n",
+ iter_data,
+ last);
+ return test_fail();
+ }
+
+ last = iter_data;
+ }
+
srand(seed);
// Delete all elements
@@ -140,6 +167,7 @@ stress(unsigned test_num, unsigned n_elems)
fprintf(stderr, "Failed to find item to remove\n");
return test_fail();
}
+
if (zix_sorted_array_remove(t, item)) {
fprintf(stderr, "Error removing item\n");
}
@@ -177,7 +205,7 @@ main(int argc, char** argv)
return 1;
}
- printf("Running %u tests with %u elements (seed %u)", n_tests, n_elems, seed);
+ printf("Running %u tests with %u elements (seed %u)\n", n_tests, n_elems, seed);
for (unsigned i = 0; i < n_tests; ++i) {
printf(".");