simplearraytest.cc 5.81 KB
Newer Older
thomas.forbriger's avatar
thomas.forbriger committed
1
2
3
4
5
/*! \file simplearraytest.cc
 * \brief test simple array class (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
6
 * $Id: simplearraytest.cc,v 1.7 2007-12-07 16:50:57 tforb Exp $
thomas.forbriger's avatar
thomas.forbriger committed
7
8
9
10
 * \author Thomas Forbriger
 * \date 25/05/2002
 * 
 * test simple array class (implementation)
thomas.forbriger's avatar
thomas.forbriger committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 *
 * ----
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version. 
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 * ----
thomas.forbriger's avatar
thomas.forbriger committed
27
28
29
30
31
32
33
 * 
 * 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
thomas.forbriger's avatar
thomas.forbriger committed
34
 *  - 13/12/2002   V1.3   reworked for libaff
thomas.forbriger's avatar
thomas.forbriger committed
35
36
37
 * 
 * ============================================================================
 */
thomas.forbriger's avatar
thomas.forbriger committed
38
39
40
#define AFF_SIMPLEARRAYTEST_CC_VERSION \
  "AFF_SIMPLEARRAYTEST_CC   V1.3"
#define AFF_SIMPLEARRAYTEST_CC_CVSID \
41
  "$Id: simplearraytest.cc,v 1.7 2007-12-07 16:50:57 tforb Exp $"
thomas.forbriger's avatar
thomas.forbriger committed
42
43
44

/*! \example tests/simplearraytest.cc
 *
thomas.forbriger's avatar
thomas.forbriger committed
45
 * Tests for aff::SimpleRidigArray and aff::util::Inline.
thomas.forbriger's avatar
thomas.forbriger committed
46
 *
thomas.forbriger's avatar
thomas.forbriger committed
47
48
49
50
51
52
53
54
 * This test program gives an example of the usage of the following classes,
 * functions, and preprocessor macros:
 *   - aff::SimpleRigidArray
 *   - aff::util::Inline
 *   - aff::dump
 *   - #DUMP
 *   - #CODE
 *
thomas.forbriger's avatar
thomas.forbriger committed
55
56
57
58
 * \sa tests/simplearraytest.cc
 */

#include<iostream>
thomas.forbriger's avatar
thomas.forbriger committed
59
#include<aff/array.h>
60
61
62
//#include<aff/dump.h>
//#include<aff/lib/dump_simplerigidarray.h>
#include<aff/lib/dump_macros.h>
thomas.forbriger's avatar
thomas.forbriger committed
63
64
65
66

using std::cout;
using std::endl;

thomas.forbriger's avatar
thomas.forbriger committed
67
using namespace aff;
thomas.forbriger's avatar
thomas.forbriger committed
68

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
namespace aff {
template<typename T, int N>
void dump(const aff::SimpleRigidArray<T,N>& array, std::ostream& os=std::cout)
{
  cout << "This is my dump of size " << N << endl;
  int i=0;
  for (aff::Tsize k=0; k<N; k++)
  {
    if (!i) { os << "  "; }
    os.width(9);
    os << array[k] << " ";
    if (++i>7) { i=0; os << endl; }
  }
  os << endl;
}
}

template<typename T, Tsize N>
Tsize myf(aff::SimpleRigidArray<T,N> a)
{
  return(N);
}

92
93
94
//! print result of function
#define FUNC( func ) cout << #func << "=" << func << endl

thomas.forbriger's avatar
thomas.forbriger committed
95
96
97
98
99
100
101
102
//! return string for bool value
const char* boolchar(const bool& v)
{
  char *s;
  if (v) { s="true"; } else { s="false"; }
  return(s);
}

103
104
105
106
107
108
109
110
111
112
113
114
115
//! print headline
void section(const char* s)
{
  cout << endl
       << s << endl;
  const char* p=s;
  while (*p) {
    cout << "-";
    ++p;
  }
  cout << endl;
}

