source: Sophya/trunk/SophyaProg/Tests/carrt.cc@ 1100

Last change on this file since 1100 was 1100, checked in by ansari, 25 years ago

Amelioration programmes test de tableaux - Reza 26/7/2000

File size: 4.4 KB
Line 
1#include "machdefs.h"
2
3#include <math.h>
4#include <iostream.h>
5
6#include "tarrinit.h"
7#include "array.h"
8#include "timing.h"
9
10static int test_ac();
11static int test_oso(int r, int c);
12static int test_odo(int r, int c);
13
14static int prtlev = 0;
15static int nprt = 0;
16
17template <class T>
18void getMinMax(TArray<T>& a, T& min, T& max)
19{
20 min = a[0];
21 max = a[0];
22 for(uint_8 k=1; k<a.Size(); k++) {
23 if (a[k]<min) min = a[k];
24 else if (a[k]>max) max = a[k];
25 }
26}
27
28int main(int narg, char* arg[])
29{
30
31 SophyaInit();
32 InitTim(); // Initializing the CPU timer
33
34 if (narg < 2) {
35 cout << " carrt ac/oso/odo [NRow=5] [NCols=10] [prtlev=0] [nprtmax=100] \n"
36 << " ac : array conversion test \n"
37 << " oso : operation same memory organisation \n"
38 << " odo : operation different memory organisation \n" << endl;
39 exit(0);
40 }
41
42 string opt = arg[1];
43 int nr = 5;
44 int nc = 10;
45 if (narg > 2) nr = atoi(arg[2]);
46 if (narg > 3) nc = atoi(arg[3]);
47 if (narg > 4) prtlev = atoi(arg[4]);
48 if (narg > 5) nprt = atoi(arg[5]);
49
50 BaseArray::SetMaxPrint(nprt, prtlev);
51
52 PrtTim(" Start of Test ");
53 try {
54 if (opt == "ac") test_ac();
55 else if (opt == "oso") test_oso(nr, nc);
56 else if (opt == "odo") test_odo(nr, nc);
57 }
58 catch (PThrowable & exc) {
59 cerr << " catched Exception " << exc.Msg() << endl;
60 }
61 catch (...) {
62 cerr << " catched unknown (...) exception " << endl;
63 }
64
65 PrtTim(" End of Test ");
66
67}
68
69
70int test_ac()
71{
72 cout << "\n -----> Testing TArray Conversion <---- " << endl;
73 TArray<int_4> ia(7,5);
74 ia = Sequence(10., 2.);
75 TArray<r_4> ra(7,5);
76 ra = ia;
77 cout << " ra = ia(= Sequence(10., 2.)) = \n " << ra << endl;
78 cout << ra << endl;
79 TArray<r_4> rb(5,3);
80 rb = Sequence(20., .5);
81 TMatrix<int_4> mx(3,5);
82 cout << " TArray<r_4> rb(5,3); rb = Sequence(20., .5); rb : " << endl;
83 cout << rb << endl;
84 mx = rb;
85 cout << " TMatrix<int_4> mx(3,5); mx = rb; mx: " << endl;
86 cout << mx << endl;
87 TArray<r_4> rc(10);
88 rc = 3.1415;
89 TMatrix<r_8> mx2(rc);
90 cout << " TArray<r_4> rc(10) = 3.1415 , TMatrix<r_8> mx2(rc) rc : " << endl;
91 cout << mx2 << endl;
92 TMatrix<int_4> mx3(3,5);
93 cout << " Trying TMatrix<int_4> mx3(3,5); mx3 = rc; ?? " << endl;
94 mx3 = rc;
95 return(0);
96}
97
98int test_oso(int nr, int nc)
99{
100 cout << "\n -----> Testing TArray operation TArray<int_4>(nx=" << nr << ",ny="
101 << nc << " )" << endl;
102
103 int rc = 0;
104 int min,max;
105
106 TArray<int_4> a(nr,nc);
107 a = 20;
108 TArray<int_4> b(nr,nc);
109 b = 9;
110 TArray<int_4> c = a-2*b;
111
112 if (prtlev > 0) {
113 cout << " A = \n " << a << endl;
114 cout << " B = \n " << b << endl;
115 cout << " C = A-2*B= \n " << c << endl;
116 }
117
118 getMinMax(c, min, max);
119 if ((min != 2) || (max != 2)) {
120 cout << "!!! ERROR Test C=A+2*B Min=" << min << " Max=" << max << endl;
121 rc += 1;
122 }
123 else cout << " OK Test C=A+2*B OK " << endl;
124
125 c = (a*4+1).DivElt(b);
126 if (prtlev > 0) cout << " C = (A*4+1)/B = \n" << c << endl;
127 getMinMax(c, min, max);
128 if ((min != 9) || (max != 9)) {
129 cout << "!!! ERROR Test C = (A*4+1)/B Min=" << min << " Max=" << max << endl;
130 rc += 2;
131 }
132 else cout << " OK Test C = (A*4+1)/B OK " << endl;
133
134 return(rc);
135}
136
137int test_odo(int nr, int nc)
138{
139 cout << "\n -----> Testing TMatrix operation TMatrix<r_4>(nr=" << nr << ",nc="
140 << nc << " )" << endl;
141 cout << " A CMemoryMapping - B FortranMemoryMapping " << endl;
142
143 r_4 rc = 0;
144 r_4 min,max;
145
146 TMatrix<r_4> a(nr,nc,BaseArray::CMemoryMapping);
147 a = 20;
148 TMatrix<r_4> b(nr,nc,BaseArray::FortranMemoryMapping);
149 b = 9;
150 TMatrix<r_4> c(nr,nc,BaseArray::CMemoryMapping);
151
152 if (prtlev > 0) {
153 cout << " A = \n " << a << endl;
154 cout << " B = \n " << b << endl;
155 }
156 c = a-(b*2.0f);
157 if (prtlev > 0) cout << " C = A-2*B= \n " << c << endl;
158
159 getMinMax(c, min, max);
160 if ((fabs(min-2.) > 0.0001) || (fabs(max-2.) > 0.0001)) {
161 cout << "!!! ERROR Test C=A+2*B Min=" << min << " Max=" << max << endl;
162 rc += 1;
163 }
164 else cout << " OK Test C=A+2*B OK " << endl;
165
166 c = (a*4.0f+5.5f).DivElt(b);
167 if (prtlev > 0) cout << " C = (A*4+12)/B = \n" << c << endl;
168 getMinMax(c, min, max);
169 if ((fabs(min-9.5) > 0.0001) || (fabs(max-9.5) > 0.0001)) {
170 cout << "!!! ERROR Test C = (A*4+12)/B Min=" << min << " Max=" << max << endl;
171 rc += 2;
172 }
173 else cout << " OK Test C = (A*4+12)/B OK " << endl;
174 return(rc);
175
176}
Note: See TracBrowser for help on using the repository browser.