Skip to content

Commit

Permalink
sync with private repo
Browse files Browse the repository at this point in the history
  • Loading branch information
unw9527 committed Sep 28, 2024
1 parent a9c460c commit 6df0c57
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 85 deletions.
64 changes: 2 additions & 62 deletions test/storage/b_plus_tree_delete_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,67 +24,7 @@ namespace bustub {

using bustub::DiskManagerUnlimitedMemory;

TEST(BPlusTreeTests, DISABLED_DeleteTest1) {
// create KeyComparator and index schema
auto key_schema = ParseCreateStatement("a bigint");
GenericComparator<8> comparator(key_schema.get());

auto disk_manager = std::make_unique<DiskManagerUnlimitedMemory>();
auto *bpm = new BufferPoolManager(50, disk_manager.get());
// allocate header_page
page_id_t page_id = bpm->NewPage();
// create b+ tree
BPlusTree<GenericKey<8>, RID, GenericComparator<8>> tree("foo_pk", page_id, bpm, comparator);
GenericKey<8> index_key;
RID rid;

std::vector<int64_t> keys = {1, 2, 3, 4, 5};
for (auto key : keys) {
int64_t value = key & 0xFFFFFFFF;
rid.Set(static_cast<int32_t>(key >> 32), value);
index_key.SetFromInteger(key);
tree.Insert(index_key, rid);
}

std::vector<RID> rids;
for (auto key : keys) {
rids.clear();
index_key.SetFromInteger(key);
tree.GetValue(index_key, &rids);
EXPECT_EQ(rids.size(), 1);

int64_t value = key & 0xFFFFFFFF;
EXPECT_EQ(rids[0].GetSlotNum(), value);
}

std::vector<int64_t> remove_keys = {1, 5};
for (auto key : remove_keys) {
index_key.SetFromInteger(key);
tree.Remove(index_key);
}

int64_t size = 0;
bool is_present;

for (auto key : keys) {
rids.clear();
index_key.SetFromInteger(key);
is_present = tree.GetValue(index_key, &rids);

if (!is_present) {
EXPECT_NE(std::find(remove_keys.begin(), remove_keys.end(), key), remove_keys.end());
} else {
EXPECT_EQ(rids.size(), 1);
EXPECT_EQ(rids[0].GetPageId(), 0);
EXPECT_EQ(rids[0].GetSlotNum(), key);
size = size + 1;
}
}
EXPECT_EQ(size, 3);
delete bpm;
}

TEST(BPlusTreeTests, DISABLED_DeleteTest2) {
TEST(BPlusTreeTests, DISABLED_DeleteTest) {
// create KeyComparator and index schema
auto key_schema = ParseCreateStatement("a bigint");
GenericComparator<8> comparator(key_schema.get());
Expand Down Expand Up @@ -137,7 +77,7 @@ TEST(BPlusTreeTests, DISABLED_DeleteTest2) {
EXPECT_EQ(rids.size(), 1);
EXPECT_EQ(rids[0].GetPageId(), 0);
EXPECT_EQ(rids[0].GetSlotNum(), key);
size = size + 1;
++size;
}
}
EXPECT_EQ(size, 1);
Expand Down
22 changes: 5 additions & 17 deletions test/storage/b_plus_tree_insert_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,8 @@ TEST(BPlusTreeTests, DISABLED_InsertTest2) {
tree.Insert(index_key, rid);
}

std::vector<RID> rids;
for (auto key : keys) {
rids.clear();
index_key.SetFromInteger(key);
tree.GetValue(index_key, &rids);
EXPECT_EQ(rids.size(), 1);

int64_t value = key & 0xFFFFFFFF;
EXPECT_EQ(rids[0].GetSlotNum(), value);
}

int64_t size = 0;
bool is_present;
std::vector<RID> rids;

for (auto key : keys) {
rids.clear();
Expand All @@ -100,10 +89,9 @@ TEST(BPlusTreeTests, DISABLED_InsertTest2) {
EXPECT_EQ(is_present, true);
EXPECT_EQ(rids.size(), 1);
EXPECT_EQ(rids[0].GetPageId(), 0);
EXPECT_EQ(rids[0].GetSlotNum(), key);
size = size + 1;
int64_t value = key & 0xFFFFFFFF;
EXPECT_EQ(rids[0].GetSlotNum(), value);
}
EXPECT_EQ(size, keys.size());
delete bpm;
}

Expand Down Expand Up @@ -147,7 +135,7 @@ TEST(BPlusTreeTests, DISABLED_InsertTest3) {
auto location = (*iterator).second;
EXPECT_EQ(location.GetPageId(), 0);
EXPECT_EQ(location.GetSlotNum(), current_key);
current_key = current_key + 1;
++current_key;
}

EXPECT_EQ(current_key, keys.size() + 1);
Expand All @@ -159,7 +147,7 @@ TEST(BPlusTreeTests, DISABLED_InsertTest3) {
auto location = (*iterator).second;
EXPECT_EQ(location.GetPageId(), 0);
EXPECT_EQ(location.GetSlotNum(), current_key);
current_key = current_key + 1;
++current_key;
}
delete bpm;
}
Expand Down
9 changes: 3 additions & 6 deletions test/storage/b_plus_tree_sequential_scale_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace bustub {
using bustub::DiskManagerUnlimitedMemory;

/**
* This test should be passing with your Checkpoint 1 submission.
* (Fall 2024) You should pass this test after finishing Task 1 and 2.a in P2.
*/
TEST(BPlusTreeTests, DISABLED_ScaleTest) { // NOLINT
// create KeyComparator and index schema
Expand All @@ -44,10 +44,8 @@ TEST(BPlusTreeTests, DISABLED_ScaleTest) { // NOLINT
RID rid;

int64_t scale = 5000;
std::vector<int64_t> keys;
for (int64_t key = 1; key < scale; key++) {
keys.push_back(key);
}
std::vector<int64_t> keys(scale);
std::iota(keys.begin(), keys.end(), 1);

// randomized the insertion order
auto rng = std::default_random_engine{};
Expand All @@ -68,7 +66,6 @@ TEST(BPlusTreeTests, DISABLED_ScaleTest) { // NOLINT
int64_t value = key & 0xFFFFFFFF;
ASSERT_EQ(rids[0].GetSlotNum(), value);
}

delete bpm;
}
} // namespace bustub

0 comments on commit 6df0c57

Please sign in to comment.