// CheckChiSquare_t.cpp #include "CheckChiSquare.h" #include #include #include #include #include "objstream/StdObjStream.hpp" #include "trfutil/trfstream.h" #include "trfbase/SurfTest.h" #include "trfbase/ETrack.h" #include "trffit/MTrack.h" #include "CheckerPtr.h" using std::cout; using std::cerr; using std::endl; using std::string; using std::ostringstream; using std::istringstream; using namespace trf; //********************************************************************** int main( ) { string component = "CheckChiSquare"; 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 checker." << endl; ObjTable::register_type(); CheckChiSquare chk(5.0); cout << chk << endl; //******************************************************************** cout << ok_prefix << "Test status." << endl; ETrack tre( SurfacePtr( new SurfTest(1) ) ); MTrack trm(tre); trm.set_fit(tre,2.0); assert( chk.status(trm) ); trm.set_fit(tre,7.0); assert( ! chk.status(trm) ); trm.set_fit(tre,5.0); assert( chk.status(trm) ); trm.set_fit(tre,5.1); assert( ! chk.status(trm) ); //******************************************************************** cout << ok_prefix << "Write object data." << endl; { CheckerPtr pchk( new CheckChiSquare(12.34) ); ostringstream mystream; StdObjStream objstream(mystream); objstream.write_object("chk1",pchk); cout << mystream.str() << endl; assert( ObjTable::has_object_name("chk1") ); assert( mystream.str().find("12.34 ") != string::npos ); } //******************************************************************** cout << ok_prefix << "Read object data." << endl; { string istring = "[ chk2 CheckChiSquare max_chisq=24.68 ]"; istringstream isstrm(istring); { StdObjStream obstr(isstrm); string name = obstr.read_object(); assert( name == "chk2" ); const CheckChiSquare* pchk; ObjTable::get_object("chk2",pchk); assert( pchk != 0 ); assert( pchk->get_type() == CheckChiSquare::get_static_type() ); assert( pchk->get_max_chisq() == 24.68 ); } } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }