AFF --- A container for numbers (array) by Friederich and Forbriger.
tests/simplearraytest.cc

Tests for aff::SimpleRidigArray and aff::util::Inline.

This test program gives an example of the usage of the following classes, functions, and preprocessor macros:

See also
tests/simplearraytest.cc
#define AFF_SIMPLEARRAYTEST_CC_VERSION \
"AFF_SIMPLEARRAYTEST_CC V1.4"
#include<iostream>
#include<aff/array.h>
#include<aff/dump.h>
using std::cout;
using std::endl;
using namespace aff;
#define FUNC( func ) cout << #func << "=" << func << endl
const char* boolchar(const bool& v)
{
char *s;
if (v) { s="true"; } else { s="false"; }
return(s);
}
void section(const char* s)
{
cout << endl
<< s << endl;
const char* p=s;
while (*p) {
cout << "-";
++p;
}
cout << endl;
}
int main()
{
// test for basic functionality of SimpleRigidArray
{
cout << "Test SimpleRigidArray" << endl
<< "=====================" << endl;
section("constructors");
cout << "SimpleRigidArray<double, 6> A,B(8.);" << endl;
cout << "SimpleRigidArray<int, 4> C,D(100);" << endl;
DUMP( A );
DUMP( B );
DUMP( C );
DUMP( D );
cout << "const SimpleRigidArray<int, 4> E(D);" << endl;
cout << "SimpleRigidArray<float, 4> 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]=int(-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 );
// the following is illegal, since E is declared with a const qualifier
#ifdef ILLEGAL1
CODE( E[4]=334 );
#endif
// the following is illegal, since E is declared with a const qualifier
#ifdef ILLEGAL2
CODE( E=A );
#endif
}
cout << endl;
{
cout << "Test raw array functions" << endl
<< "========================" << endl << endl;
cout << "SimpleRigidArray<int, 4> A;" << endl;
cout << "SimpleRigidArray<int, 4> B;" << endl;
cout << "SimpleRigidArray<float, 4> 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");
{
}
section("comparison");
{
CODE( B=A; )
DUMP(B);
cout << "anysmaller A<B: "
cout << " anylarger A>B: "
cout << endl;
B[2]++; DUMP(B);
cout << "anysmaller A<B: "
cout << " anylarger A>B: "
cout << endl;
B[1]--; DUMP(B);
cout << "anysmaller A<B: "
cout << " anylarger A>B: "
cout << endl;
B[2]--; DUMP(B);
cout << "anysmaller A<B: "
cout << " anylarger A>B: "
cout << endl;
}
}
}
/* ----- END OF simplearraytest.cc ----- */