Refactor shrinking test cases

This commit is contained in:
Sebastian Messmer 2015-02-23 17:30:44 +01:00
parent fee8cd42eb
commit 7fea8017c8
6 changed files with 85 additions and 110 deletions

View File

@ -13,51 +13,51 @@ public:
};
TEST_F(DataTreeShrinkingTest_KeyDoesntChange, ShrinkATwoLeafTree) {
auto key = CreateTwoLeafTree()->key();
auto key = CreateTwoLeaf()->key();
EXPECT_KEY_DOESNT_CHANGE_WHEN_SHRINKING(key);
}
TEST_F(DataTreeShrinkingTest_KeyDoesntChange, ShrinkAFourNodeThreeLeafTree) {
auto key = CreateFourNodeThreeLeafTree();
auto key = CreateFourNodeThreeLeaf()->key();
EXPECT_KEY_DOESNT_CHANGE_WHEN_SHRINKING(key);
}
TEST_F(DataTreeShrinkingTest_KeyDoesntChange, ShrinkATwoInnerNodeOneTwoLeavesTree) {
auto key = CreateTwoInnerNodeOneTwoLeavesTree();
auto key = CreateTwoInnerNodeOneTwoLeaves()->key();
EXPECT_KEY_DOESNT_CHANGE_WHEN_SHRINKING(key);
}
TEST_F(DataTreeShrinkingTest_KeyDoesntChange, ShrinkATwoInnerNodeTwoOneLeavesTree) {
auto key = CreateTwoInnerNodeTwoOneLeavesTree();
auto key = CreateTwoInnerNodeTwoOneLeaves()->key();
EXPECT_KEY_DOESNT_CHANGE_WHEN_SHRINKING(key);
}
TEST_F(DataTreeShrinkingTest_KeyDoesntChange, ShrinkAThreeLevelMinDataTree) {
auto key = CreateThreeLevelMinDataTree();
auto key = CreateThreeLevelMinData()->key();
EXPECT_KEY_DOESNT_CHANGE_WHEN_SHRINKING(key);
}
TEST_F(DataTreeShrinkingTest_KeyDoesntChange, ShrinkAFourLevelMinDataTree) {
auto key = CreateFourLevelMinDataTree();
auto key = CreateFourLevelMinData()->key();
EXPECT_KEY_DOESNT_CHANGE_WHEN_SHRINKING(key);
}
TEST_F(DataTreeShrinkingTest_KeyDoesntChange, ShrinkAFourLevelTreeWithTwoSiblingLeaves1) {
auto key = CreateFourLevelTreeWithTwoSiblingLeaves1();
auto key = CreateFourLevelWithTwoSiblingLeaves1()->key();
EXPECT_KEY_DOESNT_CHANGE_WHEN_SHRINKING(key);
}
TEST_F(DataTreeShrinkingTest_KeyDoesntChange, ShrinkAFourLevelTreeWithTwoSiblingLeaves2) {
auto key = CreateFourLevelTreeWithTwoSiblingLeaves2();
auto key = CreateFourLevelWithTwoSiblingLeaves2()->key();
EXPECT_KEY_DOESNT_CHANGE_WHEN_SHRINKING(key);
}
TEST_F(DataTreeShrinkingTest_KeyDoesntChange, ShrinkATreeWithFirstChildOfRootFullThreelevelAndSecondChildMindataThreelevel) {
auto key = CreateTreeWithFirstChildOfRootFullThreelevelAndSecondChildMindataThreelevel();
auto key = CreateWithFirstChildOfRootFullThreelevelAndSecondChildMindataThreelevel()->key();
EXPECT_KEY_DOESNT_CHANGE_WHEN_SHRINKING(key);
}
TEST_F(DataTreeShrinkingTest_KeyDoesntChange, ShrinkAThreeLevelTreeWithThreeChildrenOfRoot) {
auto key = CreateThreeLevelTreeWithThreeChildrenOfRoot();
auto key = CreateThreeLevelWithThreeChildrenOfRoot()->key();
EXPECT_KEY_DOESNT_CHANGE_WHEN_SHRINKING(key);
}

