Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions tests/test_database.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,47 @@ 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);
Row expected = make_row(id);
assert(found.id == id);
assert(strcmp(found.username, expected.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";
Expand Down Expand Up @@ -144,6 +185,7 @@ int main(void)
{
test_insert_and_read();
test_btree_split_and_order();
test_btree_mixed_insertion_order();
test_lookup();
test_validation();
return 0;
Expand Down
Loading