/*! \file helpertest.cc * \brief test helpers like iterator, subarray and slice (implementation) * * ---------------------------------------------------------------------------- * * $Id: helpertest.cc,v 1.1 2002-12-23 11:45:02 forbrig Exp $ * \author Thomas Forbriger * \date 23/12/2002 * * test helpers like iterator, subarray and slice (implementation) * * Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt) * * REVISIONS and CHANGES * - 23/12/2002 V1.0 Thomas Forbriger * * ============================================================================ */ #define AFF_HELPERTEST_CC_VERSION \ "AFF_HELPERTEST_CC V1.0 " #define AFF_HELPERTEST_CC_CVSID \ "$Id: helpertest.cc,v 1.1 2002-12-23 11:45:02 forbrig Exp $" /*! \example tests/helpertest.cc * * Test helper classes. * * \sa tests/helpertest.cc * \sa aff::Iterator * \sa aff::Subarray * \sa aff::Slice */ #include #include #include #include #include #include using std::cout; using std::endl; using namespace aff; /*----------------------------------------------------------------------*/ //! print headline void section(const char* s, const char l='-') { cout << endl << s << endl; const char* p=s; while (*p) { cout << l; ++p; } cout << endl; } /*----------------------------------------------------------------------*/ //! test for passing subarrays and slices template void printarray(const Array& array) { cout << endl; cout << "Received array in function:" << endl; dump_array(array); } /*======================================================================*/ //! test helper classes int main() { cout << AFF_HELPERTEST_CC_VERSION << endl; cout << AFF_HELPERTEST_CC_CVSID << endl; section("Preparing test array"); CODE( Array A(Shaper(-2,2)(-3,3)) ); CODE( dump_array(A) ); section("Tests for class Iterator", '='); { CODE(int i=1); CODE(for( Iterator > I(A); I.valid(); ++I) { *I=i; i++; }); CODE( dump_array(A) ); } section("Tests for class Subarray", '='); { section("First mode: Use a Subarray object just for initialization"); CODE(Array B=Subarray(A)(-1,1)(-2,2)); CODE( dump_array(B) ); CODE(B=-5); CODE( dump_array(A) ); section("Second mode: Create a Subarray object to which you can assign"); CODE(Subarray S); CODE(S(A)()(1,2)=100); CODE(S(A)(1,1)=-200); CODE( dump_array(A) ); // you must explicitely create an array through member function array() CODE(printarray(Subarray(A)(-2,0)(-3,0).array())); } section("Tests for class Slice", '='); { section("First mode: Use a Slice object just for initialization"); CODE(Array B=Slice(A)(1,-1)); CODE( dump_array(B) ); CODE(B=555); CODE( dump_array(A) ); section("Second mode: Create a Slice object to which you can assign"); CODE(Slice S); CODE(S(A)()(1)=666); CODE(S(A)(0)=-777); CODE( dump_array(A) ); // you must explicitely create an array through member function array() CODE(printarray(Slice(A)(-2).array())); } section("Mixed tests", '='); section("Iterator on a Subarray"); { CODE(int i=501); CODE(Array B=Subarray(A)(-1,1)(-2,2)); CODE(for( Iterator > I(B); I.valid(); ++I) { *I=i; i++; }); CODE( dump_array(A) ); } section("Iterator on a Slice"); { CODE(int i=-801); CODE(Array B=Slice(A)(1)); CODE(for( Iterator > I(B); I.valid(); ++I) { *I=i; i++; }); CODE( dump_array(A) ); } section("Extract copy of subarray"); { CODE(Array B=Subarray(A)(-1,1)(-1,1)); CODE(dump_array(B)); CODE(Array C=B.copyout()); CODE(dump_array(C)); } } /* ----- END OF helpertest.cc ----- */