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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1312 - (show annotations)
Mon Sep 24 06:18:44 2007 UTC (11 years, 10 months ago) by ksteube
File size: 15570 byte(s)
The MPI branch is hereby closed. All future work should be in trunk.

Previously in revision 1295 I merged the latest changes to trunk into trunk-mpi-branch.
In this revision I copied all files from trunk-mpi-branch over the corresponding
trunk files. I did not use 'svn merge', it was a copy.

1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
13 *
14 *******************************************************/
15
16 #include "escript/DataArrayView.h"
17 #include "escript/DataArray.h"
18 #include "esysUtils/EsysException.h"
19
20 #include "DataArrayTestCase.h"
21
22 #include <iostream>
23 #include <vector>
24
25 using namespace CppUnitTest;
26 using namespace esysUtils;
27 using namespace escript;
28 using namespace std;
29
30 void DataArrayTestCase::setUp() {
31 //
32 // This is called before each test is run
33
34 }
35
36 void DataArrayTestCase::tearDown() {
37 //
38 // This is called after each test has been run
39
40 }
41
42 void DataArrayTestCase::testAll() {
43 //
44 // The test code may be entered here
45 // There is nothing special about the function name, it may be renamed to
46 // something more suitable.
47 // As many test methods as desired may be added.
48
49 cout << endl;
50
51 {
52 cout << endl;
53 cout << "\tTest default DataArray constructor - default value." << endl;
54
55 cout << "\tConstruct Default DataArray." << endl;
56 DataArrayView::ShapeType newShape;
57 DataArray newArray;
58 DataArrayView newView = newArray.getView();
59
60 cout << "\tCheck DataArray view shape." << endl;
61 assert(newView.getShape()==newShape);
62 assert(newView.getRank()==0);
63 assert(newView.noValues()==1);
64
65 cout << "\tCheck DataArray data vector values." << endl;
66 DataArrayView::ValueType arrayData = newArray.getData();
67 DataArrayView::ValueType viewData = newView.getData();
68 assert(viewData==arrayData);
69 int noValues = newView.noValues();
70 for (int i=0; i<noValues; i++) {
71 assert(arrayData[i]==0.0);
72 }
73 assert(newView()==0.0);
74 }
75
76 {
77 cout << endl;
78 cout << "\tTest default DataArray constructor - value 5.0." << endl;
79
80 cout << "\tConstruct Default DataArray." << endl;
81 DataArrayView::ShapeType newShape;
82 DataArray newArray(5.0);
83 DataArrayView newView = newArray.getView();
84
85 cout << "\tCheck DataArray view shape." << endl;
86 assert(newView.getShape()==newShape);
87 assert(newView.getRank()==0);
88 assert(newView.noValues()==1);
89
90 cout << "\tCheck DataArray data vector values." << endl;
91 DataArrayView::ValueType arrayData = newArray.getData();
92 DataArrayView::ValueType viewData = newView.getData();
93 assert(viewData==arrayData);
94 int noValues = newView.noValues();
95 for (int i=0; i<noValues; i++) {
96 assert(arrayData[i]==5.0);
97 }
98 assert(newView()==5.0);
99 }
100
101 {
102 cout << endl;
103 cout << "\tTest DataArray shape constructor, shape() - default value." << endl;
104
105 cout << "\tConstruct new DataArray with rank 0 view." << endl;
106 DataArrayView::ShapeType newShape;
107 DataArray newArray(newShape);
108 DataArrayView newView = newArray.getView();
109
110 cout << "\tCheck DataArray view shape." << endl;
111 assert(newView.getShape()==newShape);
112 assert(newView.getRank()==0);
113 assert(newView.noValues()==1);
114
115 cout << "\tCheck DataArray data vector values." << endl;
116 DataArrayView::ValueType arrayData = newArray.getData();
117 DataArrayView::ValueType viewData = newView.getData();
118 assert(viewData==arrayData);
119 int noValues = newView.noValues();
120 for (int i=0; i<noValues; i++) {
121 assert(arrayData[i]==0.0);
122 }
123 assert(newView()==0.0);
124 }
125
126 {
127 cout << endl;
128 cout << "\tTest DataArray shape constructor, shape() - value 5.0." << endl;
129
130 cout << "\tConstruct new DataArray with rank 0 view." << endl;
131 DataArrayView::ShapeType newShape;
132 DataArray newArray(newShape, 5.0);
133 DataArrayView newView = newArray.getView();
134
135 cout << "\tCheck DataArray view shape." << endl;
136 assert(newView.getShape()==newShape);
137 assert(newView.getRank()==0);
138 assert(newView.noValues()==1);
139
140 cout << "\tCheck DataArray data vector values." << endl;
141 DataArrayView::ValueType arrayData = newArray.getData();
142 DataArrayView::ValueType viewData = newView.getData();
143 assert(viewData==arrayData);
144 int noValues = newView.noValues();
145 for (int i=0; i<noValues; i++) {
146 assert(arrayData[i]==5.0);
147 }
148 assert(newView()==5.0);
149 }
150
151 {
152 cout << endl;
153 cout << "\tTest DataArray shape constructor, shape(5)." << endl;
154
155 cout << "\tConstruct new DataArray with rank 1 view." << endl;
156 DataArrayView::ShapeType newShape;
157 newShape.push_back(5);
158 DataArray newArray(newShape);
159 DataArrayView newView = newArray.getView();
160
161 cout << "\tCheck DataArray view shape." << endl;
162 assert(newView.getShape()==newShape);
163 assert(newView.getRank()==1);
164 assert(newView.noValues()==5);
165
166 cout << "\tCheck DataArray data vector values." << endl;
167 DataArrayView::ValueType::size_type index;
168 DataArrayView::ValueType arrayData = newArray.getData();
169 DataArrayView::ValueType viewData = newView.getData();
170 assert(viewData==arrayData);
171 for (int i=0; i<newShape[0]; i++) {
172 index=newView.index(i);
173 assert(arrayData[index]==0.0);
174 assert(newView(i)==0.0);
175 }
176 }
177
178 {
179 cout << endl;
180 cout << "\tTest DataArray shape constructor, shape(2,3)." << endl;
181
182 cout << "\tConstruct new DataArray with rank 2 view." << endl;
183 DataArrayView::ShapeType newShape;
184 newShape.push_back(2);
185 newShape.push_back(3);
186 DataArray newArray(newShape);
187 DataArrayView newView = newArray.getView();
188
189 cout << "\tCheck DataArray view shape." << endl;
190 assert(newView.getShape()==newShape);
191 assert(newView.getRank()==2);
192 assert(newView.noValues()==6);
193
194 cout << "\tCheck DataArray data vector values." << endl;
195 DataArrayView::ValueType::size_type index;
196 DataArrayView::ValueType arrayData = newArray.getData();
197 DataArrayView::ValueType viewData = newView.getData();
198 assert(viewData==arrayData);
199 for (int i=0; i<newShape[0]; i++) {
200 for (int j=0; j<newShape[1]; j++) {
201 index=newView.index(i,j);
202 assert(arrayData[index]==0.0);
203 assert(newView(i,j)==0.0);
204 }
205 }
206 }
207
208 {
209 cout << endl;
210 cout << "\tTest DataArray shape constructor, shape(2,3,4)." << endl;
211
212 cout << "\tConstruct new DataArray with rank 3 view." << endl;
213 DataArrayView::ShapeType newShape;
214 newShape.push_back(2);
215 newShape.push_back(3);
216 newShape.push_back(4);
217 DataArray newArray(newShape);
218 DataArrayView newView = newArray.getView();
219
220 cout << "\tCheck DataArray view shape." << endl;
221 assert(newView.getShape()==newShape);
222 assert(newView.getRank()==3);
223 assert(newView.noValues()==24);
224
225 cout << "\tCheck DataArray data vector values." << endl;
226 DataArrayView::ValueType::size_type index;
227 DataArrayView::ValueType viewData = newView.getData();
228 DataArrayView::ValueType arrayData = newArray.getData();
229 assert(viewData==arrayData);
230 for (int i=0; i<newShape[0]; i++) {
231 for (int j=0; j<newShape[1]; j++) {
232 for (int k=0; k<newShape[2]; k++) {
233 index=newView.index(i,j,k);
234 assert(arrayData[index]==0.0);
235 assert(newView(i,j,k)==0.0);
236 }
237 }
238 }
239 }
240
241 {
242 cout << endl;
243 cout << "\tTest DataArray shape constructor, shape(2,3,4,7)." << endl;
244
245 cout << "\tConstruct new DataArray with rank 4 view." << endl;
246 DataArrayView::ShapeType newShape;
247 newShape.push_back(2);
248 newShape.push_back(3);
249 newShape.push_back(4);
250 newShape.push_back(7);
251 DataArray newArray(newShape);
252 DataArrayView newView = newArray.getView();
253
254 cout << "\tCheck DataArray view shape." << endl;
255 assert(newView.getShape()==newShape);
256 assert(newView.getRank()==4);
257 assert(newView.noValues()==168);
258
259 cout << "\tCheck DataArray data vector values." << endl;
260 DataArrayView::ValueType::size_type index;
261 DataArrayView::ValueType viewData = newView.getData();
262 DataArrayView::ValueType arrayData = newArray.getData();
263 assert(viewData==arrayData);
264 for (int i=0; i<newShape[0]; i++) {
265 for (int j=0; j<newShape[1]; j++) {
266 for (int k=0; k<newShape[2]; k++) {
267 for (int l=0; l<newShape[3]; l++) {
268 index=newView.index(i,j,k,l);
269 assert(arrayData[index]==0.0);
270 assert(newView(i,j,k,l)==0.0);
271 }
272 }
273 }
274 }
275 }
276
277 {
278 cout << endl;
279 cout << "\tTest DataArray copy constructor, default DataArray." << endl;
280
281 cout << "\tConstruct Default DataArray." << endl;
282 DataArray oldArray;
283
284 cout << "\tCopy Default DataArray." << endl;
285 DataArrayView::ShapeType newShape;
286 DataArray newArray(oldArray);
287 DataArrayView newView = newArray.getView();
288
289 cout << "\tCheck DataArray view shape." << endl;
290 assert(newView.getShape()==newShape);
291 assert(newView.getRank()==0);
292 assert(newView.noValues()==1);
293
294 cout << "\tCheck DataArray data vector values." << endl;
295 DataArrayView::ValueType arrayData = newArray.getData();
296 DataArrayView::ValueType viewData = newView.getData();
297 assert(viewData==arrayData);
298 assert(arrayData[0]==0.0);
299 assert(newView()==0.0);
300 }
301
302 {
303 cout << endl;
304 cout << "\tTest DataArray copy constructor, shape(2,3)." << endl;
305
306 cout << "\tConstruct new DataArray with rank 2 view." << endl;
307 DataArrayView::ShapeType oldShape;
308 oldShape.push_back(2);
309 oldShape.push_back(3);
310 DataArray oldArray(oldShape);
311
312 cout << "\tCopy rank 2 DataArray." << endl;
313 DataArrayView::ShapeType newShape = oldShape;
314 DataArray newArray(oldArray);
315 DataArrayView newView = newArray.getView();
316
317 cout << "\tCheck DataArray view shape." << endl;
318 assert(newView.getShape()==newShape);
319 assert(newView.getRank()==2);
320 assert(newView.noValues()==6);
321
322 cout << "\tCheck DataArray data vector values." << endl;
323 DataArrayView::ValueType::size_type index;
324 DataArrayView::ValueType viewData = newView.getData();
325 DataArrayView::ValueType arrayData = newArray.getData();
326 assert(viewData==arrayData);
327 for (int i=0; i<newShape[0]; i++) {
328 for (int j=0; j<newShape[1]; j++) {
329 index=newView.index(i,j);
330 assert(arrayData[index]==0.0);
331 assert(newView(i,j)==0.0);
332 }
333 }
334 }
335
336 {
337 cout << endl;
338 cout << "\tTest DataArray copy constructor, shape(2,3,4,7)." << endl;
339
340 cout << "\tConstruct new DataArray with rank 4 view." << endl;
341 DataArrayView::ShapeType oldShape;
342 oldShape.push_back(2);
343 oldShape.push_back(3);
344 oldShape.push_back(4);
345 oldShape.push_back(7);
346 DataArray oldArray(oldShape);
347
348 cout << "\tCopy rank 4 DataArray." << endl;
349 DataArrayView::ShapeType newShape = oldShape;
350 DataArray newArray(oldArray);
351 DataArrayView newView = newArray.getView();
352
353 cout << "\tCheck DataArray view shape." << endl;
354 assert(newView.getShape()==newShape);
355 assert(newView.getRank()==4);
356 assert(newView.noValues()==168);
357
358 cout << "\tCheck DataArray data vector values." << endl;
359 DataArrayView::ValueType::size_type index;
360 DataArrayView::ValueType viewData = newView.getData();
361 DataArrayView::ValueType arrayData = newArray.getData();
362 assert(viewData==arrayData);
363 for (int i=0; i<newShape[0]; i++) {
364 for (int j=0; j<newShape[1]; j++) {
365 for (int k=0; k<newShape[2]; k++) {
366 for (int l=0; l<newShape[3]; l++) {
367 index=newView.index(i,j,k,l);
368 assert(arrayData[index]==0.0);
369 assert(newView(i,j,k,l)==0.0);
370 }
371 }
372 }
373 }
374 }
375
376 {
377 cout << endl;
378 cout << "\tTest DataArray DataArrayView constructor, default DataArray." << endl;
379
380 cout << "\tConstruct Default DataArray." << endl;
381 DataArray oldArray;
382
383 cout << "\tExtract Default DataArray DataArrayView." << endl;
384 DataArrayView oldView = oldArray.getView();
385
386 cout << "\tCopy Default DataArray from DataArrayView." << endl;
387 DataArrayView::ShapeType newShape;
388 DataArray newArray(oldView);
389 DataArrayView newView = newArray.getView();
390
391 cout << "\tCheck DataArray view shape." << endl;
392 assert(newView.getShape()==newShape);
393 assert(newView.getRank()==0);
394 assert(newView.noValues()==1);
395
396 cout << "\tCheck DataArray data vector values." << endl;
397 DataArrayView::ValueType arrayData = newArray.getData();
398 DataArrayView::ValueType viewData = newView.getData();
399 assert(viewData==arrayData);
400 assert(arrayData[0]==0.0);
401 assert(newView()==0.0);
402 }
403
404 {
405 cout << endl;
406 cout << "\tTest DataArray DataArrayView constructor, shape(2,3)." << endl;
407
408 cout << "\tConstruct new DataArray with rank 2 view." << endl;
409 DataArrayView::ShapeType oldShape;
410 oldShape.push_back(2);
411 oldShape.push_back(3);
412 DataArray oldArray(oldShape);
413
414 cout << "\tExtract rank 2 DataArray DataArrayView." << endl;
415 DataArrayView oldView = oldArray.getView();
416
417 cout << "\tCopy rank 2 DataArray from DataArrayView." << endl;
418 DataArrayView::ShapeType newShape = oldShape;
419 DataArray newArray(oldView);
420 DataArrayView newView = newArray.getView();
421
422 cout << "\tCheck DataArray view shape." << endl;
423 assert(newView.getShape()==newShape);
424 assert(newView.getRank()==2);
425 assert(newView.noValues()==6);
426
427 cout << "\tCheck DataArray data vector values." << endl;
428 DataArrayView::ValueType::size_type index;
429 DataArrayView::ValueType viewData = newView.getData();
430 DataArrayView::ValueType arrayData = newArray.getData();
431 assert(viewData==arrayData);
432 for (int i=0; i<newShape[0]; i++) {
433 for (int j=0; j<newShape[1]; j++) {
434 index=newView.index(i,j);
435 assert(arrayData[index]==0.0);
436 assert(newView(i,j)==0.0);
437 }
438 }
439 }
440
441 {
442 cout << endl;
443 cout << "\tTest DataArray DataArrayView constructor, shape(2,3,4,7)." << endl;
444
445 cout << "\tConstruct new DataArray with rank 4 view." << endl;
446 DataArrayView::ShapeType oldShape;
447 oldShape.push_back(2);
448 oldShape.push_back(3);
449 oldShape.push_back(4);
450 oldShape.push_back(7);
451 DataArray oldArray(oldShape);
452
453 cout << "\tExtract rank 4 DataArray DataArrayView." << endl;
454 DataArrayView oldView = oldArray.getView();
455
456 cout << "\tCopy rank 4 DataArray from DataArrayView." << endl;
457 DataArrayView::ShapeType newShape = oldShape;
458 DataArray newArray(oldView);
459 DataArrayView newView = newArray.getView();
460
461 cout << "\tCheck DataArray view shape." << endl;
462 assert(newView.getShape()==newShape);
463 assert(newView.getRank()==4);
464 assert(newView.noValues()==168);
465
466 cout << "\tCheck DataArray data vector values." << endl;
467 DataArrayView::ValueType::size_type index;
468 DataArrayView::ValueType viewData = newView.getData();
469 DataArrayView::ValueType arrayData = newArray.getData();
470 assert(viewData==arrayData);
471 for (int i=0; i<newShape[0]; i++) {
472 for (int j=0; j<newShape[1]; j++) {
473 for (int k=0; k<newShape[2]; k++) {
474 for (int l=0; l<newShape[3]; l++) {
475 index=newView.index(i,j,k,l);
476 assert(arrayData[index]==0.0);
477 assert(newView(i,j,k,l)==0.0);
478 }
479 }
480 }
481 }
482 }
483
484 }
485
486 TestSuite* DataArrayTestCase::suite ()
487 {
488 //
489 // create the suite of tests to perform.
490 TestSuite *testSuite = new TestSuite ("DataArrayTestCase");
491
492 testSuite->addTest (new TestCaller< DataArrayTestCase>("testAll",&DataArrayTestCase::testAll));
493 return testSuite;
494 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26