simplearraytest.cc 5.29 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: simplearraytest.cc,v 1.6 2006-03-28 16:03:12 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 \
thomas.forbriger's avatar
thomas.forbriger committed
41
  "$Id: simplearraytest.cc,v 1.6 2006-03-28 16:03:12 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
60
#include<aff/array.h>
#include<aff/dump.h>
thomas.forbriger's avatar
thomas.forbriger committed
61
62
63
64

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

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

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

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

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

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

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

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

    cout << "SimpleRigidArray<double, 6> A,B(8.);" << endl;
    cout << "SimpleRigidArray<int, 4> C,D(100);" << endl;
thomas.forbriger's avatar
thomas.forbriger committed
109
   
thomas.forbriger's avatar
thomas.forbriger committed
110
111
112
113
    DUMP( A );
    DUMP( B );
    DUMP( C );
    DUMP( D );
thomas.forbriger's avatar
thomas.forbriger committed
114

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

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

    CODE( F=C; )
    CODE( F[1]=-13.2; )
thomas.forbriger's avatar
thomas.forbriger committed
135
   
thomas.forbriger's avatar
thomas.forbriger committed
136
137
138
139
    DUMP( A );
    DUMP( B );
    DUMP( C );
    DUMP( D );
140
    DUMP( F );
thomas.forbriger's avatar
thomas.forbriger committed
141

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

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

#ifdef ILLEGAL1
147
148
149
150
151
    CODE( E[4]=334 );
#endif

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

thomas.forbriger's avatar
thomas.forbriger committed
154
155
  }

thomas.forbriger's avatar
thomas.forbriger committed
156
157
  cout << endl;

thomas.forbriger's avatar
thomas.forbriger committed
158
  {
thomas.forbriger's avatar
thomas.forbriger committed
159
160
    cout << "Test raw array functions" << endl
         << "========================" << endl << endl;
161

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

169
170
171
    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
172
173

    DUMP(A);
174
175
176
177
178
179
180
181
182
183
    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
184
185
    }

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

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