seriestest.cc 2.56 KB
Newer Older
thomas.forbriger's avatar
thomas.forbriger committed
1
2
3
4
5
/*! \file seriestest.cc
 * \brief test aff::Series class (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
thomas.forbriger's avatar
thomas.forbriger committed
6
 * $Id: seriestest.cc,v 1.3 2002-12-29 00:09:07 forbrig Exp $
thomas.forbriger's avatar
thomas.forbriger committed
7
8
9
10
11
12
13
14
15
 * \author Thomas Forbriger
 * \date 17/12/2002
 * 
 * test aff::Series class (implementation)
 * 
 * Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt) 
 * 
 * REVISIONS and CHANGES 
 *  - 17/12/2002   V1.0   Thomas Forbriger
thomas.forbriger's avatar
thomas.forbriger committed
16
17
 *  - 28/12/2002   V1.1   (thof)
 *                        - new term for containers of const elements
thomas.forbriger's avatar
thomas.forbriger committed
18
19
20
21
22
23
 * 
 * ============================================================================
 */
#define AFF_SERIESTEST_CC_VERSION \
  "AFF_SERIESTEST_CC   V1.1"
#define AFF_SERIESTEST_CC_CVSID \
thomas.forbriger's avatar
thomas.forbriger committed
24
  "$Id: seriestest.cc,v 1.3 2002-12-29 00:09:07 forbrig Exp $"
thomas.forbriger's avatar
thomas.forbriger committed
25
26
27
28
29
30
31

#include <aff/series.h>
#include <aff/dump.h>

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

thomas.forbriger's avatar
thomas.forbriger committed
32
33
34
35
36
37
38
/*! \example tests/seriestest.cc
 *
 * Test series class aff::Series.
 *
 * \sa tests/seriestest.cc
 */

thomas.forbriger's avatar
thomas.forbriger committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! echo
#define CODE( C ) cout << #C << endl; C

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

//! testing SharedHeap
int main()
{
  cout << AFF_SERIESTEST_CC_VERSION << endl;
  cout << AFF_SERIESTEST_CC_CVSID << endl;

  section("array dimensions");
  CODE( const int N=10; )
  CODE( const int N2=23; )

  section("instantiate arrays");
  CODE( aff::SharedHeap<int> A(N); )
  CODE( aff::SharedHeap<int> B(N2); )
thomas.forbriger's avatar
thomas.forbriger committed
68
  CODE( aff::ConstSharedHeap<int> C(N2); )
thomas.forbriger's avatar
thomas.forbriger committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  CODE( aff::SharedHeap<float> D(N2); )

  section("create a const reference to D");
  CODE( aff::SharedHeap<float>::Tcoc E(D); )

  section("const int array should share memory with int array");
  CODE( C=B; )

  section("fill arrays");
  CODE( for (int i=0; i<N; i++) { A[i]=(i+1)*10; } )
  CODE( for (int i=0; i<N2; i++) { B[i]=(i+4)*3; } )
  CODE( for (int i=0; i<N2; i++) { D[i]=(i+2.45)*2; } )

  section("dump contents - C is filled through B and E is filled through D");
  DUMP( aff::SharedHeap<int>::Tcontainer_of_const(A) );
  DUMP( B );
  DUMP( C );
  DUMP( E );

  section("modify C through B");
  CODE( B[8]=632; )
  DUMP( C );

#ifdef ILLEGAL1
  // you may activate this section by passing -DILLEGAL1 to the compiler
  section("modify C directly - is illegal");
  C[9]=354;
  DUMP( C );
#endif

  section("make B a reference to A");
  CODE( B=A; )
  section("modification should be visible through B");
  CODE( A[5]=453; )
  DUMP( B );
  section("but C holds the original values");
  DUMP( C );
}

/* ----- END OF seriestest.cc ----- */