feat(lsm): implement bt insert & search
This commit is contained in:
parent
fd42b446a6
commit
13e42181a2
5 changed files with 2056 additions and 1 deletions
67
lsm/test/bt/bt.c
Normal file
67
lsm/test/bt/bt.c
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#include "test.h"
|
||||
#include "lsm.h"
|
||||
#include "lsm_bt.h"
|
||||
|
||||
#define BT_INIT() \
|
||||
lsm_bt *bt; \
|
||||
TEST_CHECK(lsm_bt_init(&bt) == lsm_error_ok); \
|
||||
TEST_CHECK(bt != NULL)
|
||||
|
||||
void test_init() {
|
||||
BT_INIT();
|
||||
}
|
||||
|
||||
void test_insert_first() {
|
||||
BT_INIT();
|
||||
|
||||
TEST_CHECK(lsm_bt_insert(bt, 'a', (void *)1) == lsm_error_ok);
|
||||
TEST_CHECK(lsm_bt_insert(bt, 'a', (void *)1) == lsm_error_already_present);
|
||||
|
||||
void *data;
|
||||
TEST_CHECK(lsm_bt_search(&data, bt, 'a') == lsm_error_ok);
|
||||
TEST_CHECK(data == (void *)1);
|
||||
|
||||
TEST_CHECK(lsm_bt_search(&data, bt, 'b') == lsm_error_not_found);
|
||||
}
|
||||
|
||||
void test_insert_two() {
|
||||
BT_INIT();
|
||||
|
||||
TEST_CHECK(lsm_bt_insert(bt, 'a', (void *)1) == lsm_error_ok);
|
||||
TEST_CHECK(lsm_bt_insert(bt, 'a', (void *)1) == lsm_error_already_present);
|
||||
TEST_CHECK(lsm_bt_insert(bt, 'b', (void *)2) == lsm_error_ok);
|
||||
TEST_CHECK(lsm_bt_insert(bt, 'b', (void *)2) == lsm_error_already_present);
|
||||
|
||||
void *data;
|
||||
TEST_CHECK(lsm_bt_search(&data, bt, 'a') == lsm_error_ok);
|
||||
TEST_CHECK(data == (void *)1);
|
||||
TEST_CHECK(lsm_bt_search(&data, bt, 'b') == lsm_error_ok);
|
||||
TEST_CHECK(data == (void *)2);
|
||||
TEST_CHECK(lsm_bt_search(&data, bt, 'c') == lsm_error_not_found);
|
||||
}
|
||||
|
||||
void test_insert_multiple() {
|
||||
char chars[] = "falcoep";
|
||||
size_t char_count = sizeof(chars) / sizeof(char);
|
||||
|
||||
BT_INIT();
|
||||
|
||||
for (size_t i = 0; i < char_count; i++) {
|
||||
TEST_CHECK(lsm_bt_insert(bt, chars[i], (void *)(i + 1)) == lsm_error_ok);
|
||||
}
|
||||
|
||||
void *data;
|
||||
for (size_t i = 0; i < char_count; i++) {
|
||||
TEST_CHECK(lsm_bt_insert(bt, chars[i], (void *)(i + 1)) == lsm_error_already_present);
|
||||
TEST_CHECK(lsm_bt_search(&data, bt, chars[i]) == lsm_error_ok);
|
||||
TEST_CHECK(data == (void *)(i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_LIST = {
|
||||
{ "test init", test_init },
|
||||
{ "test insert first", test_insert_first },
|
||||
{ "test insert two", test_insert_two },
|
||||
{ "test insert multiple", test_insert_multiple },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue