From: Mukund Sivaraman Date: Mon, 25 Feb 2013 17:10:03 +0000 (+0530) Subject: [2811] Move common code to a separate function X-Git-Tag: bind10-1.2.0beta1-release~301^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f6fd9cc583267c0ddf779ee0d0fce7ffa697c554;p=thirdparty%2Fkea.git [2811] Move common code to a separate function --- diff --git a/src/lib/datasrc/tests/memory/domaintree_unittest.cc b/src/lib/datasrc/tests/memory/domaintree_unittest.cc index 48ac111ff6..e65da18b24 100644 --- a/src/lib/datasrc/tests/memory/domaintree_unittest.cc +++ b/src/lib/datasrc/tests/memory/domaintree_unittest.cc @@ -150,6 +150,22 @@ TEST_F(DomainTreeTest, getDistance) { } } +void +checkDistances(const TestDomainTree& tree, size_t distance) { + TestDomainTreeNodeChain node_path; + const TestDomainTreeNode* node = NULL; + + // Try to find a node left of the left-most node, and start from its + // next node (which is the left-most node in its subtree). + EXPECT_EQ(TestDomainTree::NOTFOUND, + tree.find(Name("0"), &node, node_path, NULL, NULL)); + while ((node = tree.nextNode(node_path)) != NULL) { + // The distance from each node to its sub-tree root must be less + // than 2 * log(n). + EXPECT_GE(2 * distance, node->getDistance()); + } +} + TEST_F(DomainTreeTest, checkDistanceRandom) { // This test checks an important performance-related property of the // DomainTree (a red-black tree), which is important for us: the @@ -190,18 +206,7 @@ TEST_F(DomainTreeTest, checkDistanceRandom) { EXPECT_EQ(static_cast(NULL), dtnode->setData(new int(i + 1))); } - TestDomainTreeNodeChain node_path; - const TestDomainTreeNode* node = NULL; - - // Try to find a node left of the left-most node, and start from its - // next node (which is the left-most node in its subtree). - EXPECT_EQ(TestDomainTree::NOTFOUND, - mytree.find(Name("0"), &node, node_path, NULL, NULL)); - while ((node = mytree.nextNode(node_path)) != NULL) { - // The distance from each node to its sub-tree root must be less - // than 2 * log(n). - EXPECT_GE(2 * log_num_nodes, node->getDistance()); - } + checkDistances(mytree, log_num_nodes); } TEST_F(DomainTreeTest, checkDistanceSorted) { @@ -230,18 +235,7 @@ TEST_F(DomainTreeTest, checkDistanceSorted) { EXPECT_EQ(static_cast(NULL), dtnode->setData(new int(i + 1))); } - TestDomainTreeNodeChain node_path; - const TestDomainTreeNode* node = NULL; - - // Try to find a node left of the left-most node, and start from its - // next node (which is the left-most node in its subtree). - EXPECT_EQ(TestDomainTree::NOTFOUND, - mytree.find(Name("0"), &node, node_path, NULL, NULL)); - while ((node = mytree.nextNode(node_path)) != NULL) { - // The distance from each node to its sub-tree root must be less - // than 2 * log(n). - EXPECT_GE(2 * log_num_nodes, node->getDistance()); - } + checkDistances(mytree, log_num_nodes); } TEST_F(DomainTreeTest, setGetData) {