From 172741e8f63e357b5a70fa2e7af41a05158cedbd Mon Sep 17 00:00:00 2001 From: Florian Burgener <florian.brgnr@gmail.com> Date: Fri, 10 Jun 2022 00:59:59 +0200 Subject: [PATCH] Add a new test case --- src/tests/BPTreeTests.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/tests/BPTreeTests.c b/src/tests/BPTreeTests.c index 4e05be0..511a8dc 100644 --- a/src/tests/BPTreeTests.c +++ b/src/tests/BPTreeTests.c @@ -46,6 +46,20 @@ static bool check_if_the_leaf_nodes_are_correctly_chained(BPTreeNode *root) { return true; } +static bool check_if_all_leaf_nodes_nodes_have_no_children(BPTreeNode *root) { + if (root->is_leaf) { + return root->children->size == 0; + } + + for (int i = 0; i < root->children->size; i++) { + if (!check_if_all_leaf_nodes_nodes_have_no_children(root->children->items[i])) { + return false; + } + } + + return true; +} + static bool check_if_all_leaf_nodes_have_as_many_keys_as_data(BPTreeNode *root) { if (root->is_leaf) { return root->keys->size == root->data->size; @@ -204,6 +218,7 @@ static bool check_BPTree_compliance(BPTreeNode *root) { bool is_compliant = true; is_compliant &= check_if_the_leaf_nodes_are_correctly_chained(root); + is_compliant &= check_if_all_leaf_nodes_nodes_have_no_children(root); is_compliant &= check_if_all_leaf_nodes_have_as_many_keys_as_data(root); is_compliant &= check_if_all_leaf_nodes_are_at_the_same_depth(root, compute_first_leaf_depth(root), 0); -- GitLab