// eatest.cc // uncomment following line to verify that input (which is undefined on // EulerAngles objects) will fail to compile: //#define TEST_INPUT #include "ZMutility/ZMenvironment.h" #include "PhysicsVectors/EulerAngles.h" #include "PhysicsVectors/UnitVector.h" #include "ZMutility/FixedTypes.h" ZM_USING_NAMESPACE( zmpv ) #include "ZMutility/iostream" using std::cin; using std::cout; using std::endl; using std::flush; bool OK = true; const Float8 DEG0 = 0.0; const Float8 DEG180 = 3.14159265358979323846; const Float8 DEG30 = DEG180 / 6.0; const Float8 DEG90 = DEG180 / 2.0; const Float8 DEG270 = DEG180 + DEG90; void accessors(); void comparators(); void constructors(); void input(); void relComparators(); int main() { cout << "\tEulerAngles testing\n" << "\t=========== =======" << endl; constructors(); input(); accessors(); comparators(); relComparators(); cout << "\n\n===== EulerAngles testing summary:\n" << ( OK ? "OK: all automated tests passed" : "??? problems detected" ) << endl; return OK ? 0 : -1; } // main() void accessors() { cout << "\n\n===== Testing accessors:" << endl; const EulerAngles xc = EulerAngles( -DEG90, DEG0, DEG90 ); cout << '\n'; if ( xc.phi() == -DEG90 ) cout << "OK: phi() gave correct result " << -DEG90 << endl; else OK = false, cout << "??? phi() gave incorrect result of " << xc.phi() << "\n instead of " << -DEG90 << endl; if ( xc.theta() == DEG0 ) cout << "OK: theta() gave correct result " << DEG0 << endl; else OK = false, cout << "??? theta() gave incorrect result of " << xc.theta() << "\n instead of " << DEG0 << endl; if ( xc.psi() == DEG90 ) cout << "OK: psi() gave correct result " << DEG90 << endl; else OK = false, cout << "??? psi() gave incorrect result of " << xc.psi() << "\n instead of " << DEG90 << endl; EulerAngles x = EulerAngles( -DEG90, DEG0, DEG90 ); cout << '\n'; if ( x.phi() == -DEG90 ) cout << "OK: phi() gave correct result " << -DEG90 << endl; else OK = false, cout << "??? phi() gave incorrect result of " << x.phi() << "\n instead of " << -DEG90 << endl; if ( x.theta() == DEG0 ) cout << "OK: theta() gave correct result " << DEG0 << endl; else OK = false, cout << "??? theta() gave incorrect result of " << x.theta() << "\n instead of " << DEG0 << endl; if ( x.psi() == DEG90 ) cout << "OK: psi() gave correct result " << DEG90 << endl; else OK = false, cout << "??? psi() gave incorrect result of " << x.psi() << "\n instead of " << DEG90 << endl; cout << '\n'; x.setPhi( DEG30 ); if ( x.phi() == DEG30 ) cout << "OK: phi() correctly reset to " << DEG30 << endl; else OK = false, cout << "??? phi() incorrectly reset to " << x.phi() << " instead of " << DEG30 << endl; x.setTheta( DEG30 ); if ( x.theta() == DEG30 ) cout << "OK: theta() correctly reset to " << DEG30 << endl; else OK = false, cout << "??? theta() incorrectly reset to " << x.theta() << " instead of " << DEG30 << endl; x.setPsi( DEG30 ); if ( x.psi() == DEG30 ) cout << "OK: psi() correctly reset to " << DEG30 << endl; else OK = false, cout << "??? psi() incorrectly reset to " << x.psi() << " instead of " << DEG30 << endl; cout << '\n'; x.set( DEG0, DEG0, DEG0 ); if ( x.phi() == DEG0 && x.theta() == DEG0 && x.psi() == DEG0 ) cout << "OK: set(" << DEG0 << ", " << DEG0 << ", " << DEG0 << ") correctly reset" << endl; else OK = false, cout << "??? set(" << DEG0 << ", " << DEG0 << ", " << DEG0 << ") incorrectly reset to " << x << endl; } // accessors() void comparators() { cout << "\n\n===== Testing comparators:" << endl; const EulerAngles xc = EulerAngles( DEG180, DEG90, DEG0 ); EulerAngles aa = xc; cout << '\n'; if ( aa == xc ) cout << "OK: " << aa << " == " << xc << " is true" << endl; else OK = false, cout << "??? " << aa << " == " << xc << " is false" << endl; if ( aa != xc ) OK = false, cout << "??? " << aa << " != " << xc << " is true" << endl; else cout << "OK: " << aa << " != " << xc << " is false" << endl; if ( aa < xc ) OK = false, cout << "??? " << aa << " < " << xc << " is true" << endl; else cout << "OK: " << aa << " < " << xc << " is false" << endl; if ( aa <= xc ) cout << "OK: " << aa << " <= " << xc << " is true" << endl; else OK = false, cout << "??? " << aa << " <= " << xc << " is false" << endl; if ( aa > xc ) OK = false, cout << "??? " << aa << " > " << xc << " is true" << endl; else cout << "OK: " << aa << " > " << xc << " is false" << endl; if ( aa >= xc ) cout << "OK: " << aa << " >= " << xc << " is true" << endl; else OK = false, cout << "??? " << aa << " >= " << xc << " is false" << endl; cout << '\n'; aa.setPhi( DEG270 ); if ( aa == xc ) OK = false, cout << "??? " << aa << " == " << xc << " is true" << endl; else cout << "OK: " << aa << " == " << xc << " is false" << endl; if ( aa != xc ) cout << "OK: " << aa << " != " << xc << " is true" << endl; else OK = false, cout << "??? " << aa << " != " << xc << " is false" << endl; if ( aa < xc ) OK = false, cout << "??? " << aa << " < " << xc << " is true" << endl; else cout << "OK: " << aa << " < " << xc << " is false" << endl; if ( aa <= xc ) OK = false, cout << "??? " << aa << " <= " << xc << " is true" << endl; else cout << "OK: " << aa << " <= " << xc << " is false" << endl; if ( aa > xc ) cout << "OK: " << aa << " > " << xc << " is true" << endl; else OK = false, cout << "??? " << aa << " > " << xc << " is false" << endl; if ( aa >= xc ) cout << "OK: " << aa << " >= " << xc << " is true" << endl; else OK = false, cout << "??? " << aa << " >= " << xc << " is false" << endl; cout << '\n'; aa.set( xc.phi(), DEG180, xc.psi() ); if ( aa == xc ) OK = false, cout << "??? " << aa << " == " << xc << " is true" << endl; else cout << "OK: " << aa << " == " << xc << " is false" << endl; if ( aa != xc ) cout << "OK: " << aa << " != " << xc << " is true" << endl; else OK = false, cout << "??? " << aa << " != " << xc << " is false" << endl; if ( aa < xc ) OK = false, cout << "??? " << aa << " < " << xc << " is true" << endl; else cout << "OK: " << aa << " < " << xc << " is false" << endl; if ( aa <= xc ) OK = false, cout << "??? " << aa << " <= " << xc << " is true" << endl; else cout << "OK: " << aa << " <= " << xc << " is false" << endl; if ( aa > xc ) cout << "OK: " << aa << " > " << xc << " is true" << endl; else OK = false, cout << "??? " << aa << " > " << xc << " is false" << endl; if ( aa >= xc ) cout << "OK: " << aa << " >= " << xc << " is true" << endl; else OK = false, cout << "??? " << aa << " >= " << xc << " is false" << endl; cout << '\n'; aa.set( xc.phi(), xc.theta(), DEG90 ); if ( aa == xc ) OK = false, cout << "??? " << aa << " == " << xc << " is true" << endl; else cout << "OK: " << aa << " == " << xc << " is false" << endl; if ( aa != xc ) cout << "OK: " << aa << " != " << xc << " is true" << endl; else OK = false, cout << "??? " << aa << " != " << xc << " is false" << endl; if ( aa < xc ) OK = false, cout << "??? " << aa << " < " << xc << " is true" << endl; else cout << "OK: " << aa << " < " << xc << " is false" << endl; if ( aa <= xc ) OK = false, cout << "??? " << aa << " <= " << xc << " is true" << endl; else cout << "OK: " << aa << " <= " << xc << " is false" << endl; if ( aa > xc ) cout << "OK: " << aa << " > " << xc << " is true" << endl; else OK = false, cout << "??? " << aa << " > " << xc << " is false" << endl; if ( aa >= xc ) cout << "OK: " << aa << " >= " << xc << " is true" << endl; else OK = false, cout << "??? " << aa << " >= " << xc << " is false" << endl; } // comparators() void constructors() { cout << "\n\n===== Testing constructors & output:" << endl; cout << '\n'; EulerAngles aa; cout << "OK: constructed default EulerAngles (0, 0, 0): " << aa << endl; const EulerAngles ac; cout << "OK: constructed default const EulerAngles (0, 0, 0): " << ac << endl; cout << '\n'; EulerAngles x( 2.0, 1.0, 0.0 ); cout << "OK: constructed EulerAngles (2, 1, 0): " << x << endl; const EulerAngles xc( 2.0, 1.0, 0.0 ); cout << "OK: constructed const EulerAngles (2, 1, 0): " << xc << endl; cout << '\n'; EulerAngles y = EulerAngles( 1.0, 2.0, 3.0 ); cout << "OK: copy-constructed EulerAngles y from temporary (1, 2, 3): " << y << endl; const EulerAngles yc = EulerAngles( 1.0, 2.0, 3.0 ); cout << "OK: copy-constructed const EulerAngles from temporary (1, 2, 3): " << yc << endl; cout << '\n'; EulerAngles z(y); cout << "OK: copy-constructed EulerAngles z from y above: " << z << endl; const EulerAngles zc(z); cout << "OK: copy-constructed const EulerAngles from z above: " << zc << endl; } // constructors() void input() { cout << "\n\n===== Testing input:" << endl; const EulerAngles xc = EulerAngles( DEG90, DEG0, -DEG90 ); EulerAngles aa = xc; cout << '\n'; cout << "Old EulerAngles value: " << aa << endl; cout << "Enter new EulerAngles information: " << flush; cin >> aa; cout << "OK: new EulerAngles value: " << aa; #ifdef TEST_INPUT cout << '\n'; cout << "Old const EulerAngles value: " << xc; cout << "Enter const EulerAngles information (ought not get here!): " << flush; cin >> xc; // ought not compile OK = false, cout << "??? new const EulerAngles value: " << xc << "; erroneously allowed input to const EulerAngles" << endl; #endif // TEST_INPUT } // input() void relComparators() { cout << "\n\n===== Testing relative comparators:" << endl; cout << '\n'; const EulerAngles xc = EulerAngles( DEG30, DEG30, DEG30 ); if ( xc.isNear( xc ) ) cout << "OK: " << xc << " isNear itself"; else OK = false, cout << "??? " << xc << " isNear iself fails"; cout << "\n (distance = " << xc.howNear(xc) << ')' << endl; cout << '\n'; const Float8 newTol = 0.005; Float8 oldTol = EulerAngles::setTolerance( newTol ); if ( EulerAngles::getTolerance() == newTol ) cout << "OK: tolerance successfully changed from " << oldTol << " to " << newTol << endl; else OK = false, cout << "??? tolerance unsuccessfully changed from " << oldTol << " to " << EulerAngles::getTolerance() << "; ought be " << newTol << endl; cout << '\n'; EulerAngles aa( xc.phi(), xc.theta(), xc.psi()+.0025 ); if ( aa.isNear( xc ) ) cout << "OK: " << aa << " isNear " << xc; else OK = false, cout << "??? " << aa << " isNear " << xc << " fails"; cout << "\n (distance = " << aa.howNear(xc) << ')' << endl; } // relComparators()