Skip to content

Commit

Permalink
[TEST] Rename and adapt the For Loop test for every iterators.
Browse files Browse the repository at this point in the history
  • Loading branch information
frozar committed Jan 3, 2018
1 parent 4f00996 commit d521c6e
Showing 1 changed file with 200 additions and 1 deletion.
201 changes: 200 additions & 1 deletion test/octree/test_octree_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,15 @@ TEST_F (OctreeBaseBeginEndIteratorsTest, BreadthEnd)
EXPECT_NE (it_a_2, it_b);
}

TEST_F (OctreeBaseBeginEndIteratorsTest, ForLoop)
////////////////////////////////////////////////////////
// OctreeBase Iterator For Loop Case
////////////////////////////////////////////////////////

struct OctreeBaseIteratorsForLoopTest : public OctreeBaseBeginEndIteratorsTest
{
};

TEST_F (OctreeBaseIteratorsForLoopTest, DefaultIterator)
{
// Useful types
typedef typename OctreeT::Iterator IteratorT;
Expand Down Expand Up @@ -445,6 +453,197 @@ TEST_F (OctreeBaseBeginEndIteratorsTest, ForLoop)
ASSERT_EQ (oct_a_.getBranchCount (), branch_count);
}

TEST_F (OctreeBaseIteratorsForLoopTest, LeafNodeIterator)
{
// Useful types
typedef typename OctreeT::LeafNodeIterator IteratorT;

// Default initialization
IteratorT it_a;
IteratorT it_a_end = oct_a_.leaf_end ();

unsigned int node_count = 0;
unsigned int branch_count = 0;
unsigned int leaf_count = 0;

// Iterate over every node of the octree oct_a_.
for (it_a = oct_a_.leaf_begin (); it_a != it_a_end; ++it_a)
{
// store node, branch and leaf count
const pcl::octree::OctreeNode* node = it_a.getCurrentOctreeNode ();
if (node->getNodeType () == pcl::octree::BRANCH_NODE)
{
branch_count++;
}
else if (node->getNodeType () == pcl::octree::LEAF_NODE)
{
leaf_count++;
}
node_count++;
}

// Check the node_count, branch_count and leaf_count values
ASSERT_EQ (leaf_count, 64);
ASSERT_EQ (branch_count, 0);
ASSERT_EQ (oct_a_.getLeafCount (), leaf_count);

// Iterate over the octree oct_a_ with a depth max of 1.
// As oct_a_ has a depth level of 2, we should only iterate
// over 9 branch node: the root node + 8 node at depth 1
node_count = 0;
branch_count = 0;
leaf_count = 0;
unsigned int max_depth = 1;
for (it_a = oct_a_.leaf_begin (max_depth); it_a != it_a_end; ++it_a)
{
// store node, branch and leaf count
const pcl::octree::OctreeNode* node = it_a.getCurrentOctreeNode ();
if (node->getNodeType () == pcl::octree::BRANCH_NODE)
{
branch_count++;
}
else if (node->getNodeType () == pcl::octree::LEAF_NODE)
{
leaf_count++;
}
node_count++;
}

// Check the node_count, branch_count and leaf_count values
ASSERT_EQ (leaf_count, 0);
ASSERT_EQ (branch_count, 0);
}

