// CrossStat_t.cpp // Test CrossStat. #include "CrossStat.h" #include #include #include #include "trfutil/trfstream.h" using std::cout; using std::cerr; using std::endl; using std::string; using trf::trf_format; using trf::CrossStat; //********************************************************************** // Routine to check crossing status. bool check_xs(CrossStat xstat, bool at, bool on, bool inside, bool outside, bool inb, bool outb) { cout << xstat << endl; bool bad = false; if ( xstat.at() != at ) return bad; if ( xstat.on() != on ) return bad; if ( xstat.inside() != inside ) return bad; if ( xstat.outside() != outside ) return bad; if ( xstat.in_bounds() != inb ) return bad; if ( xstat.out_of_bounds() != outb ) return bad; return ! bad; } //********************************************************************** int main( ) { string ok_prefix = "CrossStat test (I): "; string error_prefix = "CrossStat test (E): "; cout << ok_prefix << "------- Testing component CrossStat. -------" << endl; cout << trf_format; //******************************************************************** cout << ok_prefix << "Testing pure constructor." << new_line; CrossStat xstat1(CrossStat::AT); cout << xstat1 << endl; assert( check_xs(xstat1, true, true, false, false, false, false) ); CrossStat xstat2(CrossStat::ON); cout << xstat2 << endl; assert( check_xs(xstat2, false, true, false, false, false, false) ); CrossStat xstat3(CrossStat::INSIDE); cout << xstat3 << endl; assert( check_xs(xstat3, false, false, true, false, false, false) ); CrossStat xstat4(CrossStat::OUTSIDE); cout << xstat4 << endl; assert( check_xs(xstat4, false, false, false, true, false, false) ); //******************************************************************** cout << ok_prefix << "Testing bound constructor." << new_line; CrossStat xstat5(CrossStat::UNDEFINED_BOUNDS); cout << xstat5 << endl; assert( check_xs(xstat5, true, true, false, false, false, false) ); CrossStat xstat6(CrossStat::IN_BOUNDS); cout << xstat6 << endl; assert( check_xs(xstat6, true, true, false, false, true, false) ); CrossStat xstat7(CrossStat::OUT_OF_BOUNDS); cout << xstat7 << endl; assert( check_xs(xstat7, true, true, false, false, false, true) ); CrossStat xstat8(CrossStat::BOTH_BOUNDS); cout << xstat8 << endl; assert( check_xs(xstat8, true, true, false, false, true, true) ); //******************************************************************** cout << ok_prefix << "Check parameters." << endl; assert( xstat1.get_nsigma() == 5.0 ); assert( xstat2.get_precision() == 1.e-14 ); //******************************************************************** cout << ok_prefix << "Check bounds_checked method." << endl; assert( ! xstat1.bounds_checked() ); assert( ! xstat2.bounds_checked() ); assert( ! xstat3.bounds_checked() ); assert( ! xstat4.bounds_checked() ); assert( ! xstat5.bounds_checked() ); assert( xstat6.bounds_checked() ); assert( xstat7.bounds_checked() ); assert( xstat8.bounds_checked() ); //******************************************************************** cout << ok_prefix << "Check assignment." << endl; xstat3 = xstat8; assert( check_xs(xstat3, true, true, false, false, true, true) ); //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }