// aatest.cc // uncomment following line to verify that input (which is undefined on // AxisAngle objects) will fail to compile: //#define TEST_INPUT #include "ZMutility/ZMenvironment.h" #include "PhysicsVectors/AxisAngle.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 DEG180 = 3.14159265358979323846; const Float8 DEG30 = DEG180 / 6.0; const Float8 DEG90 = DEG180 / 2.0; const Float8 DEG120 = 2.0 * DEG180 / 3.0; void accessors(); void comparators(); void constructors(); void input(); void relComparators(); int main() { cout << "\tAxisAngle testing\n" << "\t========= =======" << endl; constructors(); input(); accessors(); comparators(); relComparators(); cout << "\n\n===== AxisAngle 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 AxisAngle xc = AxisAngle( X_HAT, DEG90 ); cout << '\n'; if ( xc.axis() == X_HAT ) cout << "OK: axis() gave correct result " << X_HAT << endl; else OK = false, cout << "??? axis() gave incorrect result of " << xc.axis() << "\n instead of " << X_HAT << endl; if ( xc.delta() == DEG90 ) cout << "OK: delta() gave correct result " << DEG90 << endl; else OK = false, cout << "??? delta() gave incorrect result of " << xc.delta() << "\n instead of " << DEG90 << endl; AxisAngle x = AxisAngle( X_HAT, DEG90 ); cout << '\n'; if ( x.axis() == X_HAT ) cout << "OK: axis() gave correct result " << X_HAT << endl; else OK = false, cout << "??? axis() gave incorrect result of " << x.axis() << "\n instead of " << X_HAT << endl; if ( x.delta() == DEG90 ) cout << "OK: delta() gave correct result " << DEG90 << endl; else OK = false, cout << "??? delta() gave incorrect result of " << x.delta() << "\n instead of " << DEG90 << endl; cout << '\n'; //x.axis() = Y_HAT; x.setAxis( Y_HAT ); if ( x.axis() == Y_HAT ) cout << "OK: axis() correctly reset to " << Y_HAT << endl; else OK = false, cout << "??? axis() incorrectly reset to " << x.axis() << " instead of " << Y_HAT << endl; x.setDelta( DEG120 ); if ( x.delta() == DEG120 ) cout << "OK: delta() correctly reset to " << DEG120 << endl; else OK = false, cout << "??? delta() incorrectly reset to " << x.delta() << " instead of " << DEG120 << endl; cout << '\n'; x.set( Z_HAT, DEG180 ); if ( x.axis() == Z_HAT && x.delta() == DEG180 ) cout << "OK: set(" << Z_HAT << ", " << DEG180 << ") correctly reset" << endl; else OK = false, cout << "??? set(" << Z_HAT << ", " << DEG180 << ") incorrectly reset to (" << x.axis() << ", " << x.delta() << ')' << endl; } // accessors() void comparators() { cout << "\n\n===== Testing comparators:" << endl; const AxisAngle xc = AxisAngle( X_HAT, 0.0 ); AxisAngle 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.setDelta( 0.1 ); 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( Y_HAT, xc.delta() ); 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'; AxisAngle aa; cout << "OK: constructed default AxisAngle (def_UV, 0):\t" << aa << endl; const AxisAngle ac; cout << "OK: constructed default const AxisAngle (def_UV, 0):\t" << ac << endl; cout << '\n'; AxisAngle x(X_HAT, 0.0 ); cout << "OK: constructed AxisAngle (X_HAT, 0):\t" << x << endl; const AxisAngle xc(X_HAT, 0.0 ); cout << "OK: constructed const AxisAngle (X_HAT, 0):\t" << xc << endl; cout << '\n'; AxisAngle y = AxisAngle( Y_HAT, 0.0 ); cout << "OK: copy-constructed AxisAngle y from temporary (Y_HAT, 0):\t" << y << endl; const AxisAngle yc = AxisAngle( Y_HAT, 0.0 ); cout << "OK: copy-constructed const AxisAngle from temporary (Y_HAT, 0):\t" << yc << endl; cout << '\n'; AxisAngle z(y); cout << "OK: copy-constructed AxisAngle z from y above:\t" << z << endl; const AxisAngle zc(z); cout << "OK: copy-constructed const AxisAngle from z above:\t" << zc << endl; } // constructors() void input() { cout << "\n\n===== Testing input:" << endl; const AxisAngle xc = AxisAngle( X_HAT, 0.0 ); AxisAngle aa = xc; cout << '\n'; cout << "Old AxisAngle: " << aa << endl; cout << "Enter AxisAngle information: " << flush; cin >> aa; cout << "OK: new AxisAngle: " << aa << endl; #ifdef TEST_INPUT cout << '\n'; cout << "Old const AxisAngle: " << xc << endl; cout << "Enter const AxisAngle information (ought not get here!): " << flush; cin >> xc; // ought not compile OK = false, cout << "??? new AxisAngle: " << xc << "; erroneously allowed input to const AxisAngle" << endl; #endif // TEST_INPUT } // input() void relComparators() { cout << "\n\n===== Testing relative comparators:" << endl; cout << '\n'; const AxisAngle xc = AxisAngle( X_HAT, DEG30 ); if ( xc.isNear( xc ) ) cout << "OK: " << xc << " isNear itself"; else OK = false, cout << "??? " << xc << " isNear iself fails"; cout << " (distance = " << xc.howNear(xc) << ')' << endl; cout << '\n'; const Float8 newTol = 0.005; Float8 oldTol = AxisAngle::setTolerance( newTol ); if ( AxisAngle::getTolerance() == newTol ) cout << "OK: tolerance successfully changed from " << oldTol << " to " << newTol << endl; else OK = false, cout << "??? tolerance unsuccessfully changed from " << oldTol << " to " << AxisAngle::getTolerance() << "; ought be " << newTol << endl; cout << '\n'; AxisAngle aa( xc.axis(), xc.delta()+.0025 ); if ( aa.isNear( xc ) ) cout << "OK: " << aa << " isNear " << xc; else OK = false, cout << "??? " << aa << " isNear " << xc << " fails"; cout << " (distance = " << aa.howNear(xc) << ')' << endl; } // relComparators()