AFF --- A container for numbers (array) by Friederich and Forbriger.

◆ main()

int main ( )

Test for the SimpleRigidArray module and associated functions.

Definition at line 90 of file simplearraytest.cc.

References AFF_SIMPLEARRAYTEST_CC_VERSION, boolchar(), CODE, DUMP, FUNC, aff::inline_anylarger(), aff::inline_anysmaller(), aff::inline_innerproduct(), aff::inline_product(), aff::inline_strideproduct(), aff::inline_sum(), and section().

91 {
92  cout << AFF_SIMPLEARRAYTEST_CC_VERSION << endl;
93 
94  // test for basic functionality of SimpleRigidArray
95  {
96  cout << "Test SimpleRigidArray" << endl
97  << "=====================" << endl;
98 
99  section("constructors");
100 
102  SimpleRigidArray<int, 4> C,D(100);
103 
104  cout << "SimpleRigidArray<double, 6> A,B(8.);" << endl;
105  cout << "SimpleRigidArray<int, 4> C,D(100);" << endl;
106 
107  DUMP( A );
108  DUMP( B );
109  DUMP( C );
110  DUMP( D );
111 
112  const SimpleRigidArray<int, 4> E(D);
113  cout << "const SimpleRigidArray<int, 4> E(D);" << endl;
114 
116  cout << "SimpleRigidArray<float, 4> F(D);" << endl;
117 
118  DUMP( E );
119  DUMP( F );
120 
121  section("assignment");
122 
123  CODE( A=B; )
124  CODE( C=D; )
125 
126  CODE( B[3]=78.5; )
127  CODE( D[2]=7883; )
128  CODE( C[2]=int(-13.2); )
129 
130  CODE( F=C; )
131  CODE( F[1]=-13.2; )
132 
133  DUMP( A );
134  DUMP( B );
135  DUMP( C );
136  DUMP( D );
137  DUMP( F );
138 
139  CODE( D=777; )
140 
141  DUMP( D );
142 
143 // the following is illegal, since E is declared with a const qualifier
144 #ifdef ILLEGAL1
145  CODE( E[4]=334 );
146 #endif
147 
148 // the following is illegal, since E is declared with a const qualifier
149 #ifdef ILLEGAL2
150  CODE( E=A );
151 #endif
152 
153  }
154 
155  cout << endl;
156 
157  {
158  cout << "Test raw array functions" << endl
159  << "========================" << endl << endl;
160 
162  cout << "SimpleRigidArray<int, 4> A;" << endl;
164  cout << "SimpleRigidArray<int, 4> B;" << endl;
166  cout << "SimpleRigidArray<float, 4> C;" << endl;
167 
168  CODE( A[0]=2; A[1]=3; A[2]=4; A[3]=5; )
169  CODE( B[0]=1; B[1]=3; B[2]=5; B[3]=7; )
170  CODE( C[0]=.1; C[1]=.3; C[2]=.5; C[3]=.7; )
171 
172  DUMP(A);
173  DUMP(B);
174  DUMP(C);
175 
176  section("reduction to scalar");
177  {
178  FUNC( inline_sum(A) );
179  FUNC( inline_product(A) );
180  FUNC( inline_innerproduct(B,A) );
181  FUNC( inline_innerproduct(C,A) );
182  FUNC( inline_strideproduct(A,B) );
183  }
184 
185  section("comparison");
186  {
187  CODE( B=A; )
188  DUMP(B);
189  cout << "anysmaller A<B: "
190  << boolchar(inline_anysmaller(A, B));
191  cout << " anylarger A>B: "
192  << boolchar(inline_anylarger(A, B));
193  cout << endl;
194  B[2]++; DUMP(B);
195  cout << "anysmaller A<B: "
196  << boolchar(inline_anysmaller(A, B));
197  cout << " anylarger A>B: "
198  << boolchar(inline_anylarger(A, B));
199  cout << endl;
200  B[1]--; DUMP(B);
201  cout << "anysmaller A<B: "
202  << boolchar(inline_anysmaller(A, B));
203  cout << " anylarger A>B: "
204  << boolchar(inline_anylarger(A, B));
205  cout << endl;
206  B[2]--; DUMP(B);
207  cout << "anysmaller A<B: "
208  << boolchar(inline_anysmaller(A, B));
209  cout << " anylarger A>B: "
210  << boolchar(inline_anylarger(A, B));
211  cout << endl;
212  }
213  }
214 }
void section(const char *s)
print headline
T inline_product(const SimpleRigidArray< T, N > &array)
Product of all elements.
Definition: simplearray.h:178
#define FUNC(func)
print result of function
const char * boolchar(const bool &v)
return string for bool value
#define AFF_SIMPLEARRAYTEST_CC_VERSION
#define DUMP(A)
Dump any object through its dump function.
Definition: dump_macros.h:62
bool inline_anysmaller(const SimpleRigidArray< T, N > &A, const SimpleRigidArray< T, N > &B)
Returns true if any of A is smaller than corresponding B.
Definition: simplearray.h:188
bool inline_anylarger(const SimpleRigidArray< T, N > &A, const SimpleRigidArray< T, N > &B)
Returns true if any of A is larger than corresponding B.
Definition: simplearray.h:194
T inline_strideproduct(const SimpleRigidArray< T, N > &A, const SimpleRigidArray< T, N > &B)
Returns strided product.
Definition: simplearray.h:218
#define CODE(C)
Dump code and execute (works like echo)
Definition: dump_macros.h:82
A very basic rigid array class (with deep inline copy).
Definition: simplearray.h:94
T inline_sum(const SimpleRigidArray< T, N > &array)
Sum of all elements.
Definition: simplearray.h:183
T inline_innerproduct(const SimpleRigidArray< T, N > &A, const SimpleRigidArray< T, N > &B)
Returns inner product.
Definition: simplearray.h:206
Here is the call graph for this function: