// PathTree_t.cpp #include "PathTree.h" #include #include #include "trfutil/trfstream.h" #include "trflayer/LayerTest.h" #include "trfbase/PropStat.h" #include "trfbase/PropDirectedTest.h" #include "trffit/AddFitter.h" #include "trffit/AddFitterTest.h" #include "Checker.h" #include "CheckerTest.h" #include "Filter.h" #include "PathStop.h" using std::cout; using std::cerr; using std::endl; using std::string; using namespace trf; //********************************************************************** int main( ) { string component = "PathTree"; string ok_prefix = component + " (I): "; string error_prefix = component + " test (E): "; cout << ok_prefix << "-------- Testing component " + component + ". --------" << endl; // Make sure assert is enabled. bool assert_flag = false; assert ( ( assert_flag = true, assert_flag ) ); if ( ! assert_flag ) { cerr << "Assert is disabled" << endl; return 1; } //******************************************************************** cout << trf_format; cout << ok_prefix << "Create the head path." << endl; assert( Path::get_path_count() == 0 ); Path* ppath = new Path; PathPtr ppath0(ppath); Path& path0 = *ppath; const Path& cpath0 = path0; cout << cpath0 << endl; assert( cpath0.is_head() ); assert( cpath0.get_children().size() == 0 ); assert( path0.get_mutable_children().size() == 0 ); assert( Path::get_path_count() == 1 ); //******************************************************************** cout << ok_prefix << "Add a child." << endl; LayerTest lay(1.0); PropTest prop; AddFitterTest fit(4); Path& path1 = *path0.add_child(lay,prop,fit); cout << path1 << endl; assert( ! path1.is_head() ); assert( path0.get_children().size() == 1 ); assert( path1.get_children().size() == 0 ); assert( path1.get_checkers().size() == 0 ); assert( Path::get_path_count() == 2 ); //******************************************************************** cout << ok_prefix << "Add more children." << endl; Path& path2 = *path0.add_child(lay,prop,fit); Path& path3 = *path0.add_child(lay,prop,fit); cout << path0 << endl; assert( path0.get_children().size() == 3 ); assert( path0.get_mutable_children().size() == 3 ); assert( Path::get_path_count() == 4 ); //******************************************************************** cout << ok_prefix << "Add another generation." << endl; Path& path11 = *path1.add_child(lay,prop,fit); Path& path21 = *path2.add_child(lay,prop,fit); Path& path22 = *path2.add_child(lay,prop,fit); Path& path31 = *path3.add_child(lay,prop,fit); Path& path32 = *path3.add_child(lay,prop,fit); Path& path33 = *path3.add_child(lay,prop,fit); cout << path0 << endl; cout << path1 << endl; cout << path2 << endl; cout << path3 << endl; assert( path0.get_children().size() == 3 ); Path::PathList::const_iterator ipth; const Path::PathList& paths = path0.get_children(); assert( paths.size() == 3 ); int icnt = 0; cout << ok_prefix << "Checking paths." << endl; for ( ipth=paths.begin(); ipth!=paths.end(); ++ipth ) { cout << **ipth << endl; assert( (*ipth)->get_children().size() == ++icnt ); assert( (*ipth)->get_parent() == &path0 ); } assert( Path::get_path_count() == 10 ); //******************************************************************** cout << ok_prefix << "Add checkers." << endl; assert( path0.get_checkers().size() == 0 ); assert( path1.get_checkers().size() == 0 ); CheckerPtr pchk( new CheckerTest ); path1.add_checker(pchk); path1.add_checker(pchk); path1.add_checker(pchk); path1.add_checker(pchk); cout << path1 << endl; assert( path0.get_checkers().size() == 0 ); assert( path1.get_checkers().size() == 4 ); assert( path2.get_checkers().size() == 0 ); //******************************************************************** cout << ok_prefix << "Check candidate layer." << endl; const CandidateLayer& cnl = path1.get_candidate_layer(); cout << path1 << endl; assert( &cnl.get_propagator() == &prop ); //******************************************************************** cout << ok_prefix << "Check stop." << endl; PathStopPtr pstop( new PathStop ); assert( ! path1.get_stop() ); path1.set_stop(pstop); cout << path1 << endl; assert( path1.get_stop() == pstop ); //******************************************************************** cout << ok_prefix << "Check end." << endl; assert( ! path1.get_end() ); path1.set_end(); assert( path1.get_end() ); path1.set_end(false); assert( ! path1.get_end() ); //******************************************************************** cout << ok_prefix << "Check the tree." << endl; PathTree tree(ppath0); assert( tree.size() == 10 ); cout << tree << endl; //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }