// LayerStat_t.cpp #include "LayerStat.h" #include #include #include "trfutil/trfstream.h" #include "trfbase/MissTest.h" #include "trfbase/SurfTest.h" #include "trfbase/ETrack.h" #include "ClusterFinderTest.h" #include "ClusterContainer.h" using std::cout; using std::cerr; using std::endl; using std::string; using namespace trf; //********************************************************************** // Dummy layer class. // Needed to access private methods of LayerStat. namespace trf { class Layer { private: bool _same; bool _exit; const Miss* _pmiss; const ClusterFinder* _pfinder; int _state; public: Layer(bool same, bool exit, const Miss* pmiss, const ClusterFinder* pfinder, int state) : _same(same), _exit(exit), _pmiss(pmiss), _pfinder(pfinder), _state(state) { }; LayerStat propagate() const { LayerStat lstat(*this); propagate(lstat); return lstat; }; void propagate(LayerStat& lstat) const { if ( _exit ) lstat.set_at_exit(); if ( _pmiss ) lstat.set_miss(*_pmiss); if ( _pfinder ) lstat.set_finder(*_pfinder); lstat.set_state(_state); }; void check(const LayerStat lstat) const { assert( _exit == lstat._at_exit ); assert( ! ( _pmiss && ! _pmiss ) ); assert( ! ( ! _pmiss && _pmiss ) ); assert( ! _pmiss || _pmiss->get_likelihood() == lstat._pmiss->get_likelihood() ); assert( _pfinder == lstat._pfinder ); assert( _state == lstat._layer_state ); }; }; } // end namespace trf //********************************************************************** int main( ) { string component = "LayerStat"; 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 << "Construct and fill status." << endl; MissTest miss(2.0,0.4); ClusterFinderTest find(2.0); const Surface& srf = find.get_surface(); ETrack tre( SurfacePtr(srf.new_pure_surface()) ); Layer lyr(true,true,&miss,&find,5); LayerStat lstat = lyr.propagate(); cout << lstat << endl; lyr.check(lstat); assert( lstat.at_exit() ); assert( lstat.has_clusters() ); assert( lstat.get_clusters().size() == 0 ); assert( lstat.get_clusters(tre,0,0).get_clusters().size() == 0 ); assert( lstat.get_miss()->get_likelihood() == 0.4 ); assert( &lstat.get_layer() == &lyr ); //******************************************************************** cout << ok_prefix << "Test copy." << endl; LayerStat lstat2 = lstat; cout << lstat2 << endl; assert( lstat2.at_exit() ); assert( lstat2.has_clusters() ); assert( lstat2.get_clusters().size() == 0 ); assert( lstat2.get_clusters(tre,0,0).get_clusters().size() == 0 ); assert( lstat2.get_miss()->get_likelihood() == 0.4 ); assert( &lstat2.get_layer() == &lyr ); lyr.check(lstat2); //******************************************************************** cout << ok_prefix << "Test assignment." << endl; lstat2 = lstat; cout << lstat2 << endl; assert( lstat2.at_exit() ); assert( lstat2.has_clusters() ); assert( lstat2.get_clusters().size() == 0 ); assert( lstat2.get_clusters(tre,0,0).get_clusters().size() == 0 ); assert( lstat2.get_miss()->get_likelihood() == 0.4 ); assert( &lstat2.get_layer() == &lyr ); lyr.check(lstat2); //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }