// SpacePath_t.cpp // Test the SpacePath class. #include "SpacePath.h" #include #include #include #include #include #include "ptr/Ptr.h" #ifndef DEFECT_NO_STDLIB_NAMESPACES using std::cout; using std::cerr; using std::endl; using std::string; using std::list; #ifndef DEFECT_CMATH_NOT_STD using std::fabs; using std::sqrt; #endif #endif //********************************************************************** bool myequal(double x1, double x2) { return fabs(x2-x1) < 1.e-10; } //********************************************************************** int main() { string name = "SpacePoint"; string ok_prefix = name + " test (I): "; string error_prefix = name + " test (E): "; cout << ok_prefix << "------- Testing component " + name + ". -------" << endl; double x = 1.23; double y = 2.46; double z = 3.69; double dx = 0.23; double dy = 0.45; double dz = 0.67; //********************************************************************** cout << ok_prefix << "Testing constructors." << endl; // Create a space path element CartesianPath cart(x,y,z,dx,dy,dz); cout << cart << endl; // Create in cylindrical coordinates. CylindricalPath cyl( cart.rxy(), cart.phi(), cart.z(), cart.drxy(), cart.rxy_dphi(), cart.dz() ); cout << cyl << endl; // Create in spherical coordinates. SphericalPath sph( cyl.rxyz(), cyl.phi(), cyl.theta(), cyl.drxyz(), cyl.rxyz_dtheta(), cyl.rxy_dphi() ); cout << sph << endl; assert( myequal(sph.x(),x) ); assert( myequal(sph.y(),y) ); assert( myequal(sph.z(),z) ); assert( myequal(sph.dx(),dx) ); assert( myequal(sph.dy(),dy) ); assert( myequal(sph.dz(),dz) ); //********************************************************************** cout << ok_prefix << "Testing assignment." << endl; SpacePath dpth; cout << dpth << endl; assert( dpth.magnitude() == 0.0 ); dpth = sph; cout << dpth << endl; assert( myequal(dpth.x(),x) ); assert( myequal(dpth.y(),y) ); assert( myequal(dpth.z(),z) ); assert( myequal(dpth.dx(),dx) ); assert( myequal(dpth.dy(),dy) ); assert( myequal(dpth.dz(),dz) ); //********************************************************************** cout << ok_prefix << "Testing normalizations." << endl; double n0 = dx*dx + dy*dy + dz*dz; cout << n0 << endl; double ncart = dpth.dx()*dpth.dx() + dpth.dy()*dpth.dy() + dpth.dz()*dpth.dz(); cout << ncart << endl; double ncyl = dpth.drxy()*dpth.drxy() + dpth.rxy_dphi()*dpth.rxy_dphi() + dpth.dz()*dpth.dz(); cout << ncyl << endl; double nsph = dpth.drxyz()*dpth.drxyz() + dpth.rxy_dphi()*dpth.rxy_dphi() + dpth.rxyz_dtheta()*dpth.rxyz_dtheta(); cout << nsph << endl; assert( myequal(ncart,n0) ); assert( myequal(ncyl,n0) ); assert( myequal(nsph,n0) ); assert( myequal( sqrt(n0), dpth.magnitude() ) ); //********************************************************************** cout << ok_prefix << "------------- All tests passed. ------------" << endl; return 0; }