Add tests that the depth flags stay intact on shrinking
This commit is contained in:
parent
6127a9d6a8
commit
67dbb96774
@ -4,15 +4,6 @@ using blockstore::Key;
|
|||||||
|
|
||||||
class DataTreeGrowingTest_DepthFlags: public DataTreeGrowingTest {
|
class DataTreeGrowingTest_DepthFlags: public DataTreeGrowingTest {
|
||||||
public:
|
public:
|
||||||
void CHECK_DEPTH(int depth, const Key &key) {
|
|
||||||
auto node = LoadInnerNode(key);
|
|
||||||
EXPECT_EQ(depth, node->depth());
|
|
||||||
if (depth > 1) {
|
|
||||||
for (int i = 0; i < node->numChildren(); ++i) {
|
|
||||||
CHECK_DEPTH(depth-1, node->getChild(i)->key());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(DataTreeGrowingTest_DepthFlags, GrowAOneNodeTree) {
|
TEST_F(DataTreeGrowingTest_DepthFlags, GrowAOneNodeTree) {
|
||||||
|
@ -47,5 +47,3 @@ TEST_F(DataTreeShrinkingTest, ShrinkATwoLeafTree_IntermediateBlocksAreDeleted) {
|
|||||||
tree->removeLastDataLeaf();
|
tree->removeLastDataLeaf();
|
||||||
EXPECT_EQ(nullptr, nodeStore.load(firstChildKey));
|
EXPECT_EQ(nullptr, nodeStore.load(firstChildKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Test DepthFlags stay intact
|
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
#include "testutils/DataTreeShrinkingTest.h"
|
||||||
|
|
||||||
|
using blobstore::onblocks::datatreestore::DataTree;
|
||||||
|
using blockstore::Key;
|
||||||
|
|
||||||
|
class DataTreeShrinkingTest_DepthFlags: public DataTreeShrinkingTest {
|
||||||
|
public:
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(DataTreeShrinkingTest_DepthFlags, ShrinkATwoLeafTree) {
|
||||||
|
auto key = CreateTwoLeaf()->key();
|
||||||
|
Shrink(key);
|
||||||
|
CHECK_DEPTH(0, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DataTreeShrinkingTest_DepthFlags, ShrinkAFourNodeThreeLeafTree) {
|
||||||
|
auto key = CreateFourNodeThreeLeaf()->key();
|
||||||
|
Shrink(key);
|
||||||
|
CHECK_DEPTH(1, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DataTreeShrinkingTest_DepthFlags, ShrinkATwoInnerNodeOneTwoLeavesTree) {
|
||||||
|
auto key = CreateTwoInnerNodeOneTwoLeaves()->key();
|
||||||
|
Shrink(key);
|
||||||
|
CHECK_DEPTH(2, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DataTreeShrinkingTest_DepthFlags, ShrinkATwoInnerNodeTwoOneLeavesTree) {
|
||||||
|
auto key = CreateTwoInnerNodeTwoOneLeaves()->key();
|
||||||
|
Shrink(key);
|
||||||
|
CHECK_DEPTH(1, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DataTreeShrinkingTest_DepthFlags, ShrinkAThreeLevelMinDataTree) {
|
||||||
|
auto key = CreateThreeLevelMinData()->key();
|
||||||
|
Shrink(key);
|
||||||
|
CHECK_DEPTH(1, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DataTreeShrinkingTest_DepthFlags, ShrinkAFourLevelMinDataTree) {
|
||||||
|
auto key = CreateFourLevelMinData()->key();
|
||||||
|
Shrink(key);
|
||||||
|
CHECK_DEPTH(2, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DataTreeShrinkingTest_DepthFlags, ShrinkAFourLevelTreeWithTwoSiblingLeaves1) {
|
||||||
|
auto key = CreateFourLevelWithTwoSiblingLeaves1()->key();
|
||||||
|
Shrink(key);
|
||||||
|
CHECK_DEPTH(3, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DataTreeShrinkingTest_DepthFlags, ShrinkAFourLevelTreeWithTwoSiblingLeaves2) {
|
||||||
|
auto key = CreateFourLevelWithTwoSiblingLeaves2()->key();
|
||||||
|
Shrink(key);
|
||||||
|
CHECK_DEPTH(3, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DataTreeShrinkingTest_DepthFlags, ShrinkATreeWithFirstChildOfRootFullThreelevelAndSecondChildMindataThreelevel) {
|
||||||
|
auto key = CreateWithFirstChildOfRootFullThreelevelAndSecondChildMindataThreelevel()->key();
|
||||||
|
Shrink(key);
|
||||||
|
CHECK_DEPTH(3, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DataTreeShrinkingTest_DepthFlags, ShrinkAThreeLevelTreeWithThreeChildrenOfRoot) {
|
||||||
|
auto key = CreateThreeLevelWithThreeChildrenOfRoot()->key();
|
||||||
|
Shrink(key);
|
||||||
|
CHECK_DEPTH(2, key);
|
||||||
|
}
|
@ -128,3 +128,17 @@ void DataTreeTest::EXPECT_IS_FULL_THREELEVEL_TREE(const Key &key) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DataTreeTest::CHECK_DEPTH(int depth, const Key &key) {
|
||||||
|
if (depth == 0) {
|
||||||
|
EXPECT_IS_LEAF_NODE(key);
|
||||||
|
} else {
|
||||||
|
auto node = LoadInnerNode(key);
|
||||||
|
EXPECT_EQ(depth, node->depth());
|
||||||
|
if (depth > 1) {
|
||||||
|
for (int i = 0; i < node->numChildren(); ++i) {
|
||||||
|
CHECK_DEPTH(depth-1, node->getChild(i)->key());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -35,6 +35,8 @@ public:
|
|||||||
void EXPECT_IS_TWONODE_CHAIN(const blockstore::Key &key);
|
void EXPECT_IS_TWONODE_CHAIN(const blockstore::Key &key);
|
||||||
void EXPECT_IS_FULL_TWOLEVEL_TREE(const blockstore::Key &key);
|
void EXPECT_IS_FULL_TWOLEVEL_TREE(const blockstore::Key &key);
|
||||||
void EXPECT_IS_FULL_THREELEVEL_TREE(const blockstore::Key &key);
|
void EXPECT_IS_FULL_THREELEVEL_TREE(const blockstore::Key &key);
|
||||||
|
|
||||||
|
void CHECK_DEPTH(int depth, const blockstore::Key &key);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user