thomas.forbriger's avatar
thomas.forbriger committed
116
117
118
//! Test for the SimpleRigidArray module and associated functions
int main()
{
thomas.forbriger's avatar
thomas.forbriger committed
119
120
  cout << AFF_SIMPLEARRAYTEST_CC_VERSION << endl;
  cout << AFF_SIMPLEARRAYTEST_CC_CVSID << endl << endl;;
thomas.forbriger's avatar
thomas.forbriger committed
121

thomas.forbriger's avatar
thomas.forbriger committed
122
  // test for basic functionality of SimpleRigidArray
thomas.forbriger's avatar
thomas.forbriger committed
123
  {
thomas.forbriger's avatar
thomas.forbriger committed
124
    cout << "Test SimpleRigidArray" << endl
125
126
127
         << "=====================" << endl;

    section("constructors");
thomas.forbriger's avatar
thomas.forbriger committed
128

thomas.forbriger's avatar
thomas.forbriger committed
129
    SimpleRigidArray<double, 6> A,B(8.);
thomas.forbriger's avatar
thomas.forbriger committed
130
131
132
133
    SimpleRigidArray<int, 4> C,D(100);

    cout << "SimpleRigidArray<double, 6> A,B(8.);" << endl;
    cout << "SimpleRigidArray<int, 4> C,D(100);" << endl;
134
135

    myf(A);
thomas.forbriger's avatar
thomas.forbriger committed
136
   
thomas.forbriger's avatar
thomas.forbriger committed
137
138
139
140
    DUMP( A );
    DUMP( B );
    DUMP( C );
    DUMP( D );
thomas.forbriger's avatar
thomas.forbriger committed
141

142
143
144
145
146
147
148
149
150
151
152
    const SimpleRigidArray<int, 4> E(D);
    cout << "const SimpleRigidArray<int, 4> E(D);" << endl;

    SimpleRigidArray<float, 4> F(D);
    cout << "SimpleRigidArray<float, 4> F(D);" << endl;

    DUMP( E );
    DUMP( F );

    section("assignment");

thomas.forbriger's avatar
thomas.forbriger committed
153
154
    CODE( A=B; )
    CODE( C=D; )
thomas.forbriger's avatar
thomas.forbriger committed
155

156
    CODE( B[3]=78.5; )
thomas.forbriger's avatar
thomas.forbriger committed
157
    CODE( D[2]=7883; )
158
159
160
161
    CODE( C[2]=-13.2; )

    CODE( F=C; )
    CODE( F[1]=-13.2; )
thomas.forbriger's avatar
thomas.forbriger committed
162
   
thomas.forbriger's avatar
thomas.forbriger committed
163
164
165
166
    DUMP( A );
    DUMP( B );
    DUMP( C );
    DUMP( D );
167
    DUMP( F );
thomas.forbriger's avatar
thomas.forbriger committed
168

thomas.forbriger's avatar
thomas.forbriger committed
169
    CODE( D=777; )
thomas.forbriger's avatar
thomas.forbriger committed
170

thomas.forbriger's avatar
thomas.forbriger committed
171
    DUMP( D );
thomas.forbriger's avatar
thomas.forbriger committed
172
173

#ifdef ILLEGAL1
174
175
176
177
178
    CODE( E[4]=334 );
#endif

#ifdef ILLEGAL2
    CODE( E=A );
thomas.forbriger's avatar
thomas.forbriger committed
179
#endif
180

thomas.forbriger's avatar
thomas.forbriger committed
181
182
  }

thomas.forbriger's avatar
thomas.forbriger committed
183
184
  cout << endl;

thomas.forbriger's avatar
thomas.forbriger committed
185
  {
thomas.forbriger's avatar
thomas.forbriger committed
186
187
    cout << "Test raw array functions" << endl
         << "========================" << endl << endl;
188

thomas.forbriger's avatar
thomas.forbriger committed
189
    SimpleRigidArray<int, 4> A;
190
191
192
193
    cout << "SimpleRigidArray<int, 4> A;" << endl;
    SimpleRigidArray<int, 4> B;
    cout << "SimpleRigidArray<int, 4> B;" << endl;
    SimpleRigidArray<float, 4> C;
thomas.forbriger's avatar
thomas.forbriger committed
194
    cout << "SimpleRigidArray<float, 4> C;" << endl;
thomas.forbriger's avatar
thomas.forbriger committed
195

196
197
198
    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; )
thomas.forbriger's avatar
thomas.forbriger committed
199
200

    DUMP(A);
201
202
203
204
205
206
207
208
209
210
    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) );
thomas.forbriger's avatar
thomas.forbriger committed
211
212
    }

213
214
215
    section("comparison");
    { 
      CODE( B=A; )
thomas.forbriger's avatar
thomas.forbriger committed
216
      DUMP(B);
thomas.forbriger's avatar
thomas.forbriger committed
217
218
219
220
221
      cout << "anysmaller A<B: " 
        << boolchar(inline_anysmaller(A, B));
      cout << "  anylarger A>B: " 
        << boolchar(inline_anylarger(A, B));
      cout << endl;
thomas.forbriger's avatar
thomas.forbriger committed
222
      B[2]++; DUMP(B);
thomas.forbriger's avatar
thomas.forbriger committed
223
224
225
226
227
      cout << "anysmaller A<B: " 
        << boolchar(inline_anysmaller(A, B));
      cout << "  anylarger A>B: " 
        << boolchar(inline_anylarger(A, B));
      cout << endl;
thomas.forbriger's avatar
thomas.forbriger committed
228
      B[1]--; DUMP(B);
thomas.forbriger's avatar
thomas.forbriger committed
229
230
231
232
233
      cout << "anysmaller A<B: " 
        << boolchar(inline_anysmaller(A, B));
      cout << "  anylarger A>B: " 
        << boolchar(inline_anylarger(A, B));
      cout << endl;
thomas.forbriger's avatar
thomas.forbriger committed
234
      B[2]--; DUMP(B);
thomas.forbriger's avatar
thomas.forbriger committed
235
236
237
238
239
240
241
242
243
244
      cout << "anysmaller A<B: " 
        << boolchar(inline_anysmaller(A, B));
      cout << "  anylarger A>B: " 
        << boolchar(inline_anylarger(A, B));
      cout << endl;
    }
  }
}

/* ----- END OF simplearraytest.cc ----- */