From 6df0c57e5422943d1a74ca641e0ac1a58098e484 Mon Sep 17 00:00:00 2001 From: unw9527 <1041593558@qq.com> Date: Sat, 28 Sep 2024 17:58:59 -0400 Subject: [PATCH] sync with private repo --- test/storage/b_plus_tree_delete_test.cpp | 64 +------------------ test/storage/b_plus_tree_insert_test.cpp | 22 ++----- .../b_plus_tree_sequential_scale_test.cpp | 9 +-- 3 files changed, 10 insertions(+), 85 deletions(-) diff --git a/test/storage/b_plus_tree_delete_test.cpp b/test/storage/b_plus_tree_delete_test.cpp index 6c03da985..80bd118e9 100644 --- a/test/storage/b_plus_tree_delete_test.cpp +++ b/test/storage/b_plus_tree_delete_test.cpp @@ -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(); - auto *bpm = new BufferPoolManager(50, disk_manager.get()); - // allocate header_page - page_id_t page_id = bpm->NewPage(); - // create b+ tree - BPlusTree, RID, GenericComparator<8>> tree("foo_pk", page_id, bpm, comparator); - GenericKey<8> index_key; - RID rid; - - std::vector keys = {1, 2, 3, 4, 5}; - for (auto key : keys) { - int64_t value = key & 0xFFFFFFFF; - rid.Set(static_cast(key >> 32), value); - index_key.SetFromInteger(key); - tree.Insert(index_key, rid); - } - - std::vector 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 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()); @@ -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); diff --git a/test/storage/b_plus_tree_insert_test.cpp b/test/storage/b_plus_tree_insert_test.cpp index f3b06efac..1c7fb817d 100644 --- a/test/storage/b_plus_tree_insert_test.cpp +++ b/test/storage/b_plus_tree_insert_test.cpp @@ -78,19 +78,8 @@ TEST(BPlusTreeTests, DISABLED_InsertTest2) { tree.Insert(index_key, rid); } - std::vector 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 rids; for (auto key : keys) { rids.clear(); @@ -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; } @@ -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); @@ -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; } diff --git a/test/storage/b_plus_tree_sequential_scale_test.cpp b/test/storage/b_plus_tree_sequential_scale_test.cpp index 6957be5ad..ffabb4a0e 100644 --- a/test/storage/b_plus_tree_sequential_scale_test.cpp +++ b/test/storage/b_plus_tree_sequential_scale_test.cpp @@ -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 @@ -44,10 +44,8 @@ TEST(BPlusTreeTests, DISABLED_ScaleTest) { // NOLINT RID rid; int64_t scale = 5000; - std::vector keys; - for (int64_t key = 1; key < scale; key++) { - keys.push_back(key); - } + std::vector keys(scale); + std::iota(keys.begin(), keys.end(), 1); // randomized the insertion order auto rng = std::default_random_engine{}; @@ -68,7 +66,6 @@ TEST(BPlusTreeTests, DISABLED_ScaleTest) { // NOLINT int64_t value = key & 0xFFFFFFFF; ASSERT_EQ(rids[0].GetSlotNum(), value); } - delete bpm; } } // namespace bustub