/[escript]/trunk/escript/test/DataArrayTestCase.cpp
ViewVC logotype

Contents of /trunk/escript/test/DataArrayTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 104 - (show annotations)
Fri Dec 17 07:43:12 2004 UTC (14 years, 9 months ago) by jgs
Original Path: trunk/esys2/escript/test/DataArray/DataArrayTestCase.cpp
File size: 11399 byte(s)
*** empty log message ***

1 /*
2 *****************************************************************************
3 * *
4 * COPYRIGHT ACcESS - All Rights Reserved *
5 * *
6 * This software is the property of ACcESS. No part of this code *
7 * may be copied in any form or by any means without the expressed written *
8 * consent of ACcESS. Copying, use or modification of this software *
9 * by any unauthorised person is illegal unless that person has a software *
10 * license agreement with ACcESS. *
11 * *
12 *****************************************************************************
13 */
14 #include "escript/Data/DataArrayView.h"
15 #include "escript/Data/DataArray.h"
16 #include "DataArrayTestCase.h"
17 #include "esysUtils/EsysException.h"
18
19 #include <iostream>
20 #include <vector>
21
22 using namespace CppUnitTest;
23 using namespace esysUtils;
24 using namespace escript;
25 using namespace std;
26
27 void DataArrayTestCase::setUp() {
28 //
29 // This is called before each test is run
30
31 }
32
33 void DataArrayTestCase::tearDown() {
34 //
35 // This is called after each test has been run
36
37 }
38
39 void DataArrayTestCase::testAll() {
40 //
41 // The test code may be entered here
42 // There is nothing special about the function name, it may be renamed to
43 // something more suitable.
44 // As many test methods as desired may be added.
45
46 cout << endl;
47
48 {
49 cout << endl;
50 cout << "\tTest default DataArray constructor." << endl;
51
52 cout << "\tConstruct Default DataArray." << endl;
53 DataArray newArray;
54 DataArrayView newView = newArray.getView();
55 DataArrayView::ShapeType newShape = newView.getShape();
56
57 cout << "\tCheck DataArray shape." << endl;
58 assert(newView.getShape()==newShape);
59 assert(newView.getRank()==0);
60 assert(newView.noValues()==1);
61
62 cout << "\tCheck DataArray data values." << endl;
63 DataArrayView::ValueType arrayData = newArray.getData();
64 DataArrayView::ValueType viewData = newView.getData();
65 assert(viewData==arrayData);
66 assert(arrayData[0]==0.0);
67 assert(newView()==0.0);
68 }
69
70 {
71 cout << endl;
72 cout << "\tTest DataArray shape constructor, shape()." << endl;
73
74 cout << "\tConstruct new DataArray, rank 0." << endl;
75 DataArrayView::ShapeType newShape;
76 DataArray newArray(newShape);
77 DataArrayView newView = newArray.getView();
78
79 cout << "\tCheck DataArray shape." << endl;
80 assert(newView.getShape()==newShape);
81 assert(newView.getRank()==0);
82 assert(newView.noValues()==1);
83
84 cout << "\tCheck DataArray data values." << endl;
85 DataArrayView::ValueType arrayData = newArray.getData();
86 DataArrayView::ValueType viewData = newView.getData();
87 assert(viewData==arrayData);
88 assert(arrayData[0]==0.0);
89 assert(newView()==0.0);
90 }
91
92 {
93 cout << endl;
94 cout << "\tTest DataArray shape constructor, shape(5)." << endl;
95
96 cout << "\tConstruct new DataArray, rank 1." << endl;
97 DataArrayView::ShapeType newShape;
98 newShape.push_back(5);
99 DataArray newArray(newShape);
100 DataArrayView newView = newArray.getView();
101
102 cout << "\tCheck DataArray shape." << endl;
103 assert(newView.getShape()==newShape);
104 assert(newView.getRank()==1);
105 assert(newView.noValues()==5);
106
107 cout << "\tCheck DataArray data values." << endl;
108 DataArrayView::ValueType::size_type index;
109 DataArrayView::ValueType arrayData = newArray.getData();
110 DataArrayView::ValueType viewData = newView.getData();
111 assert(viewData==arrayData);
112 for (int i=0;i<newShape[0];++i) {
113 index=newView.index(i);
114 assert(arrayData[index]==0.0);
115 assert(arrayData[index]==newView(i));
116 }
117 }
118
119 {
120 cout << endl;
121 cout << "\tTest DataArray shape constructor, shape(2,3)." << endl;
122
123 cout << "\tConstruct new DataArray, rank 2." << endl;
124 DataArrayView::ShapeType newShape;
125 newShape.push_back(2);
126 newShape.push_back(3);
127 DataArray newArray(newShape);
128 DataArrayView newView = newArray.getView();
129
130 cout << "\tCheck DataArray shape." << endl;
131 assert(newView.getShape()==newShape);
132 assert(newView.getRank()==2);
133 assert(newView.noValues()==6);
134
135 DataArrayView::ValueType::size_type index;
136 DataArrayView::ValueType viewData = newView.getData();
137 DataArrayView::ValueType arrayData = newArray.getData();
138
139 cout << "\tCheck DataArray data values." << endl;
140 assert(viewData==arrayData);
141 for (int i=0;i<newShape[0];++i) {
142 for (int j=0;j<newShape[1];++j) {
143 index=newView.index(i,j);
144 assert(arrayData[index]==0.0);
145 assert(arrayData[index]==newView(i,j));
146 }
147 }
148 }
149
150 {
151 cout << endl;
152 cout << "\tTest DataArray shape constructor, shape(2,3,4)." << endl;
153
154 cout << "\tConstruct new DataArray, rank 3." << endl;
155 DataArrayView::ShapeType newShape;
156 newShape.push_back(2);
157 newShape.push_back(3);
158 newShape.push_back(4);
159 DataArray newArray(newShape);
160 DataArrayView newView = newArray.getView();
161
162 cout << "\tCheck DataArray shape." << endl;
163 assert(newView.getShape()==newShape);
164 assert(newView.getRank()==3);
165 assert(newView.noValues()==24);
166
167 DataArrayView::ValueType::size_type index;
168 DataArrayView::ValueType viewData = newView.getData();
169 DataArrayView::ValueType arrayData = newArray.getData();
170
171 cout << "\tCheck DataArray data values." << endl;
172 assert(viewData==arrayData);
173 for (int i=0;i<newShape[0];++i) {
174 for (int j=0;j<newShape[1];++j) {
175 for (int k=0;k<newShape[2];++k) {
176 index=newView.index(i,j,k);
177 assert(arrayData[index]==0.0);
178 assert(arrayData[index]==newView(i,j,k));
179 }
180 }
181 }
182 }
183
184 {
185 cout << endl;
186 cout << "\tTest DataArray shape constructor, shape(2,3,4,7)." << endl;
187
188 cout << "\tConstruct new DataArray, rank 4." << endl;
189 DataArrayView::ShapeType newShape;
190 newShape.push_back(2);
191 newShape.push_back(3);
192 newShape.push_back(4);
193 newShape.push_back(7);
194 DataArray newArray(newShape);
195 DataArrayView newView = newArray.getView();
196
197 cout << "\tCheck DataArray shape." << endl;
198 assert(newView.getShape()==newShape);
199 assert(newView.getRank()==4);
200 assert(newView.noValues()==168);
201
202 DataArrayView::ValueType::size_type index;
203 DataArrayView::ValueType viewData = newView.getData();
204 DataArrayView::ValueType arrayData = newArray.getData();
205
206 cout << "\tCheck DataArray data values." << endl;
207 assert(viewData==arrayData);
208 for (int i=0;i<newShape[0];++i) {
209 for (int j=0;j<newShape[1];++j) {
210 for (int k=0;k<newShape[2];++k) {
211 for (int l=0;l<newShape[3];++l) {
212 index=newView.index(i,j,k,l);
213 assert(arrayData[index]==0.0);
214 assert(arrayData[index]==newView(i,j,k,l));
215 }
216 }
217 }
218 }
219 }
220
221 {
222 cout << endl;
223 cout << "\tTest DataArray copy constructor, default DataArray." << endl;
224
225 cout << "\tConstruct Default DataArray." << endl;
226 DataArray oldArray;
227
228 cout << "\tCopy Default DataArray." << endl;
229 DataArray newArray(oldArray);
230 DataArrayView newView = newArray.getView();
231 DataArrayView::ShapeType newShape = newView.getShape();
232
233 cout << "\tCheck DataArray shape." << endl;
234 assert(newView.getShape()==newShape);
235 assert(newView.getRank()==0);
236 assert(newView.noValues()==1);
237
238 cout << "\tCheck DataArray data values." << endl;
239 DataArrayView::ValueType arrayData = newArray.getData();
240 DataArrayView::ValueType viewData = newView.getData();
241 assert(viewData==arrayData);
242 assert(arrayData[0]==0.0);
243 assert(newView()==0.0);
244 }
245
246 {
247 cout << endl;
248 cout << "\tTest DataArray copy constructor, shape(2,3)." << endl;
249
250 cout << "\tConstruct new DataArray, rank 2." << endl;
251 DataArrayView::ShapeType oldShape;
252 oldShape.push_back(2);
253 oldShape.push_back(3);
254 DataArray oldArray(oldShape);
255
256 cout << "\tCopy rank 2 DataArray." << endl;
257 DataArray newArray(oldArray);
258 DataArrayView newView = newArray.getView();
259 DataArrayView::ShapeType newShape = newView.getShape();
260
261 cout << "\tCheck DataArray shape." << endl;
262 assert(newShape==oldShape);
263 assert(newView.getRank()==2);
264 assert(newView.noValues()==6);
265
266 DataArrayView::ValueType::size_type index;
267 DataArrayView::ValueType viewData = newView.getData();
268 DataArrayView::ValueType arrayData = newArray.getData();
269
270 cout << "\tCheck DataArray data values." << endl;
271 assert(viewData==arrayData);
272 for (int i=0;i<newShape[0];++i) {
273 for (int j=0;j<newShape[1];++j) {
274 index=newView.index(i,j);
275 assert(arrayData[index]==0.0);
276 assert(arrayData[index]==newView(i,j));
277 }
278 }
279 }
280
281 {
282 cout << endl;
283 cout << "\tTest DataArray DataArrayView constructor, default DataArray." << endl;
284
285 cout << "\tConstruct Default DataArray." << endl;
286 DataArray oldArray;
287
288 cout << "\tExtract Default DataArray DataArrayView." << endl;
289 DataArrayView oldView = oldArray.getView();
290
291 cout << "\tCopy Default DataArray from DataArrayView." << endl;
292 DataArray newArray(oldView);
293 DataArrayView newView = newArray.getView();
294 DataArrayView::ShapeType newShape = newView.getShape();
295
296 cout << "\tCheck DataArray shape." << endl;
297 assert(newView.getShape()==newShape);
298 assert(newView.getRank()==0);
299 assert(newView.noValues()==1);
300
301 cout << "\tCheck DataArray data values." << endl;
302 DataArrayView::ValueType arrayData = newArray.getData();
303 DataArrayView::ValueType viewData = newView.getData();
304 assert(viewData==arrayData);
305 assert(arrayData[0]==0.0);
306 assert(newView()==0.0);
307 }
308
309 {
310 cout << endl;
311 cout << "\tTest DataArray DataArrayView constructor, shape(2,3)." << endl;
312
313 cout << "\tConstruct new DataArray, rank 2." << endl;
314 DataArrayView::ShapeType oldShape;
315 oldShape.push_back(2);
316 oldShape.push_back(3);
317 DataArray oldArray(oldShape);
318
319 cout << "\tExtract rank2 DataArray DataArrayView." << endl;
320 DataArrayView oldView = oldArray.getView();
321
322 cout << "\tCopy rank 2 DataArray from DataArrayView." << endl;
323 DataArray newArray(oldView);
324 DataArrayView newView = newArray.getView();
325 DataArrayView::ShapeType newShape = newView.getShape();
326
327 cout << "\tCheck DataArray shape." << endl;
328 assert(newShape==oldShape);
329 assert(newView.getRank()==2);
330 assert(newView.noValues()==6);
331
332 DataArrayView::ValueType::size_type index;
333 DataArrayView::ValueType viewData = newView.getData();
334 DataArrayView::ValueType arrayData = newArray.getData();
335
336 cout << "\tCheck DataArray data values." << endl;
337 assert(viewData==arrayData);
338 for (int i=0;i<newShape[0];++i) {
339 for (int j=0;j<newShape[1];++j) {
340 index=newView.index(i,j);
341 assert(arrayData[index]==0.0);
342 assert(arrayData[index]==newView(i,j));
343 }
344 }
345 }
346
347 }
348
349 TestSuite* DataArrayTestCase::suite ()
350 {
351 //
352 // create the suite of tests to perform.
353 TestSuite *testSuite = new TestSuite ("DataArrayTestCase");
354
355 testSuite->addTest (new TestCaller< DataArrayTestCase>("testAll",&DataArrayTestCase::testAll));
356 return testSuite;
357 }
358

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26