operatortest.cc 3.97 KB
Newer Older
thomas.forbriger's avatar
thomas.forbriger committed
1
2
3
4
5
/*! \file operatortest.cc
 * \brief test operator functions
 * 
 * ----------------------------------------------------------------------------
 * 
thomas.forbriger's avatar
thomas.forbriger committed
6
 * $Id$
thomas.forbriger's avatar
thomas.forbriger committed
7
8
9
10
 * \author Thomas Forbriger
 * \date 10/02/2004
 * 
 * test operator functions
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
 * 
 * Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach) 
 * 
 * REVISIONS and CHANGES 
 *  - 10/02/2004   V1.0   Thomas Forbriger
32
 *  - 05/07/2005   V1.1   check operators on containers declared const
thomas.forbriger's avatar
thomas.forbriger committed
33
34
35
36
 * 
 * ============================================================================
 */
#define OPERATORTEST_VERSION \
37
  "OPERATORTEST   V1.1   test operator functions"
thomas.forbriger's avatar
thomas.forbriger committed
38
#define OPERATORTEST_CVSID \
thomas.forbriger's avatar
thomas.forbriger committed
39
  "$Id$"
thomas.forbriger's avatar
thomas.forbriger committed
40
41

#include <iostream>
thomas.forbriger's avatar
thomas.forbriger committed
42
#include <complex>
thomas.forbriger's avatar
thomas.forbriger committed
43
#include <aff/array.h>
thomas.forbriger's avatar
thomas.forbriger committed
44
#include <aff/series.h>
thomas.forbriger's avatar
thomas.forbriger committed
45
46
#include <aff/dump.h>
#include <aff/arrayoperators.h>
thomas.forbriger's avatar
thomas.forbriger committed
47
48
#include <aff/seriesoperators.h>
#include <aff/subarray.h>
thomas.forbriger's avatar
thomas.forbriger committed
49
50
51
52
53

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

thomas.forbriger's avatar
thomas.forbriger committed
54
55
56
57
58
59
60
61
62
63
64
65
66
/*----------------------------------------------------------------------*/

//! print headline
void section(const char* s, const char l='-')
{
  cout << endl << s << endl;
  const char* p=s;
  while (*p) { cout << l; ++p; }
  cout << endl;
}

/*======================================================================*/

thomas.forbriger's avatar
thomas.forbriger committed
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*! \example tests/operatortest.cc
 *
 * Here you can learn how to use operators with aff classes.
 *
 * This test program gives an example of the usage of the following classes,
 * functions, and preprocessor macros:
 *   - aff::Array
 *   - aff::ConstArray
 *   - aff::dump
 *   - aff::dump_array
 *   - #DUMP
 *   - #CODE
 *
 * \sa tests/operatortest.cc
 */

int main(int iargc, char* argv[])
{
  cout << OPERATORTEST_VERSION << endl;
  cout << OPERATORTEST_CVSID << endl;

thomas.forbriger's avatar
thomas.forbriger committed
88
89
90
91
  section("Test array operators", '=');
  section("Normal array with unary operator");
  CODE(aff::Array<double> A(4,4));
  CODE(A=14.);
thomas.forbriger's avatar
thomas.forbriger committed
92
  CODE(dump_array(A));
thomas.forbriger's avatar
thomas.forbriger committed
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
  CODE(A+=500.);
  CODE(dump_array(A));

  section("Access through subarray");
  CODE(aff::Array<double> Asub=aff::subarray(A)(2,3)(2,3));
  CODE(Asub/=200);
  CODE(dump_array(A));

  section("binary operator");
  CODE(aff::Array<double> B(A));
  CODE(B=A*5);
  CODE(dump_array(B));

  section("test implicit type conversion");
  CODE(B=10.);
thomas.forbriger's avatar
thomas.forbriger committed
108
109
  CODE(dump_array(B));
  CODE(B*=0.2);
thomas.forbriger's avatar
thomas.forbriger committed
110
  CODE(dump_array(B));
thomas.forbriger's avatar
thomas.forbriger committed
111
  CODE(B*=4L);
thomas.forbriger's avatar
thomas.forbriger committed
112
  CODE(dump_array(B));
thomas.forbriger's avatar
thomas.forbriger committed
113
114
  CODE(B*=0xa0);
  CODE(dump_array(B));
thomas.forbriger's avatar
thomas.forbriger committed
115
116

  section("test advanced type conversion");
thomas.forbriger's avatar
thomas.forbriger committed
117
118
119
120
121
  CODE(aff::Array<std::complex<double> > C(3,3);)
  CODE(C=std::complex<double>(14.,2.);)
  CODE(dump_array(C));
  CODE(C*=0.2);
  CODE(dump_array(C));
thomas.forbriger's avatar
thomas.forbriger committed
122
123
124
125
126
127
128
129
130
131

  section("test binary operator with constant input");
  CODE(aff::ConstArray<double> D(A));
  CODE(aff::Array<double> E(D*2.));
  CODE(dump_array(E));

  section("mixed implicit operations");
  CODE(dump_array((D*5.)-12L));

  section("Test series operators", '=');
132
  section("test scalar operators");
thomas.forbriger's avatar
thomas.forbriger committed
133
134
135
136
137
  CODE(aff::Series<double> F(-3,3));
  CODE(F=5.);
  DUMP(F);
  CODE(F/=25.);
  DUMP(F);
138
139
140
141
142
143
144
145
146
147
148
149
150

  section("test vector operators");
  CODE(aff::Series<double> G(5));
  CODE(G=5.);
  DUMP(G);
  DUMP(F+G);
  CODE(aff::Series<double> H);
  CODE(H=F+G);
  DUMP(H);
  CODE(H -= F);
  DUMP(H);
  DUMP((H *= G + 0.2) + 0.2);
  DUMP(H);
151
152
  DUMP(100+H);
  DUMP(H+100);
153
154
155
156
  CODE(const aff::Series<double> CH(H));
  DUMP(CH+100);
  DUMP(CH -= 10);
  DUMP(CH);
thomas.forbriger's avatar
thomas.forbriger committed
157
158
159
}

/* ----- END OF operatortest.cc ----- */