2016-02-11 15:19:58 +01:00
|
|
|
#include <gtest/gtest.h>
|
2015-01-26 00:38:06 +01:00
|
|
|
|
2015-02-20 18:31:18 +01:00
|
|
|
#include "../testutils/DataTreeTest.h"
|
2016-02-11 15:19:58 +01:00
|
|
|
#include "blobstore/implementations/onblocks/datatreestore/DataTree.h"
|
|
|
|
#include "blobstore/implementations/onblocks/datanodestore/DataLeafNode.h"
|
|
|
|
#include "blobstore/implementations/onblocks/datanodestore/DataInnerNode.h"
|
|
|
|
#include <blockstore/implementations/testfake/FakeBlockStore.h>
|
|
|
|
#include "blobstore/implementations/onblocks/datatreestore/impl/algorithms.h"
|
2015-01-26 00:38:06 +01:00
|
|
|
|
|
|
|
using ::testing::Test;
|
|
|
|
using std::pair;
|
|
|
|
using std::make_pair;
|
|
|
|
|
|
|
|
using blobstore::onblocks::datanodestore::DataNodeStore;
|
|
|
|
using blobstore::onblocks::datanodestore::DataNode;
|
|
|
|
using blobstore::onblocks::datanodestore::DataInnerNode;
|
|
|
|
using blockstore::testfake::FakeBlockStore;
|
|
|
|
using blockstore::Key;
|
2016-07-15 12:48:20 +02:00
|
|
|
using cpputils::Data;
|
2015-02-21 01:58:23 +01:00
|
|
|
using namespace blobstore::onblocks::datatreestore::algorithms;
|
2015-01-26 00:38:06 +01:00
|
|
|
|
2015-02-21 01:58:23 +01:00
|
|
|
class GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest: public DataTreeTest {
|
2015-01-26 00:38:06 +01:00
|
|
|
public:
|
|
|
|
struct TestData {
|
|
|
|
Key rootNode;
|
|
|
|
Key expectedResult;
|
|
|
|
};
|
|
|
|
|
|
|
|
void check(const TestData &testData) {
|
2015-06-28 16:59:13 +02:00
|
|
|
auto root = nodeStore->load(testData.rootNode).value();
|
2015-02-24 22:44:10 +01:00
|
|
|
auto result = GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNull(nodeStore, root.get());
|
2015-01-26 00:38:06 +01:00
|
|
|
EXPECT_EQ(testData.expectedResult, result->key());
|
|
|
|
}
|
|
|
|
|
|
|
|
TestData CreateTwoRightBorderNodes() {
|
2015-02-23 17:45:10 +01:00
|
|
|
auto node = CreateInner({CreateLeaf()});
|
2015-06-21 14:40:52 +02:00
|
|
|
return TestData{node->key(), node->key()};
|
2015-01-26 00:38:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TestData CreateThreeRightBorderNodes() {
|
2015-02-23 17:45:10 +01:00
|
|
|
auto node = CreateInner({CreateLeaf()});
|
|
|
|
auto root = CreateInner({node.get()});
|
2015-06-21 14:40:52 +02:00
|
|
|
return TestData{root->key(), node->key()};
|
2015-01-26 00:38:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TestData CreateThreeRightBorderNodes_LastFull() {
|
2015-02-23 17:45:10 +01:00
|
|
|
auto root = CreateInner({CreateFullTwoLevel()});
|
2015-06-21 14:40:52 +02:00
|
|
|
return TestData{root->key(), root->key()};
|
2015-01-26 00:38:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TestData CreateLargerTree() {
|
2015-02-23 17:45:10 +01:00
|
|
|
auto node = CreateInner({CreateLeaf(), CreateLeaf()});
|
|
|
|
auto root = CreateInner({CreateFullTwoLevel().get(), node.get()});
|
2015-06-21 14:40:52 +02:00
|
|
|
return TestData{root->key(), node->key()};
|
2015-01-26 00:38:06 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-21 01:58:23 +01:00
|
|
|
TEST_F(GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest, Leaf) {
|
2016-07-15 12:48:20 +02:00
|
|
|
auto leaf = nodeStore->createNewLeafNode(Data(0));
|
2015-02-24 22:44:10 +01:00
|
|
|
auto result = GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNull(nodeStore, leaf.get());
|
2015-01-26 00:38:06 +01:00
|
|
|
EXPECT_EQ(nullptr, result.get());
|
|
|
|
}
|
|
|
|
|
2015-02-21 01:58:23 +01:00
|
|
|
TEST_F(GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest, TwoRightBorderNodes) {
|
2015-01-26 00:38:06 +01:00
|
|
|
auto testData = CreateTwoRightBorderNodes();
|
|
|
|
check(testData);
|
|
|
|
}
|
|
|
|
|
2015-02-21 01:58:23 +01:00
|
|
|
TEST_F(GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest, ThreeRightBorderNodes) {
|
2015-01-26 00:38:06 +01:00
|
|
|
auto testData = CreateThreeRightBorderNodes();
|
|
|
|
check(testData);
|
|
|
|
}
|
|
|
|
|
2015-02-21 01:58:23 +01:00
|
|
|
TEST_F(GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest, ThreeRightBorderNodes_LastFull) {
|
2015-01-26 00:38:06 +01:00
|
|
|
auto testData = CreateThreeRightBorderNodes_LastFull();
|
|
|
|
check(testData);
|
|
|
|
}
|
|
|
|
|
2015-02-21 01:58:23 +01:00
|
|
|
TEST_F(GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest, LargerTree) {
|
2015-01-26 00:38:06 +01:00
|
|
|
auto testData = CreateLargerTree();
|
|
|
|
check(testData);
|
|
|
|
}
|
|
|
|
|
2015-02-21 01:58:23 +01:00
|
|
|
TEST_F(GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest, FullTwoLevelTree) {
|
2015-02-23 17:03:45 +01:00
|
|
|
auto root = CreateFullTwoLevel();
|
2015-02-24 22:44:10 +01:00
|
|
|
auto result = GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNull(nodeStore, root.get());
|
2015-01-26 00:38:06 +01:00
|
|
|
EXPECT_EQ(nullptr, result.get());
|
|
|
|
}
|
|
|
|
|
2015-02-21 01:58:23 +01:00
|
|
|
TEST_F(GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest, FullThreeLevelTree) {
|
2015-02-23 17:03:45 +01:00
|
|
|
auto root = CreateFullThreeLevel();
|
2015-02-24 22:44:10 +01:00
|
|
|
auto result = GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNull(nodeStore, root.get());
|
2015-01-26 00:38:06 +01:00
|
|
|
EXPECT_EQ(nullptr, result.get());
|
|
|
|
}
|