// BSurfCylinder_t.cpp // Test BSurfCylinder. #include "BSurfCylinder.h" #include #include #include #include "objstream/StdObjStream.hpp" #include "trfutil/trfstream.h" #include "trfbase/ETrack.h" #include "trfbase/CrossStat.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 ok_prefix = "BSurfCylinder test (I): "; string error_prefix = "BSurfCylinder test (E): "; cout << ok_prefix << "------ Testing component BSurfCylinder. ------" << 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; } //******************************************************************** ObjTable::register_type(); cout << trf_format; cout << ok_prefix << "Test constructor and get routines." << endl; BSurfCylinder bcy( 10.0, -20.0, 30.0 ); cout << bcy << endl; assert( bcy.get_radius() == 10.0 ); assert( bcy.get_zmin() == -20.0 ); assert( bcy.get_zmax() == 30.0 ); //******************************************************************** cout << ok_prefix << "Equality tests varying parameters." << endl; BSurfCylinder bcy1( 10.0, -20.0, 30.0 ); BSurfCylinder bcy2( 10.0, 20.0, 30.0 ); BSurfCylinder bcy3( 10.0, -20.0, 20.0 ); BSurfCylinder bcy4( 20.0, -20.0, 30.0 ); assert( bcy.bound_equal(bcy) ); assert( bcy.bound_equal(bcy1) ); assert( ! bcy.bound_equal(bcy2) ); assert( ! bcy.bound_equal(bcy3) ); assert( ! bcy.bound_equal(bcy4) ); //******************************************************************** cout << ok_prefix << "Equality tests using base class." << endl; SurfCylinder scy(10.0); SurfCylinder* pscy = б assert( bcy.bound_equal(*pscy) ); assert( pscy->bound_equal(bcy) ); assert( ! pscy->bound_equal(bcy2) ); assert( ! bcy.bound_equal(scy) ); assert( bcy.pure_equal(scy) ); assert( scy.pure_equal(bcy) ); //******************************************************************** cout << ok_prefix << "Test type." << endl; assert( bcy.get_type() != 0 ); assert( bcy.get_type() != scy.get_type() ); assert( bcy.get_type() == BSurfCylinder::get_static_type() ); //******************************************************************** cout << ok_prefix << "Test purity." << endl; assert( ! bcy.is_pure() ); assert( scy.is_pure() ); assert( ! pscy->is_pure() ); //******************************************************************** cout << ok_prefix << "Test crossing status." << endl; cout << bcy << endl; TrackVector tvec; TrackError terr; terr(1,1) = 4.0; // completely inside tvec(1) = 15.0; ETrack trk1(SurfacePtr(bcy.new_pure_surface()),tvec,terr); cout << trk1 << endl; CrossStat xs = bcy.status(trk1); cout << xs << endl; assert( xs.in_bounds() ); assert( ! xs.out_of_bounds() ); // inside overlapping out tvec(1) = 25.0; ETrack trk2(SurfacePtr(bcy.new_pure_surface()),tvec,terr); xs = bcy.status(trk2); cout << trk2 << endl; cout << xs << endl; assert( xs.in_bounds() ); assert( xs.out_of_bounds() ); // outside overlapping in tvec(1) = 35.0; ETrack trk3(SurfacePtr(bcy.new_pure_surface()),tvec,terr); cout << trk3 << endl; xs = bcy.status(trk3); cout << xs << endl; assert( xs.in_bounds() ); assert( xs.out_of_bounds() ); // way outside tvec(1) = 45.0; ETrack trk4(SurfacePtr(bcy.new_pure_surface()),tvec,terr); cout << trk4 << endl; xs = bcy.status(trk4); cout << xs << endl; assert( ! xs.in_bounds() ); assert( xs.out_of_bounds() ); // inside overlapping out tvec(1) = -15.0; ETrack trk5(SurfacePtr(bcy.new_pure_surface()),tvec,terr); cout << trk5 << endl; xs = bcy.status(trk5); cout << xs << endl; assert( xs.in_bounds() ); assert( xs.out_of_bounds() ); // outside overlapping in tvec(1) = -25.0; ETrack trk6(SurfacePtr(bcy.new_pure_surface()),tvec,terr); cout << trk6 << endl; xs = bcy.status(trk6); cout << xs << endl; assert( xs.in_bounds() ); assert( xs.out_of_bounds() ); // way outside tvec(1) = -35.0; ETrack trk7(SurfacePtr(bcy.new_pure_surface()),tvec,terr); cout << trk7 << endl; xs = bcy.status(trk7); cout << xs << endl; assert( ! xs.in_bounds() ); assert( xs.out_of_bounds() ); //******************************************************************** cout << ok_prefix << "Check cloning." << endl; Surface* psrf = bcy.new_surface(); assert( psrf->get_type() == BSurfCylinder::get_static_type() ); delete psrf; //******************************************************************** cout << ok_prefix << "Write object data." << endl; { ObjPtr pobj( new BSurfCylinder(12.3,-12.,34.) ); ostringstream mystream; StdObjStream objstream(mystream); objstream.write_object("cyl1",pobj); cout << mystream.str() << endl; assert( ObjTable::has_object_name("cyl1") ); string::size_type pos = 0; assert( (pos=mystream.str().find( "cyl1 ",pos)) != string::npos ); assert( (pos=mystream.str().find( "BSurfCylinder ",pos)) != string::npos ); assert( (pos=mystream.str().find( "radius",pos)) != string::npos ); assert( (pos=mystream.str().find( "12.3 ",pos)) != string::npos ); assert( (pos=mystream.str().find( "zmin",pos)) != string::npos ); assert( (pos=mystream.str().find( "-12. ",pos)) != string::npos ); assert( (pos=mystream.str().find( "zmax",pos)) != string::npos ); assert( (pos=mystream.str().find( "34. ",pos)) != string::npos ); } //******************************************************************** cout << ok_prefix << "Read object data." << endl; { string istring = "[ cyl2 BSurfCylinder radius=24.6, zmin=-24. zmax=68. ]"; istringstream isstrm(istring); { StdObjStream obstr(isstrm); string name = obstr.read_object(); assert( name == "cyl2" ); const BSurfCylinder* pobj; ObjTable::get_object(name,pobj); assert( pobj != 0 ); assert( pobj->get_type() == BSurfCylinder::get_static_type() ); assert( pobj->get_radius() == 24.6 ); assert( pobj->get_zmin() == -24.0 ); assert( pobj->get_zmax() == 68.0 ); } } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }