simplearraytest.cc 5.39 KB
Newer Older
thomas.forbriger's avatar
thomas.forbriger committed
1
2
3
4
5
/*! \file simplearraytest.cc
 * \brief test simple array class (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
thomas.forbriger's avatar
thomas.forbriger committed
6
 * $Id$
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
 *  - 10/12/2007   V1.4   compiles and is tested on Fenoglio (64bit)
thomas.forbriger's avatar
thomas.forbriger committed
36
37
38
 * 
 * ============================================================================
 */
thomas.forbriger's avatar
thomas.forbriger committed
39
#define AFF_SIMPLEARRAYTEST_CC_VERSION \
thomas.forbriger's avatar
thomas.forbriger committed
40
  "AFF_SIMPLEARRAYTEST_CC   V1.4"
thomas.forbriger's avatar
thomas.forbriger committed
41
#define AFF_SIMPLEARRAYTEST_CC_CVSID \
thomas.forbriger's avatar
thomas.forbriger committed
42
  "$Id$"
thomas.forbriger's avatar
thomas.forbriger committed
43
44
45

/*! \example tests/simplearraytest.cc
 *
thomas.forbriger's avatar
thomas.forbriger committed
46
 * Tests for aff::SimpleRidigArray and aff::util::Inline.
thomas.forbriger's avatar
thomas.forbriger committed
47
 *
thomas.forbriger's avatar
thomas.forbriger committed
48
49
50
51
52
53
54
55
 * 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
56
57
58
59
 * \sa tests/simplearraytest.cc
 */

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

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

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

68
69
70
//! print result of function
#define FUNC( func ) cout << #func << "=" << func << endl

thomas.forbriger's avatar
thomas.forbriger committed
71
72
73
74
75
76
77
78
//! return string for bool value
const char* boolchar(const bool& v)
{
  char *s;
  if (v) { s="true"; } else { s="false"; }
  return(s);
}

79
80
81
82
83
84
85
86
87
88
89
90
91
//! 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
92
93
94
//! Test for the SimpleRigidArray module and associated functions
int main()
{
thomas.forbriger's avatar
thomas.forbriger committed
95
96
  cout << AFF_SIMPLEARRAYTEST_CC_VERSION << endl;
  cout << AFF_SIMPLEARRAYTEST_CC_CVSID << endl << endl;;
thomas.forbriger's avatar
thomas.forbriger committed
97

thomas.forbriger's avatar
thomas.forbriger committed
98
  // test for basic functionality of SimpleRigidArray
thomas.forbriger's avatar
thomas.forbriger committed
99
  {
thomas.forbriger's avatar
thomas.forbriger committed
100
    cout << "Test SimpleRigidArray" << endl
101
102
103
         << "=====================" << endl;

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

thomas.forbriger's avatar
thomas.forbriger committed
105
    SimpleRigidArray<double, 6> A,B(8.);
thomas.forbriger's avatar
thomas.forbriger committed
106
107
108
109
    SimpleRigidArray<int, 4> C,D(100);

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

thomas.forbriger's avatar
thomas.forbriger committed
111
112
113
114
    DUMP( A );
    DUMP( B );
    DUMP( C );
    DUMP( D );
thomas.forbriger's avatar
thomas.forbriger committed
115

116
117
118
119
120
121
122
123
124
125
126
    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
127
128
    CODE( A=B; )
    CODE( C=D; )
thomas.forbriger's avatar
thomas.forbriger committed
129

130
    CODE( B[3]=78.5; )
thomas.forbriger's avatar
thomas.forbriger committed
131
    CODE( D[2]=7883; )
thomas.forbriger's avatar
thomas.forbriger committed
132
    CODE( C[2]=int(-13.2); )
133
134
135

    CODE( F=C; )
    CODE( F[1]=-13.2; )
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 );
141
    DUMP( F );
thomas.forbriger's avatar
thomas.forbriger committed
142

thomas.forbriger's avatar
thomas.forbriger committed
143
    CODE( D=777; )
thomas.forbriger's avatar
thomas.forbriger committed
144

thomas.forbriger's avatar
thomas.forbriger committed
145
    DUMP( D );
thomas.forbriger's avatar
thomas.forbriger committed
146

thomas.forbriger's avatar
thomas.forbriger committed
147
// the following is illegal, since E is declared with a const qualifier
thomas.forbriger's avatar
thomas.forbriger committed
148
#ifdef ILLEGAL1
149
150
151
    CODE( E[4]=334 );
#endif

thomas.forbriger's avatar
thomas.forbriger committed
152
// the following is illegal, since E is declared with a const qualifier
153
154
#ifdef ILLEGAL2
    CODE( E=A );
thomas.forbriger's avatar
thomas.forbriger committed
155
#endif
156

thomas.forbriger's avatar
thomas.forbriger committed
157
158
  }

thomas.forbriger's avatar
thomas.forbriger committed
159
160
  cout << endl;

thomas.forbriger's avatar
thomas.forbriger committed
161
  {
thomas.forbriger's avatar
thomas.forbriger committed
162
163
    cout << "Test raw array functions" << endl
         << "========================" << endl << endl;
164

thomas.forbriger's avatar
thomas.forbriger committed
165
    SimpleRigidArray<int, 4> A;
166
167
168
169
    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
170
    cout << "SimpleRigidArray<float, 4> C;" << endl;
thomas.forbriger's avatar
thomas.forbriger committed
171

172
173
174
    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
175
176

    DUMP(A);
177
178
179
180
181
182
183
184
185
186
    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
187
188
    }

189
190
191
    section("comparison");
    { 
      CODE( B=A; )
thomas.forbriger's avatar
thomas.forbriger committed
192
      DUMP(B);
thomas.forbriger's avatar
thomas.forbriger committed
193
194
195
196
197
      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
198
      B[2]++; DUMP(B);
thomas.forbriger's avatar
thomas.forbriger committed
199
200
201
202
203
      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
204
      B[1]--; DUMP(B);
thomas.forbriger's avatar
thomas.forbriger committed
205
206
207
208
209
      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
210
      B[2]--; DUMP(B);
thomas.forbriger's avatar
thomas.forbriger committed
211
212
213
214
215
216
217
218
219
220
      cout << "anysmaller A<B: " 
        << boolchar(inline_anysmaller(A, B));
      cout << "  anylarger A>B: " 
        << boolchar(inline_anylarger(A, B));
      cout << endl;
    }
  }
}

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