diff options
author | David Robillard <d@drobilla.net> | 2021-09-10 20:11:37 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-09-10 20:54:28 -0400 |
commit | 8a752cc6a170296b8a12e3da28364db3d3636562 (patch) | |
tree | 3fa86f37684c363f7eb55cc87d88659c703926e9 /test | |
parent | b91461c15620e0f2214edda70048b0a8420a70ed (diff) | |
download | zix-8a752cc6a170296b8a12e3da28364db3d3636562.tar.gz zix-8a752cc6a170296b8a12e3da28364db3d3636562.tar.bz2 zix-8a752cc6a170296b8a12e3da28364db3d3636562.zip |
Add test for BTree iterator comparison
Diffstat (limited to 'test')
-rw-r--r-- | test/btree_test.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/btree_test.c b/test/btree_test.c index 77771c4..93ec9aa 100644 --- a/test/btree_test.c +++ b/test/btree_test.c @@ -160,6 +160,49 @@ test_free(void) zix_btree_free(t, destroy); } +static void +test_iter_comparison(void) +{ + static const size_t n_elems = 4096u; + + ZixBTree* const t = zix_btree_new(int_cmp, NULL); + + // Store increasing numbers from 1 (jammed into the pointers themselves) + for (uintptr_t r = 1u; r < n_elems; ++r) { + assert(!zix_btree_insert(t, (void*)r)); + } + + // Check that begin and end work sensibly + const ZixBTreeIter begin = zix_btree_begin(t); + const ZixBTreeIter end = zix_btree_end(t); + assert(!zix_btree_iter_is_end(begin)); + assert(zix_btree_iter_is_end(end)); + assert(!zix_btree_iter_equals(begin, end)); + assert(!zix_btree_iter_equals(end, begin)); + + // Make another begin iterator + ZixBTreeIter j = zix_btree_begin(t); + assert(zix_btree_iter_equals(begin, j)); + + // Advance it and check that they are no longer equal + for (size_t r = 1u; r < n_elems - 1u; ++r) { + j = zix_btree_iter_next(j); + assert(!zix_btree_iter_is_end(j)); + assert(!zix_btree_iter_equals(begin, j)); + assert(!zix_btree_iter_equals(end, j)); + assert(!zix_btree_iter_equals(j, end)); + } + + // Advance it to the end + zix_btree_iter_increment(&j); + assert(zix_btree_iter_is_end(j)); + assert(!zix_btree_iter_equals(begin, j)); + assert(zix_btree_iter_equals(end, j)); + assert(zix_btree_iter_equals(j, end)); + + zix_btree_free(t, NULL); +} + static int stress(const unsigned test_num, const size_t n_elems) { @@ -513,6 +556,7 @@ main(int argc, char** argv) test_clear(); test_free(); + test_iter_comparison(); const unsigned n_tests = 3u; const size_t n_elems = (argc > 1) ? strtoul(argv[1], NULL, 10) : 524288u; |