AFF --- A container for numbers (array) by Friederich and Forbriger.
simplearraytest.cc
Go to the documentation of this file.
1 
38 #define AFF_SIMPLEARRAYTEST_CC_VERSION \
39  "AFF_SIMPLEARRAYTEST_CC V1.4"
40 
56 #include<iostream>
57 #include<aff/array.h>
58 #include<aff/dump.h>
59 
60 using std::cout;
61 using std::endl;
62 
63 using namespace aff;
64 
66 #define FUNC( func ) cout << #func << "=" << func << endl
67 
69 const char* boolchar(const bool& v)
70 {
71  char *s;
72  if (v) { s="true"; } else { s="false"; }
73  return(s);
74 }
75 
77 void section(const char* s)
78 {
79  cout << endl
80  << s << endl;
81  const char* p=s;
82  while (*p) {
83  cout << "-";
84  ++p;
85  }
86  cout << endl;
87 }
88 
90 int main()
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 }
215 
216 /* ----- END OF simplearraytest.cc ----- */
void section(const char *s)
print headline
Root namespace of library.
Definition: array.h:148
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
int main()
Test for the SimpleRigidArray module and associated functions.
full template array class headers (prototypes)
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
debug helpers (prototypes)
T inline_innerproduct(const SimpleRigidArray< T, N > &A, const SimpleRigidArray< T, N > &B)
Returns inner product.
Definition: simplearray.h:206