View File

@ -69,61 +69,61 @@ public:
};
TEST_F(DataTreeShrinkingTest_Structure, ShrinkATwoLeafTree) {
auto key = CreateTwoLeafTree()->key();
auto key = CreateTwoLeaf()->key();
Shrink(key);
EXPECT_IS_LEAF_ONLY_TREE(key);
}
TEST_F(DataTreeShrinkingTest_Structure, ShrinkAFourNodeThreeLeafTree) {
auto key = CreateFourNodeThreeLeafTree();
auto key = CreateFourNodeThreeLeaf()->key();
Shrink(key);
EXPECT_IS_TWO_LEAF_TREE(key);
}
TEST_F(DataTreeShrinkingTest_Structure, ShrinkATwoInnerNodeOneTwoLeavesTree) {
auto key = CreateTwoInnerNodeOneTwoLeavesTree();
auto key = CreateTwoInnerNodeOneTwoLeaves()->key();
Shrink(key);
EXPECT_IS_TWO_INNER_NODE_TREE_WITH_ONE_LEAF_EACH(key);
}
TEST_F(DataTreeShrinkingTest_Structure, ShrinkATwoInnerNodeTwoOneLeavesTree) {
auto key = CreateTwoInnerNodeTwoOneLeavesTree();
auto key = CreateTwoInnerNodeTwoOneLeaves()->key();
Shrink(key);
EXPECT_IS_TWO_LEAF_TREE(key);
}
TEST_F(DataTreeShrinkingTest_Structure, ShrinkAThreeLevelMinDataTree) {
auto key = CreateThreeLevelMinDataTree();
auto key = CreateThreeLevelMinData()->key();
Shrink(key);
EXPECT_IS_FULL_TWOLEVEL_TREE(key);
}
TEST_F(DataTreeShrinkingTest_Structure, ShrinkAFourLevelMinDataTree) {
auto key = CreateFourLevelMinDataTree();
auto key = CreateFourLevelMinData()->key();
Shrink(key);
EXPECT_IS_FULL_THREELEVEL_TREE(key);
}
TEST_F(DataTreeShrinkingTest_Structure, ShrinkAFourLevelTreeWithTwoSiblingLeaves1) {
auto key = CreateFourLevelTreeWithTwoSiblingLeaves1();
auto key = CreateFourLevelWithTwoSiblingLeaves1()->key();
Shrink(key);
EXPECT_IS_FOURLEVEL_MINDATA_TREE(key);
}
TEST_F(DataTreeShrinkingTest_Structure, ShrinkAFourLevelTreeWithTwoSiblingLeaves2) {
auto key = CreateFourLevelTreeWithTwoSiblingLeaves2();
auto key = CreateFourLevelWithTwoSiblingLeaves2()->key();
Shrink(key);
EXPECT_IS_TREE_WITH_FIRST_CHILD_OF_ROOT_FULL_THREELEVEL_AND_SECOND_CHILD_MINDATA_THREELEVEL_TREE(key);
}
TEST_F(DataTreeShrinkingTest_Structure, ShrinkATreeWithFirstChildOfRootFullThreelevelAndSecondChildMindataThreelevel) {
auto key = CreateTreeWithFirstChildOfRootFullThreelevelAndSecondChildMindataThreelevel();
auto key = CreateWithFirstChildOfRootFullThreelevelAndSecondChildMindataThreelevel()->key();
Shrink(key);
EXPECT_IS_TREE_WITH_FIRST_CHILD_OF_ROOT_FULL_THREELEVEL_AND_SECOND_CHILD_FULL_TWOLEVEL_TREE(key);
}
TEST_F(DataTreeShrinkingTest_Structure, ShrinkAThreeLevelTreeWithThreeChildrenOfRoot) {
auto key = CreateThreeLevelTreeWithThreeChildrenOfRoot();
auto key = CreateThreeLevelWithThreeChildrenOfRoot()->key();
Shrink(key);
EXPECT_IS_THREELEVEL_TREE_WITH_TWO_FULL_TWOLEVEL_TREES(key);
}

