/*! \file simplearraytest.cc * \brief test simple array class (implementation) * * ---------------------------------------------------------------------------- * * $Id: simplearraytest.cc,v 1.4 2002-12-16 18:02:02 forbrig Exp $ * \author Thomas Forbriger * \date 25/05/2002 * * test simple array class (implementation) * * Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt) * * REVISIONS and CHANGES * - 25/05/2002 V1.0 Thomas Forbriger * - 24/11/2002 V1.1 add rawarfun tests * - 25/11/2002 V1.2 new inline tests * - 13/12/2002 V1.3 reworked for libaff * * ============================================================================ */ #define AFF_SIMPLEARRAYTEST_CC_VERSION \ "AFF_SIMPLEARRAYTEST_CC V1.3" #define AFF_SIMPLEARRAYTEST_CC_CVSID \ "$Id: simplearraytest.cc,v 1.4 2002-12-16 18:02:02 forbrig Exp $" /*! \example tests/simplearraytest.cc * * Tests for aff::SimpleRidigArray and aff::util::Inline. * * \sa tests/simplearraytest.cc * \sa aff::SimpleRidigArray * \sa aff::util::Inline */ #include #include #include using std::cout; using std::endl; using namespace aff; //! Print code and execute #define CODE( code ) cout << #code << endl; code //! print result of function #define FUNC( func ) cout << #func << "=" << func << endl //! return string for bool value const char* boolchar(const bool& v) { char *s; if (v) { s="true"; } else { s="false"; } return(s); } //! print headline void section(const char* s) { cout << endl << s << endl; const char* p=s; while (*p) { cout << "-"; ++p; } cout << endl; } //! Test for the SimpleRigidArray module and associated functions int main() { cout << AFF_SIMPLEARRAYTEST_CC_VERSION << endl; cout << AFF_SIMPLEARRAYTEST_CC_CVSID << endl << endl;; // test for basic functionality of SimpleRigidArray { cout << "Test SimpleRigidArray" << endl << "=====================" << endl; section("constructors"); SimpleRigidArray A,B(8.); SimpleRigidArray C,D(100); cout << "SimpleRigidArray A,B(8.);" << endl; cout << "SimpleRigidArray C,D(100);" << endl; DUMP( A ); DUMP( B ); DUMP( C ); DUMP( D ); const SimpleRigidArray E(D); cout << "const SimpleRigidArray E(D);" << endl; SimpleRigidArray F(D); cout << "SimpleRigidArray F(D);" << endl; DUMP( E ); DUMP( F ); section("assignment"); CODE( A=B; ) CODE( C=D; ) CODE( B[3]=78.5; ) CODE( D[2]=7883; ) CODE( C[2]=-13.2; ) CODE( F=C; ) CODE( F[1]=-13.2; ) DUMP( A ); DUMP( B ); DUMP( C ); DUMP( D ); DUMP( F ); CODE( D=777; ) DUMP( D ); #ifdef ILLEGAL1 CODE( E[4]=334 ); #endif #ifdef ILLEGAL2 CODE( E=A ); #endif } cout << endl; { cout << "Test raw array functions" << endl << "========================" << endl << endl; SimpleRigidArray A; cout << "SimpleRigidArray A;" << endl; SimpleRigidArray B; cout << "SimpleRigidArray B;" << endl; SimpleRigidArray C; cout << "SimpleRigidArray C;" << endl; CODE( A[0]=2; A[1]=3; A[2]=4; A[3]=5; ) CODE( B[0]=1; B[1]=3; B[2]=5; B[3]=7; ) CODE( C[0]=.1; C[1]=.3; C[2]=.5; C[3]=.7; ) DUMP(A); DUMP(B); DUMP(C); section("reduction to scalar"); { FUNC( inline_sum(A) ); FUNC( inline_product(A) ); FUNC( inline_innerproduct(B,A) ); FUNC( inline_innerproduct(C,A) ); FUNC( inline_strideproduct(A,B) ); } section("comparison"); { CODE( B=A; ) DUMP(B); cout << "anysmaller AB: " << boolchar(inline_anylarger(A, B)); cout << endl; B[2]++; DUMP(B); cout << "anysmaller AB: " << boolchar(inline_anylarger(A, B)); cout << endl; B[1]--; DUMP(B); cout << "anysmaller AB: " << boolchar(inline_anylarger(A, B)); cout << endl; B[2]--; DUMP(B); cout << "anysmaller AB: " << boolchar(inline_anylarger(A, B)); cout << endl; } } } /* ----- END OF simplearraytest.cc ----- */