summaryrefslogtreecommitdiffstats
path: root/test/btree_test.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-09-10 20:11:38 -0400
committerDavid Robillard <d@drobilla.net>2021-09-10 20:54:28 -0400
commit7a47acac9c5b743c50ab7967cdec4645f6d868db (patch)
treebf5d634b69a739a5467e9fc297b6b3a6d25b10a7 /test/btree_test.c
parent8a752cc6a170296b8a12e3da28364db3d3636562 (diff)
downloadzix-7a47acac9c5b743c50ab7967cdec4645f6d868db.tar.gz
zix-7a47acac9c5b743c50ab7967cdec4645f6d868db.tar.bz2
zix-7a47acac9c5b743c50ab7967cdec4645f6d868db.zip
Add test for reinserting a value that is a BTree node split pivot
Diffstat (limited to 'test/btree_test.c')
-rw-r--r--test/btree_test.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/btree_test.c b/test/btree_test.c
index 93ec9aa..8039132 100644
--- a/test/btree_test.c
+++ b/test/btree_test.c
@@ -203,6 +203,25 @@ test_iter_comparison(void)
zix_btree_free(t, NULL);
}
+static void
+test_insert_split_value(void)
+{
+ static const size_t n_insertions = 767u; // Number of insertions to split
+ static const uintptr_t split_value = 512u; // Value that will be pulled up
+
+ ZixBTree* const t = zix_btree_new(int_cmp, NULL);
+
+ // Insert right up until it would cause a split
+ for (uintptr_t r = 1u; r < n_insertions; ++r) {
+ assert(!zix_btree_insert(t, (void*)r));
+ }
+
+ // Insert the element that will be chosen as the split pivot
+ assert(zix_btree_insert(t, (void*)split_value) == ZIX_STATUS_EXISTS);
+
+ zix_btree_free(t, NULL);
+}
+
static int
stress(const unsigned test_num, const size_t n_elems)
{
@@ -557,6 +576,7 @@ main(int argc, char** argv)
test_clear();
test_free();
test_iter_comparison();
+ test_insert_split_value();
const unsigned n_tests = 3u;
const size_t n_elems = (argc > 1) ? strtoul(argv[1], NULL, 10) : 524288u;