From fee8cd42eb1479dd9346c219b29e84c33711e3d0 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Mon, 23 Feb 2015 17:03:45 +0100 Subject: [PATCH] Refactoring test cases --- .../DataTreeGrowingTest_DataStaysIntact.cpp | 2 +- .../DataTreeGrowingTest_DepthFlags.cpp | 4 +- .../DataTreeGrowingTest_KeyDoesntChange.cpp | 4 +- .../growing/DataTreeGrowingTest_Structure.cpp | 4 +- ...derNodeWithLessThanKChildrenOrNullTest.cpp | 4 +- .../testutils/DataTreeShrinkingTest.cpp | 14 ++--- .../datatreestore/testutils/DataTreeTest.cpp | 51 +++++++++++-------- .../datatreestore/testutils/DataTreeTest.h | 8 ++- 8 files changed, 51 insertions(+), 40 deletions(-) diff --git a/test/implementations/onblocks/datatreestore/growing/DataTreeGrowingTest_DataStaysIntact.cpp b/test/implementations/onblocks/datatreestore/growing/DataTreeGrowingTest_DataStaysIntact.cpp index 443914f4..67cc3aca 100644 --- a/test/implementations/onblocks/datatreestore/growing/DataTreeGrowingTest_DataStaysIntact.cpp +++ b/test/implementations/onblocks/datatreestore/growing/DataTreeGrowingTest_DataStaysIntact.cpp @@ -38,7 +38,7 @@ public: } unique_ptr CreateFullTwoLevelTreeWithData(TwoLevelDataFixture *data) { - auto root = LoadInnerNode(CreateFullTwoLevelTree()); + auto root = CreateFullTwoLevel(); assert(root->numChildren() == DataInnerNode::MAX_STORED_CHILDREN); data->FillInto(root.get()); return make_unique(&nodeStore, std::move(root)); diff --git a/test/implementations/onblocks/datatreestore/growing/DataTreeGrowingTest_DepthFlags.cpp b/test/implementations/onblocks/datatreestore/growing/DataTreeGrowingTest_DepthFlags.cpp index 7a0d395e..0a9f7693 100644 --- a/test/implementations/onblocks/datatreestore/growing/DataTreeGrowingTest_DepthFlags.cpp +++ b/test/implementations/onblocks/datatreestore/growing/DataTreeGrowingTest_DepthFlags.cpp @@ -37,7 +37,7 @@ TEST_F(DataTreeGrowingTest_DepthFlags, GrowAThreeNodeChainedTree) { } TEST_F(DataTreeGrowingTest_DepthFlags, GrowAFullTwoLevelTree) { - auto key = CreateFullTwoLevelTree(); + auto key = CreateFullTwoLevel()->key(); AddLeafTo(key); CHECK_DEPTH(2, key); } @@ -49,7 +49,7 @@ TEST_F(DataTreeGrowingTest_DepthFlags, GrowAThreeLevelTreeWithLowerLevelFull) { } TEST_F(DataTreeGrowingTest_DepthFlags, GrowAFullThreeLevelTree) { - auto key = CreateFullThreeLevelTree(); + auto key = CreateFullThreeLevel()->key(); AddLeafTo(key); CHECK_DEPTH(3, key); } diff --git a/test/implementations/onblocks/datatreestore/growing/DataTreeGrowingTest_KeyDoesntChange.cpp b/test/implementations/onblocks/datatreestore/growing/DataTreeGrowingTest_KeyDoesntChange.cpp index bb5d7b7e..2e2b4c1f 100644 --- a/test/implementations/onblocks/datatreestore/growing/DataTreeGrowingTest_KeyDoesntChange.cpp +++ b/test/implementations/onblocks/datatreestore/growing/DataTreeGrowingTest_KeyDoesntChange.cpp @@ -37,12 +37,12 @@ TEST_F(DataTreeGrowingTest_KeyDoesntChange, GrowAThreeLevelTreeWithLowerLevelFul } TEST_F(DataTreeGrowingTest_KeyDoesntChange, GrowAFullTwoLevelTree) { - auto root_key = CreateFullTwoLevelTree(); + auto root_key = CreateFullTwoLevel()->key(); EXPECT_KEY_DOESNT_CHANGE_WHEN_GROWING(root_key); } TEST_F(DataTreeGrowingTest_KeyDoesntChange, GrowAFullThreeLevelTree) { - auto root_key = CreateFullThreeLevelTree(); + auto root_key = CreateFullThreeLevel()->key(); EXPECT_KEY_DOESNT_CHANGE_WHEN_GROWING(root_key); } diff --git a/test/implementations/onblocks/datatreestore/growing/DataTreeGrowingTest_Structure.cpp b/test/implementations/onblocks/datatreestore/growing/DataTreeGrowingTest_Structure.cpp index a9317de2..cc54b9fb 100644 --- a/test/implementations/onblocks/datatreestore/growing/DataTreeGrowingTest_Structure.cpp +++ b/test/implementations/onblocks/datatreestore/growing/DataTreeGrowingTest_Structure.cpp @@ -39,7 +39,7 @@ TEST_F(DataTreeGrowingTest_Structure, GrowAFullTwoLevelTreeFromGroundUp) { } TEST_F(DataTreeGrowingTest_Structure, GrowAFullTwoLevelTree) { - auto root_key = CreateFullTwoLevelTree(); + auto root_key = CreateFullTwoLevel()->key(); AddLeafTo(root_key); auto root = LoadInnerNode(root_key); @@ -69,7 +69,7 @@ TEST_F(DataTreeGrowingTest_Structure, GrowAFullThreeLevelTreeFromGroundUp) { } TEST_F(DataTreeGrowingTest_Structure, GrowAFullThreeLevelTree) { - auto root_key = CreateFullThreeLevelTree(); + auto root_key = CreateFullThreeLevel()->key(); AddLeafTo(root_key); auto root = LoadInnerNode(root_key); diff --git a/test/implementations/onblocks/datatreestore/impl/GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest.cpp b/test/implementations/onblocks/datatreestore/impl/GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest.cpp index 7bd1e55e..46d9394d 100644 --- a/test/implementations/onblocks/datatreestore/impl/GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest.cpp +++ b/test/implementations/onblocks/datatreestore/impl/GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest.cpp @@ -96,13 +96,13 @@ TEST_F(GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest, LargerTree) } TEST_F(GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest, FullTwoLevelTree) { - auto root = nodeStore.load(CreateFullTwoLevelTree()); + auto root = CreateFullTwoLevel(); auto result = GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNull(&nodeStore, root.get()); EXPECT_EQ(nullptr, result.get()); } TEST_F(GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest, FullThreeLevelTree) { - auto root = nodeStore.load(CreateFullThreeLevelTree()); + auto root = CreateFullThreeLevel(); auto result = GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNull(&nodeStore, root.get()); EXPECT_EQ(nullptr, result.get()); } diff --git a/test/implementations/onblocks/datatreestore/shrinking/testutils/DataTreeShrinkingTest.cpp b/test/implementations/onblocks/datatreestore/shrinking/testutils/DataTreeShrinkingTest.cpp index 34ee4f69..844e662b 100644 --- a/test/implementations/onblocks/datatreestore/shrinking/testutils/DataTreeShrinkingTest.cpp +++ b/test/implementations/onblocks/datatreestore/shrinking/testutils/DataTreeShrinkingTest.cpp @@ -44,7 +44,7 @@ Key DataTreeShrinkingTest::CreateTwoInnerNodeTwoOneLeavesTree() { } Key DataTreeShrinkingTest::CreateThreeLevelMinDataTree() { - auto fullTwoLevelRoot = nodeStore.load(CreateFullTwoLevelTree()); + auto fullTwoLevelRoot = CreateFullTwoLevel(); auto root = nodeStore.createNewInnerNode(*fullTwoLevelRoot); auto leaf = nodeStore.createNewLeafNode(); auto inner = nodeStore.createNewInnerNode(*leaf); @@ -53,7 +53,7 @@ Key DataTreeShrinkingTest::CreateThreeLevelMinDataTree() { } Key DataTreeShrinkingTest::CreateFourLevelMinDataTree() { - auto fullThreeLevelRoot = nodeStore.load(CreateFullThreeLevelTree()); + auto fullThreeLevelRoot = CreateFullThreeLevel(); auto root = nodeStore.createNewInnerNode(*fullThreeLevelRoot); auto leaf = nodeStore.createNewLeafNode(); auto inner = nodeStore.createNewInnerNode(*leaf); @@ -63,7 +63,7 @@ Key DataTreeShrinkingTest::CreateFourLevelMinDataTree() { } Key DataTreeShrinkingTest::CreateFourLevelTreeWithTwoSiblingLeaves1() { - auto fullThreeLevelRoot = nodeStore.load(CreateFullThreeLevelTree()); + auto fullThreeLevelRoot = CreateFullThreeLevel(); auto root = nodeStore.createNewInnerNode(*fullThreeLevelRoot); auto leaf = nodeStore.createNewLeafNode(); auto inner = nodeStore.createNewInnerNode(*leaf); @@ -74,7 +74,7 @@ Key DataTreeShrinkingTest::CreateFourLevelTreeWithTwoSiblingLeaves1() { } Key DataTreeShrinkingTest::CreateFourLevelTreeWithTwoSiblingLeaves2() { - auto fullThreeLevelRoot = nodeStore.load(CreateFullThreeLevelTree()); + auto fullThreeLevelRoot = CreateFullThreeLevel(); auto root = nodeStore.createNewInnerNode(*fullThreeLevelRoot); auto leaf1 = nodeStore.createNewLeafNode(); auto inner1 = nodeStore.createNewInnerNode(*leaf1); @@ -89,7 +89,7 @@ Key DataTreeShrinkingTest::CreateFourLevelTreeWithTwoSiblingLeaves2() { } Key DataTreeShrinkingTest::CreateTreeWithFirstChildOfRootFullThreelevelAndSecondChildMindataThreelevel() { - auto fullThreeLevelRoot = nodeStore.load(CreateFullThreeLevelTree()); + auto fullThreeLevelRoot = CreateFullThreeLevel(); auto root = nodeStore.createNewInnerNode(*fullThreeLevelRoot); auto leaf1 = nodeStore.createNewLeafNode(); auto inner1 = nodeStore.createNewInnerNode(*leaf1); @@ -103,8 +103,8 @@ Key DataTreeShrinkingTest::CreateTreeWithFirstChildOfRootFullThreelevelAndSecond } Key DataTreeShrinkingTest::CreateThreeLevelTreeWithThreeChildrenOfRoot() { - auto fullTwoLevelTree1 = nodeStore.load(CreateFullTwoLevelTree()); - auto fullTwoLevelTree2 = nodeStore.load(CreateFullTwoLevelTree()); + auto fullTwoLevelTree1 = CreateFullTwoLevel(); + auto fullTwoLevelTree2 = CreateFullTwoLevel(); auto twonodechain = nodeStore.createNewInnerNode(*nodeStore.createNewLeafNode()); auto root = nodeStore.createNewInnerNode(*fullTwoLevelTree1); root->addChild(*fullTwoLevelTree2); diff --git a/test/implementations/onblocks/datatreestore/testutils/DataTreeTest.cpp b/test/implementations/onblocks/datatreestore/testutils/DataTreeTest.cpp index 0825d654..156f3ae9 100644 --- a/test/implementations/onblocks/datatreestore/testutils/DataTreeTest.cpp +++ b/test/implementations/onblocks/datatreestore/testutils/DataTreeTest.cpp @@ -4,6 +4,7 @@ #include using blobstore::onblocks::datanodestore::DataNodeStore; +using blobstore::onblocks::datanodestore::DataNode; using blobstore::onblocks::datanodestore::DataInnerNode; using blobstore::onblocks::datanodestore::DataLeafNode; using blobstore::onblocks::datatreestore::DataTree; @@ -11,47 +12,52 @@ using blockstore::testfake::FakeBlockStore; using blockstore::Key; using std::make_unique; using std::unique_ptr; +using std::initializer_list; using cpputils::dynamic_pointer_move; DataTreeTest::DataTreeTest() :nodeStore(make_unique()) { } +unique_ptr DataTreeTest::CreateLeaf() { + return nodeStore.createNewLeafNode(); +} + +unique_ptr DataTreeTest::CreateInner(initializer_list children) { + assert(children.size() >= 1); + auto node = nodeStore.createNewInnerNode(**children.begin()); + for(auto child = children.begin()+1; child != children.end(); ++child) { + node->addChild(**child); + } + return node; +} + unique_ptr DataTreeTest::CreateLeafOnlyTree() { - auto leafnode = nodeStore.createNewLeafNode(); - return make_unique(&nodeStore, std::move(leafnode)); + return make_unique(&nodeStore, CreateLeaf()); } void DataTreeTest::FillNode(DataInnerNode *node) { for(unsigned int i=node->numChildren(); i < DataInnerNode::MAX_STORED_CHILDREN; ++i) { - node->addChild(*nodeStore.createNewLeafNode()); + node->addChild(*CreateLeaf()); } } void DataTreeTest::FillNodeTwoLevel(DataInnerNode *node) { for(unsigned int i=node->numChildren(); i < DataInnerNode::MAX_STORED_CHILDREN; ++i) { - auto inner_node = nodeStore.createNewInnerNode(*nodeStore.createNewLeafNode()); - for(unsigned int j = 1;j < DataInnerNode::MAX_STORED_CHILDREN; ++j) { - inner_node->addChild(*nodeStore.createNewLeafNode()); - } - node->addChild(*inner_node); + node->addChild(*CreateFullTwoLevel()); } } -Key DataTreeTest::CreateFullTwoLevelTree() { - auto leaf = nodeStore.createNewLeafNode(); - auto root = nodeStore.createNewInnerNode(*leaf); +unique_ptr DataTreeTest::CreateFullTwoLevel() { + auto root = CreateInner({CreateLeaf().get()}); FillNode(root.get()); - return root->key(); + return root; } -Key DataTreeTest::CreateFullThreeLevelTree() { - auto leaf = nodeStore.createNewLeafNode(); - auto node = nodeStore.createNewInnerNode(*leaf); - auto root = nodeStore.createNewInnerNode(*node); - FillNode(node.get()); +unique_ptr DataTreeTest::CreateFullThreeLevel() { + auto root = CreateInner({CreateFullTwoLevel().get()}); FillNodeTwoLevel(root.get()); - return root->key(); + return root; } unique_ptr DataTreeTest::LoadInnerNode(const Key &key) { @@ -68,11 +74,12 @@ unique_ptr DataTreeTest::LoadLeafNode(const Key &key) { return casted; } +unique_ptr DataTreeTest::CreateTwoLeaf() { + return CreateInner({CreateLeaf().get(), CreateLeaf().get()}); +} + unique_ptr DataTreeTest::CreateTwoLeafTree() { - auto leaf1 = nodeStore.createNewLeafNode(); - auto root = nodeStore.createNewInnerNode(*leaf1); - root->addChild(*nodeStore.createNewLeafNode()); - return make_unique(&nodeStore, std::move(root)); + return make_unique(&nodeStore, CreateTwoLeaf()); } void DataTreeTest::EXPECT_IS_LEAF_NODE(const Key &key) { diff --git a/test/implementations/onblocks/datatreestore/testutils/DataTreeTest.h b/test/implementations/onblocks/datatreestore/testutils/DataTreeTest.h index a8fda2a0..234d368b 100644 --- a/test/implementations/onblocks/datatreestore/testutils/DataTreeTest.h +++ b/test/implementations/onblocks/datatreestore/testutils/DataTreeTest.h @@ -13,12 +13,16 @@ class DataTreeTest: public ::testing::Test { public: DataTreeTest(); + std::unique_ptr CreateLeaf(); + std::unique_ptr CreateInner(std::initializer_list children); + std::unique_ptr CreateLeafOnlyTree(); + std::unique_ptr CreateTwoLeaf(); std::unique_ptr CreateTwoLeafTree(); void FillNode(blobstore::onblocks::datanodestore::DataInnerNode *node); void FillNodeTwoLevel(blobstore::onblocks::datanodestore::DataInnerNode *node); - blockstore::Key CreateFullTwoLevelTree(); - blockstore::Key CreateFullThreeLevelTree(); + std::unique_ptr CreateFullTwoLevel(); + std::unique_ptr CreateFullThreeLevel(); blobstore::onblocks::datanodestore::DataNodeStore nodeStore; std::unique_ptr LoadInnerNode(const blockstore::Key &key);