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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 682 - (hide annotations)
Mon Mar 27 02:43:09 2006 UTC (13 years, 5 months ago) by robwdcock
File size: 16006 byte(s)
+ NEW BUILD SYSTEM

This commit contains the new build system with cross-platform support.
Most things work are before though you can have more control.

ENVIRONMENT settings have changed:
+ You no longer require LD_LIBRARY_PATH or PYTHONPATH to point to the
esysroot for building and testing performed via scons
+ ACcESS altix users: It is recommended you change your modules to load
the latest intel compiler and other libraries required by boost to match
the setup in svn (you can override). The correct modules are as follows

module load intel_cc.9.0.026
export
MODULEPATH=${MODULEPATH}:/data/raid2/toolspp4/modulefiles/gcc-3.3.6
module load boost/1.33.0/python-2.4.1
module load python/2.4.1
module load numarray/1.3.3


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26