TEST_F (OctreeBaseIteratorsForLoopTest, DepthFirstIterator)
{
// Useful types
typedef typename OctreeT::DepthFirstIterator IteratorT;

// Default initialization
IteratorT it_a;
IteratorT it_a_end = oct_a_.depth_end ();

unsigned int node_count = 0;
unsigned int branch_count = 0;
unsigned int leaf_count = 0;

// Iterate over every node of the octree oct_a_.
for (it_a = oct_a_.depth_begin (); it_a != it_a_end; ++it_a)
{
// store node, branch and leaf count
const pcl::octree::OctreeNode* node = it_a.getCurrentOctreeNode ();
if (node->getNodeType () == pcl::octree::BRANCH_NODE)
{
branch_count++;
}
else if (node->getNodeType () == pcl::octree::LEAF_NODE)
{
leaf_count++;
}
node_count++;
}

// Check the node_count, branch_count and leaf_count values
ASSERT_EQ (leaf_count, 64);
ASSERT_EQ (branch_count, 9);
ASSERT_EQ (branch_count + leaf_count, node_count);
ASSERT_EQ (oct_a_.getLeafCount (), leaf_count);
ASSERT_EQ (oct_a_.getBranchCount (), branch_count);

// Iterate over the octree oct_a_ with a depth max of 1.
// As oct_a_ has a depth level of 2, we should only iterate
// over 9 branch node: the root node + 8 node at depth 1
node_count = 0;
branch_count = 0;
leaf_count = 0;
unsigned int max_depth = 1;
for (it_a = oct_a_.depth_begin (max_depth); it_a != it_a_end; ++it_a)
{
// store node, branch and leaf count
const pcl::octree::OctreeNode* node = it_a.getCurrentOctreeNode ();
if (node->getNodeType () == pcl::octree::BRANCH_NODE)
{
branch_count++;
}
else if (node->getNodeType () == pcl::octree::LEAF_NODE)
{
leaf_count++;
}
node_count++;
}

// Check the node_count, branch_count and leaf_count values
ASSERT_EQ (leaf_count, 0);
ASSERT_EQ (branch_count, 9);
ASSERT_EQ (branch_count + leaf_count, node_count);
ASSERT_EQ (oct_a_.getBranchCount (), branch_count);
}

TEST_F (OctreeBaseIteratorsForLoopTest, BreadthFirstIterator)
{
// Useful types
typedef typename OctreeT::BreadthFirstIterator IteratorT;

// Default initialization
IteratorT it_a;
IteratorT it_a_end = oct_a_.breadth_end ();

unsigned int node_count = 0;
unsigned int branch_count = 0;
unsigned int leaf_count = 0;

// Iterate over every node of the octree oct_a_.
for (it_a = oct_a_.breadth_begin (); it_a != it_a_end; ++it_a)
{
// store node, branch and leaf count
const pcl::octree::OctreeNode* node = it_a.getCurrentOctreeNode ();
if (node->getNodeType () == pcl::octree::BRANCH_NODE)
{
branch_count++;
}
else if (node->getNodeType () == pcl::octree::LEAF_NODE)
{
leaf_count++;
}
node_count++;
}

// Check the node_count, branch_count and leaf_count values
ASSERT_EQ (leaf_count, 64);
ASSERT_EQ (branch_count, 9);
ASSERT_EQ (branch_count + leaf_count, node_count);
ASSERT_EQ (oct_a_.getLeafCount (), leaf_count);
ASSERT_EQ (oct_a_.getBranchCount (), branch_count);

// Iterate over the octree oct_a_ with a depth max of 1.
// As oct_a_ has a depth level of 2, we should only iterate
// over 9 branch node: the root node + 8 node at depth 1
node_count = 0;
branch_count = 0;
leaf_count = 0;
unsigned int max_depth = 1;
for (it_a = oct_a_.breadth_begin (max_depth); it_a != it_a_end; ++it_a)
{
// store node, branch and leaf count
const pcl::octree::OctreeNode* node = it_a.getCurrentOctreeNode ();
if (node->getNodeType () == pcl::octree::BRANCH_NODE)
{
branch_count++;
}
else if (node->getNodeType () == pcl::octree::LEAF_NODE)
{
leaf_count++;
}
node_count++;
}

// Check the node_count, branch_count and leaf_count values
ASSERT_EQ (leaf_count, 0);
ASSERT_EQ (branch_count, 9);
ASSERT_EQ (branch_count + leaf_count, node_count);
ASSERT_EQ (oct_a_.getBranchCount (), branch_count);
}

////////////////////////////////////////////////////////
// OctreeBase End Begin/End Iterator Construction
////////////////////////////////////////////////////////
Expand Down

0 comments on commit d521c6e

Please sign in to comment.