View File

@ -13,101 +13,63 @@ void DataTreeShrinkingTest::Shrink(const Key &key) {
tree.removeLastDataLeaf();
}
Key DataTreeShrinkingTest::CreateFourNodeThreeLeafTree() {
auto leaf1 = nodeStore.createNewLeafNode();
auto root = nodeStore.createNewInnerNode(*leaf1);
root->addChild(*nodeStore.createNewLeafNode());
root->addChild(*nodeStore.createNewLeafNode());
return root->key();
unique_ptr<DataInnerNode> DataTreeShrinkingTest::CreateFourNodeThreeLeaf() {
return CreateInner({CreateLeaf(), CreateLeaf(), CreateLeaf()});
}
Key DataTreeShrinkingTest::CreateTwoInnerNodeOneTwoLeavesTree() {
auto leaf1 = nodeStore.createNewLeafNode();
auto node1 = nodeStore.createNewInnerNode(*leaf1);
auto leaf2 = nodeStore.createNewLeafNode();
auto node2 = nodeStore.createNewInnerNode(*leaf2);
node2->addChild(*nodeStore.createNewLeafNode());
auto root = nodeStore.createNewInnerNode(*node1);
root->addChild(*node2);
return root->key();
unique_ptr<DataInnerNode> DataTreeShrinkingTest::CreateTwoInnerNodeOneTwoLeaves() {
return CreateInner({
CreateInner({CreateLeaf()}),
CreateInner({CreateLeaf(), CreateLeaf()})
});
}
Key DataTreeShrinkingTest::CreateTwoInnerNodeTwoOneLeavesTree() {
auto leaf1 = nodeStore.createNewLeafNode();
auto node1 = nodeStore.createNewInnerNode(*leaf1);
node1->addChild(*nodeStore.createNewLeafNode());
auto leaf2 = nodeStore.createNewLeafNode();
auto node2 = nodeStore.createNewInnerNode(*leaf2);
auto root = nodeStore.createNewInnerNode(*node1);
root->addChild(*node2);
return root->key();
unique_ptr<DataInnerNode> DataTreeShrinkingTest::CreateTwoInnerNodeTwoOneLeaves() {
return CreateInner({
CreateInner({CreateLeaf(), CreateLeaf()}),
CreateInner({CreateLeaf()})
});
}
Key DataTreeShrinkingTest::CreateThreeLevelMinDataTree() {
auto fullTwoLevelRoot = CreateFullTwoLevel();
auto root = nodeStore.createNewInnerNode(*fullTwoLevelRoot);
auto leaf = nodeStore.createNewLeafNode();
auto inner = nodeStore.createNewInnerNode(*leaf);
root->addChild(*inner);
return root->key();
unique_ptr<DataInnerNode> DataTreeShrinkingTest::CreateThreeLevelMinData() {
return CreateInner({
CreateFullTwoLevel(),
CreateInner({CreateLeaf()})
});
}
Key DataTreeShrinkingTest::CreateFourLevelMinDataTree() {
auto fullThreeLevelRoot = CreateFullThreeLevel();
auto root = nodeStore.createNewInnerNode(*fullThreeLevelRoot);
auto leaf = nodeStore.createNewLeafNode();
auto inner = nodeStore.createNewInnerNode(*leaf);
auto nodechainRoot = nodeStore.createNewInnerNode(*inner);
root->addChild(*nodechainRoot);
return root->key();
unique_ptr<DataInnerNode> DataTreeShrinkingTest::CreateFourLevelMinData() {
return CreateInner({
CreateFullThreeLevel(),
CreateInner({CreateInner({CreateLeaf()})})
});
}
Key DataTreeShrinkingTest::CreateFourLevelTreeWithTwoSiblingLeaves1() {
auto fullThreeLevelRoot = CreateFullThreeLevel();
auto root = nodeStore.createNewInnerNode(*fullThreeLevelRoot);
auto leaf = nodeStore.createNewLeafNode();
auto inner = nodeStore.createNewInnerNode(*leaf);
inner->addChild(*nodeStore.createNewLeafNode());
auto inner_top = nodeStore.createNewInnerNode(*inner);
root->addChild(*inner_top);
return root->key();
unique_ptr<DataInnerNode> DataTreeShrinkingTest::CreateFourLevelWithTwoSiblingLeaves1() {
return CreateInner({
CreateFullThreeLevel(),
CreateInner({CreateTwoLeaf()})
});
}
Key DataTreeShrinkingTest::CreateFourLevelTreeWithTwoSiblingLeaves2() {
auto fullThreeLevelRoot = CreateFullThreeLevel();
auto root = nodeStore.createNewInnerNode(*fullThreeLevelRoot);
auto leaf1 = nodeStore.createNewLeafNode();
auto inner1 = nodeStore.createNewInnerNode(*leaf1);
FillNode(inner1.get());
auto leaf2 = nodeStore.createNewLeafNode();
auto inner2 = nodeStore.createNewInnerNode(*leaf2);
inner2->addChild(*nodeStore.createNewLeafNode());
auto inner_top = nodeStore.createNewInnerNode(*inner1);
inner_top->addChild(*inner2);
root->addChild(*inner_top);
return root->key();
unique_ptr<DataInnerNode> DataTreeShrinkingTest::CreateFourLevelWithTwoSiblingLeaves2() {
return CreateInner({
CreateFullThreeLevel(),
CreateInner({CreateFullTwoLevel(), CreateTwoLeaf()})
});
}
Key DataTreeShrinkingTest::CreateTreeWithFirstChildOfRootFullThreelevelAndSecondChildMindataThreelevel() {
auto fullThreeLevelRoot = CreateFullThreeLevel();
auto root = nodeStore.createNewInnerNode(*fullThreeLevelRoot);
auto leaf1 = nodeStore.createNewLeafNode();
auto inner1 = nodeStore.createNewInnerNode(*leaf1);
FillNode(inner1.get());
auto leaf2 = nodeStore.createNewLeafNode();
auto inner2 = nodeStore.createNewInnerNode(*leaf2);
auto inner_top = nodeStore.createNewInnerNode(*inner1);
inner_top->addChild(*inner2);
root->addChild(*inner_top);
return root->key();
unique_ptr<DataInnerNode> DataTreeShrinkingTest::CreateWithFirstChildOfRootFullThreelevelAndSecondChildMindataThreelevel() {
return CreateInner({
CreateFullThreeLevel(),
CreateThreeLevelMinData()
});
}
Key DataTreeShrinkingTest::CreateThreeLevelTreeWithThreeChildrenOfRoot() {
auto fullTwoLevelTree1 = CreateFullTwoLevel();
auto fullTwoLevelTree2 = CreateFullTwoLevel();
auto twonodechain = nodeStore.createNewInnerNode(*nodeStore.createNewLeafNode());
auto root = nodeStore.createNewInnerNode(*fullTwoLevelTree1);
root->addChild(*fullTwoLevelTree2);
root->addChild(*twonodechain);
return root->key();
unique_ptr<DataInnerNode> DataTreeShrinkingTest::CreateThreeLevelWithThreeChildrenOfRoot() {
return CreateInner({
CreateFullTwoLevel(),
CreateFullTwoLevel(),
CreateInner({CreateLeaf()})
});
}

View File

@ -13,15 +13,15 @@ class DataTreeShrinkingTest: public DataTreeTest {
public:
void Shrink(const blockstore::Key &key);
blockstore::Key CreateFourNodeThreeLeafTree();
blockstore::Key CreateTwoInnerNodeOneTwoLeavesTree();
blockstore::Key CreateTwoInnerNodeTwoOneLeavesTree();
blockstore::Key CreateThreeLevelMinDataTree();
blockstore::Key CreateFourLevelMinDataTree();
blockstore::Key CreateFourLevelTreeWithTwoSiblingLeaves1();
blockstore::Key CreateFourLevelTreeWithTwoSiblingLeaves2();
blockstore::Key CreateTreeWithFirstChildOfRootFullThreelevelAndSecondChildMindataThreelevel();
blockstore::Key CreateThreeLevelTreeWithThreeChildrenOfRoot();
std::unique_ptr<blobstore::onblocks::datanodestore::DataInnerNode> CreateFourNodeThreeLeaf();
std::unique_ptr<blobstore::onblocks::datanodestore::DataInnerNode> CreateTwoInnerNodeOneTwoLeaves();
std::unique_ptr<blobstore::onblocks::datanodestore::DataInnerNode> CreateTwoInnerNodeTwoOneLeaves();
std::unique_ptr<blobstore::onblocks::datanodestore::DataInnerNode> CreateThreeLevelMinData();
std::unique_ptr<blobstore::onblocks::datanodestore::DataInnerNode> CreateFourLevelMinData();
std::unique_ptr<blobstore::onblocks::datanodestore::DataInnerNode> CreateFourLevelWithTwoSiblingLeaves1();
std::unique_ptr<blobstore::onblocks::datanodestore::DataInnerNode> CreateFourLevelWithTwoSiblingLeaves2();
std::unique_ptr<blobstore::onblocks::datanodestore::DataInnerNode> CreateWithFirstChildOfRootFullThreelevelAndSecondChildMindataThreelevel();
std::unique_ptr<blobstore::onblocks::datanodestore::DataInnerNode> CreateThreeLevelWithThreeChildrenOfRoot();
};

View File

@ -13,6 +13,7 @@ using blockstore::Key;
using std::make_unique;
using std::unique_ptr;
using std::initializer_list;
using std::vector;
using cpputils::dynamic_pointer_move;
DataTreeTest::DataTreeTest()
@ -23,7 +24,17 @@ unique_ptr<DataLeafNode> DataTreeTest::CreateLeaf() {
return nodeStore.createNewLeafNode();
}
unique_ptr<DataInnerNode> DataTreeTest::CreateInner(initializer_list<unique_ptr<DataNode>> children) {
vector<const DataNode*> childrenVector(children.size());
std::transform(children.begin(), children.end(), childrenVector.begin(), [](const unique_ptr<DataNode> &ptr) {return ptr.get();});
return CreateInner(childrenVector);
}
unique_ptr<DataInnerNode> DataTreeTest::CreateInner(initializer_list<const DataNode*> children) {
return CreateInner(vector<const DataNode*>(children));
}
unique_ptr<DataInnerNode> DataTreeTest::CreateInner(vector<const DataNode*> children) {
assert(children.size() >= 1);
auto node = nodeStore.createNewInnerNode(**children.begin());
for(auto child = children.begin()+1; child != children.end(); ++child) {

View File

@ -14,7 +14,9 @@ public:
DataTreeTest();
std::unique_ptr<blobstore::onblocks::datanodestore::DataLeafNode> CreateLeaf();
std::unique_ptr<blobstore::onblocks::datanodestore::DataInnerNode> CreateInner(std::vector<const blobstore::onblocks::datanodestore::DataNode *> children);
std::unique_ptr<blobstore::onblocks::datanodestore::DataInnerNode> CreateInner(std::initializer_list<const blobstore::onblocks::datanodestore::DataNode *> children);
std::unique_ptr<blobstore::onblocks::datanodestore::DataInnerNode> CreateInner(std::initializer_list<std::unique_ptr<blobstore::onblocks::datanodestore::DataNode>> children);
std::unique_ptr<blobstore::onblocks::datatreestore::DataTree> CreateLeafOnlyTree();
std::unique_ptr<blobstore::onblocks::datanodestore::DataInnerNode> CreateTwoLeaf();