From 8434edb0d7879817041b0ebd02ed97ee856eded6 Mon Sep 17 00:00:00 2001 From: All Asmaul Husnain <2263081025@uttarauniversity.edu.bd> Date: Sat, 10 Oct 2026 17:27:33 +0600 Subject: [PATCH 1/2] Test B tree splits with mixed insertion order --- tests/test_database.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/test_database.c b/tests/test_database.c index bf26b82..d186ab1 100644 --- a/tests/test_database.c +++ b/tests/test_database.c @@ -85,6 +85,46 @@ static void test_btree_split_and_order(void) remove(filename); } +static void test_btree_mixed_insertion_order(void) +{ + const char *filename = "build/test_btree_mixed.db"; + remove(filename); + + SqliteResult result; + Table *table = table_open(filename, &result); + assert(table != NULL); + + for (int i = 0; i < 80; ++i) { + int id = ((i * 37) % 80) + 1; + Row row = make_row(id); + assert(table_insert(table, &row) == SQLITE_OK); + } + + assert(table_size(table) == 80); + + for (int id = 1; id <= 80; ++id) { + Row found = {0}; + assert(table_find(table, id, &found) == SQLITE_OK); + assert(found.id == id); + assert(strcmp(found.username, make_row(id).username) == 0); + } + + table_destroy(table); + + table = table_open(filename, &result); + assert(table != NULL); + assert(table_size(table) == 80); + + for (size_t i = 0; i < table_size(table); ++i) { + const Row *row = table_row_at(table, i); + assert(row != NULL); + assert(row->id == (int)i + 1); + } + + table_destroy(table); + remove(filename); +} + static void test_lookup(void) { const char *filename = "build/test_lookup.db"; @@ -144,6 +184,7 @@ int main(void) { test_insert_and_read(); test_btree_split_and_order(); + test_btree_mixed_insertion_order(); test_lookup(); test_validation(); return 0; From 785591a24904203db7c5a683013e24e70d83db1c Mon Sep 17 00:00:00 2001 From: All Asmaul Husnain <2263081025@uttarauniversity.edu.bd> Date: Sat, 10 Oct 2026 17:27:44 +0600 Subject: [PATCH 2/2] Avoid temporary array expression in test --- tests/test_database.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_database.c b/tests/test_database.c index d186ab1..ce9f448 100644 --- a/tests/test_database.c +++ b/tests/test_database.c @@ -105,8 +105,9 @@ static void test_btree_mixed_insertion_order(void) for (int id = 1; id <= 80; ++id) { Row found = {0}; assert(table_find(table, id, &found) == SQLITE_OK); + Row expected = make_row(id); assert(found.id == id); - assert(strcmp(found.username, make_row(id).username) == 0); + assert(strcmp(found.username, expected.username) == 0); } table_destroy(table);