24 #include <boost/shared_ptr.hpp> 25 #include <boost/make_shared.hpp> 26 #include <boost/assign/std/list.hpp> 28 using boost::assign::operator+=;
30 using namespace gtsam;
54 forest.
roots_.push_back(boost::make_shared<TestNode>(0));
55 forest.
roots_.push_back(boost::make_shared<TestNode>(1));
56 forest.
roots_[0]->children.push_back(boost::make_shared<TestNode>(2));
57 forest.
roots_[0]->children.push_back(boost::make_shared<TestNode>(3));
58 forest.
roots_[0]->children[1]->children.push_back(boost::make_shared<TestNode>(4));
71 visited.push_back(node->data);
73 const int expectedParentIndex =
74 node->data == 0 ? -1 :
75 node->data == 1 ? -1 :
79 node->data == 10 ? 0 :
80 (parentsMatched =
false, -1);
81 if(expectedParentIndex != parentData)
82 parentsMatched =
false;
92 visited.push_back(node->data);
107 TEST(treeTraversal, DepthFirst)
113 std::list<int> preOrderExpected;
114 preOrderExpected += 0, 2, 3, 4, 1;
115 std::list<int> postOrderExpected;
116 postOrderExpected += 2, 4, 3, 0, 1;
138 std::list<int> preOrder1Expected;
139 preOrder1Expected += 0, 2, 3, 4, 1;
140 std::list<int> preOrder1Actual =
getPreorder(testForest1);
141 std::list<int> preOrder2Actual =
getPreorder(testForest2);
146 testForest2.
roots_[0]->children[1]->data = 10;
147 std::list<int> preOrderModifiedExpected;
148 preOrderModifiedExpected += 0, 2, 10, 4, 1;
151 std::list<int> preOrder1ModActual =
getPreorder(testForest1);
152 std::list<int> preOrder2ModActual =
getPreorder(testForest2);
Provides additional testing facilities for common data structures.
FastVector< sharedNode > roots_
TestForest makeTestForest()
static int runAllTests(TestResult &result)
void operator()(const TestNode::shared_ptr &node, int myData)
std::list< int > getPreorder(const TestForest &forest)
int operator()(const TestNode::shared_ptr &node, int parentData)
bool assert_container_equality(const std::map< size_t, V2 > &expected, const std::map< size_t, V2 > &actual)
void DepthFirstForest(FOREST &forest, DATA &rootData, VISITOR_PRE &visitorPre, VISITOR_POST &visitorPost)
boost::shared_ptr< TestNode > shared_ptr
#define EXPECT(condition)
const FastVector< sharedNode > & roots() const
FastVector< boost::shared_ptr< typename FOREST::Node > > CloneForest(const FOREST &forest)
Node::shared_ptr sharedNode
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
TEST(treeTraversal, DepthFirst)
vector< shared_ptr > children