// Surface_t.cpp // Test Surface. // This class is abstract so we introduce a concrete subclass. #include "SurfTest.h" #include #include #include #include #include "trfutil/trfstream.h" #include "TrackVector.h" using std::cout; using std::cerr; using std::endl; using std::string; using trf::trf_format; //********************************************************************** int main( ) { string component = "Surface"; 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 << "Testing constructors." << endl; SurfTest tst1(123.); cout << tst1 << endl; SurfTest tst2(246.); cout << tst2 << endl; BSurfTest btst1(123.,456.); cout << btst1 << endl; BSurfTest btst2(246.,369.); cout << btst2 << endl; //******************************************************************** cout << ok_prefix << "Check SurfTest type." << endl; cout << Surface::get_creator(); cout << Surface::get_static_type(); cout << SurfTest::get_static_type(); cout << tst1.get_type(); assert( tst1.get_type() == SurfTest::get_static_type() ); cout << tst1.get_pure_type(); assert( tst1.get_pure_type() == SurfTest::get_static_type() ); cout << tst1.get_generic_type(); assert( tst1.get_generic_type() == Surface::get_static_type() ); //******************************************************************** cout << ok_prefix << "Check BSurfTest type." << endl; cout << BSurfTest::get_static_type(); cout << btst1.get_type(); assert( btst1.get_type() == BSurfTest::get_static_type() ); cout << btst1.get_pure_type(); assert( btst1.get_pure_type() == SurfTest::get_static_type() ); cout << btst1.get_generic_type(); assert( btst1.get_generic_type() == Surface::get_static_type() ); //******************************************************************** cout << ok_prefix << "Testing purity." << endl; if ( ! tst1.is_pure() ) { cerr << error_prefix << "Pure test class is not pure." << endl; return 1; } if ( btst1.is_pure() ) { cerr << error_prefix << "Bounded test class is pure." << endl; return 2; } //******************************************************************** cout << ok_prefix << "Testing equality." << endl; assert( tst1.bound_equal(tst1) ); assert( tst1 == tst1 ); assert( ! tst1.bound_equal(tst2) ); assert( tst1 != tst2 ); assert( ! tst1.bound_equal(btst1) ); assert( ! btst1.bound_equal(tst1) ); assert( tst1.pure_equal(btst1) ); assert( btst1.pure_equal(tst1) ); //******************************************************************** cout << ok_prefix << "Testing ordering." << endl; assert( ! tst1.pure_less_than(tst1) ); assert( tst1.pure_less_than(tst2) || tst2.pure_less_than(tst1) ); assert( ! (tst1.pure_less_than(tst2) && tst2.pure_less_than(tst1)) ); assert( ! btst1.pure_less_than(tst1) ); assert( ! btst1.pure_less_than(btst1) ); assert( btst1.pure_less_than(tst2) || tst2.pure_less_than(btst1) ); //******************************************************************** cout << ok_prefix << "Testing assignment." << endl; SurfTest tst3 = tst1; if ( tst3 != tst1 ) { cerr << error_prefix << "Failure: tst3 != tst1." << endl; return 7; } BSurfTest btst3 = btst1; if ( btst3 != btst1 ) { cerr << error_prefix << "Failure: btst3 != btst1." << endl; return 8; } //******************************************************************** cout << ok_prefix << "Testing types." << endl; cout << tst1.get_type() << endl; cout << tst2.get_type() << endl; cout << btst1.get_type() << endl; cout << btst2.get_type() << endl; assert( tst1.get_type() != 0 ); assert( tst1.get_type() == tst2.get_type() ); assert( btst1.get_type() != 0 ); assert( btst1.get_type() == btst2.get_type() ); assert( tst1.get_type() != btst1.get_type() ); //******************************************************************** cout << ok_prefix << "Testing pure types." << endl; cout << tst1.get_pure_type() << endl; cout << btst1.get_pure_type() << endl; assert( tst1.get_pure_type() == tst1.get_type() ); assert( tst1.get_pure_type() == btst1.get_pure_type() ); //******************************************************************** cout << ok_prefix << "Test curvature." << endl; TrackVector vec; vec(4) = 0.0012345; cout << "expect " << vec(4) << "; found " << tst1.qoverp(vec) << endl; assert( tst1.qoverp(vec) == vec(4) ); //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }