simplearraytest.cc 4.01 KB
Newer Older
thomas.forbriger's avatar
thomas.forbriger committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
68
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*! \file simplearraytest.cc
 * \brief test simple array class (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
 * $Id: simplearraytest.cc,v 1.1 2002-12-06 19:21:08 forbrig Exp $
 * \author Thomas Forbriger
 * \date 25/05/2002
 * 
 * test simple array class (implementation)
 * 
 * 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
 * 
 * ============================================================================
 */
#define TF_SIMPLEARRAYTEST_CC_VERSION \
  "TF_SIMPLEARRAYTEST_CC   V1.2   "
#define TF_SIMPLEARRAYTEST_CC_CVSID \
  "$Id: simplearraytest.cc,v 1.1 2002-12-06 19:21:08 forbrig Exp $"

/*! \example tests/simplearraytest.cc
 *
 * Tests for contxx::util::SimpleRidigArray and contxx::util::Inline.
 *
 * \sa tests/simplearraytest.cc
 * \sa contxx::util::SimpleRidigArray
 * \sa contxx::util::Inline
 */

#include<iostream>
#include<contxx/util/simplearray.h>
#include<contxx/util/rawarfun.h>
#include<contxx/shape/shaper.h>

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

using namespace contxx::util;

//! Print a SimpleRigidArray
template<class T, Tsize N>
void print(const char* name, const SimpleRigidArray<T,N>& array)
{
  cout << "array " << name << ":" << endl;
  for (Tsubscript i=0; i<static_cast<Tsubscript>(array.size()); i++)
  { cout << i << ": " << array[i] << "  "; }
  cout << endl;
}

//! Print a SimpleRigidArray and its name
#define PRINT( array ) print( #array , array ); cout << endl;

//! Print a SimpleRigidArray and its name
#define PRINTA( array ) cout << "----" << endl; print( #array , array )

//! Print code and execute
#define CODE( code ) cout << #code << endl; code

//! return string for bool value
const char* boolchar(const bool& v)
{
  char *s;
  if (v) { s="true"; } else { s="false"; }
  return(s);
}

//! Test for the SimpleRigidArray module and associated functions
int main()
{
  cout << TF_SIMPLEARRAYTEST_CC_VERSION << endl;
  cout << TF_SIMPLEARRAYTEST_CC_CVSID << endl << endl;;

  {
    SimpleRigidArray<double, 6> A,B(8.);
    SimpleRigidArray<int, 10> C,D(100);
   
    PRINT( A )
    PRINT( B )
    PRINT( C )
    PRINT( D )

    A=B;
    C=D;

    B[3]=78.;
    D[7]=7883;
   
    PRINT( A )
    PRINT( B )
    PRINT( C )
    PRINT( D )

    D=777;

    PRINT( D )

    const SimpleRigidArray<int, 10> E(C);

    PRINT( E )

#ifdef ILLEGAL1
    E[4]=334;
#endif

    PRINT( contxx::shape::tuple(3, 6, 7) )
    PRINT( contxx::shape::tuple(3, 6, 7, 2, 1) )
  }

  {
    cout << endl;
    cout << "test raw array functions" << endl
      <<    "========================" << endl << endl;
    SimpleRigidArray<int, 4> A;
    A[0]=2;
    A[1]=3;
    A[2]=4;
    A[3]=5;

    PRINTA(A);
    cout << "sum A: " << inline_sum(A) << endl;
    cout << "product A: " << inline_product(A) << endl;
    { SimpleRigidArray<int, 4> B(1); PRINTA(B);
      CODE(( inline_set<int, 4>(B.pointer(), 16)) ); PRINT(B) }
    { SimpleRigidArray<int, 4> B(1); PRINTA(B);
      CODE(( inline_copy<int, 4>(A.pointer(), B.pointer())) ); PRINTA(B); }
    { SimpleRigidArray<int, 4> B(A);
      PRINTA(B);
      cout << "anysmaller A<B: " 
        << boolchar(inline_anysmaller(A, B));
      cout << "  anylarger A>B: " 
        << boolchar(inline_anylarger(A, B));
      cout << endl;
      B[2]++; PRINTA(B);
      cout << "anysmaller A<B: " 
        << boolchar(inline_anysmaller(A, B));
      cout << "  anylarger A>B: " 
        << boolchar(inline_anylarger(A, B));
      cout << endl;
      B[1]--; PRINTA(B);
      cout << "anysmaller A<B: " 
        << boolchar(inline_anysmaller(A, B));
      cout << "  anylarger A>B: " 
        << boolchar(inline_anylarger(A, B));
      cout << endl;
      B[2]--; PRINTA(B);
      cout << "anysmaller A<B: " 
        << boolchar(inline_anysmaller(A, B));
      cout << "  anylarger A>B: " 
        << boolchar(inline_anylarger(A, B));
      cout << endl;
    }
  }
}

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