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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 682 - (hide annotations)
Mon Mar 27 02:43:09 2006 UTC (13 years, 3 months ago) by robwdcock
File size: 28319 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 82 // $Id$
2     /*
3     *****************************************************************************
4     * *
5     * COPYRIGHT ACcESS - All Rights Reserved *
6     * *
7     * This software is the property of ACcESS. No part of this code *
8     * may be copied in any form or by any means without the expressed written *
9     * consent of ACcESS. Copying, use or modification of this software *
10     * by any unauthorised person is illegal unless that person has a software *
11     * license agreement with ACcESS. *
12     * *
13     *****************************************************************************
14     */
15 jgs 511
16     #include "DataTestCase.h"
17    
18 robwdcock 670 #include "escript/FunctionSpace.h"
19 robwdcock 638 #include "esysUtils/EsysException.h"
20 jgs 82
21 robwdcock 670 #include "escript/Data.h"
22 jgs 537
23 jgs 82 #include <iostream>
24 jgs 113 #include <math.h>
25 jgs 82
26     using namespace std;
27     using namespace CppUnitTest;
28     using namespace escript;
29     using namespace esysUtils;
30    
31     void DataTestCase::setUp() {
32     //
33     // This is called before each test is run
34     }
35    
36     void DataTestCase::tearDown() {
37     //
38     // This is called after each test has been run
39     }
40    
41     void DataTestCase::testSlicing() {
42    
43     cout << endl;
44    
45     {
46 jgs 537
47     cout << "\tTest get-slicing DataConstant" << endl;
48    
49 jgs 82 DataArrayView::ShapeType viewShape;
50     viewShape.push_back(2);
51     viewShape.push_back(3);
52 jgs 537 Data data(1.3,viewShape,FunctionSpace(),false);
53    
54     //cout << data.toString() << endl;
55    
56 jgs 82 DataArrayView::RegionType region;
57     region.push_back(DataArrayView::RegionType::value_type(0,0));
58     region.push_back(DataArrayView::RegionType::value_type(0,0));
59 jgs 537
60     Data slice1(data.getSlice(region));
61    
62     //cout << slice1.toString() << endl;
63    
64     assert(slice1.getDataPointRank()==0);
65     assert(slice1.getDataPoint(0,0)()==1.3);
66    
67 jgs 82 region.clear();
68     region.push_back(DataArrayView::RegionType::value_type(0,1));
69     region.push_back(DataArrayView::RegionType::value_type(0,1));
70 jgs 537
71     Data slice2(data.getSlice(region));
72    
73     //cout << slice2.toString() << endl;
74    
75     assert(slice2.getDataPointRank()==2);
76     assert(slice2.getDataPoint(0,0)(0,0)==1.3);
77    
78     region.clear();
79     region.push_back(DataArrayView::RegionType::value_type(0,1));
80     region.push_back(DataArrayView::RegionType::value_type(0,2));
81    
82     Data slice3(data.getSlice(region));
83    
84     //cout << slice3.toString() << endl;
85    
86     assert(slice3.getDataPointRank()==2);
87     assert(slice3.getDataPoint(0,0)(0,0)==1.3);
88     assert(slice3.getDataPoint(0,0)(0,1)==1.3);
89    
90 jgs 82 }
91    
92     {
93 jgs 537
94     cout << "\tTest set-slicing DataConstant" << endl;
95    
96 jgs 82 DataArrayView::ShapeType viewShape;
97 jgs 537 Data source(10.0,viewShape,FunctionSpace(),false);
98    
99     //cout << source.toString() << endl;
100    
101     viewShape.push_back(2);
102     viewShape.push_back(3);
103     Data target(1.3,viewShape,FunctionSpace(),false);
104    
105     //cout << target.toString() << endl;
106    
107     DataArrayView::RegionType region;
108     region.push_back(DataArrayView::RegionType::value_type(0,0));
109     region.push_back(DataArrayView::RegionType::value_type(0,0));
110    
111     target.setSlice(source,region);
112    
113     //cout << target.toString() << endl;
114    
115     assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)());
116    
117     }
118    
119     {
120    
121     cout << "\tTest get-slicing DataTagged" << endl;
122    
123 jgs 82 //
124 jgs 537 // create a DataTagged with a default value only
125    
126     DataArrayView::ShapeType viewShape;
127 jgs 82 viewShape.push_back(2);
128     viewShape.push_back(3);
129 jgs 537 Data data(1.3,viewShape,FunctionSpace(),false);
130     data.tag();
131     data.getDataPoint(0,0)(0,0)=1.0;
132     data.getDataPoint(0,0)(1,1)=2.0;
133    
134     //cout << data.toString() << endl;
135    
136     //
137     // create a scalar slice
138    
139 jgs 82 DataArrayView::RegionType region;
140     region.push_back(DataArrayView::RegionType::value_type(0,0));
141     region.push_back(DataArrayView::RegionType::value_type(0,0));
142 jgs 537
143     Data slice1(data.getSlice(region));
144    
145     //cout << slice1.toString() << endl;
146    
147     assert(slice1.isTagged());
148     assert(slice1.getDataPointRank()==0);
149     assert(slice1.getDataPoint(0,0)()==1.0);
150    
151 jgs 82 //
152 jgs 537 // create a rank 2 slice with one value
153    
154 jgs 82 region.clear();
155     region.push_back(DataArrayView::RegionType::value_type(0,1));
156     region.push_back(DataArrayView::RegionType::value_type(0,1));
157 jgs 537
158     Data slice2(data.getSlice(region));
159    
160     //cout << slice2.toString() << endl;
161    
162     assert(slice2.isTagged());
163     assert(slice2.getDataPointRank()==2);
164     assert(slice2.getDataPoint(0,0)(0,0)==1.0);
165    
166     //
167     // create a rank 2 slice with four values
168    
169 jgs 82 region.clear();
170     region.push_back(DataArrayView::RegionType::value_type(0,2));
171     region.push_back(DataArrayView::RegionType::value_type(0,2));
172 jgs 537
173     Data slice3(data.getSlice(region));
174    
175     //cout << slice3.toString() << endl;
176    
177     assert(slice3.isTagged());
178     assert(slice3.getDataPointRank()==2);
179     assert(slice3.getDataPoint(0,0)(0,0)==1.0);
180     assert(slice3.getDataPoint(0,0)(0,1)==1.3);
181     assert(slice3.getDataPoint(0,0)(1,0)==1.3);
182     assert(slice3.getDataPoint(0,0)(1,1)==2.0);
183    
184     //
185     // add a value for tag "1"
186    
187     DataArrayView::ValueType viewData(6);
188     for (int i=0;i<viewData.size();i++) {
189     viewData[i]=i;
190     }
191     DataArrayView dataView(viewData,viewShape);
192    
193     data.setTaggedValueFromCPP(1, dataView);
194    
195     //
196     // create a full slice
197    
198     region.clear();
199     region.push_back(DataArrayView::RegionType::value_type(0,2));
200     region.push_back(DataArrayView::RegionType::value_type(0,3));
201    
202     Data slice4(data.getSlice(region));
203    
204     //cout << slice4.toString() << endl;
205    
206     assert(slice4.isTagged());
207     assert(slice4.getDataPointRank()==2);
208     assert(slice4.getDataPoint(0,0)(0,0)==0);
209     assert(slice4.getDataPoint(0,0)(0,1)==2);
210     assert(slice4.getDataPoint(0,0)(0,2)==4);
211     assert(slice4.getDataPoint(0,0)(1,0)==1);
212     assert(slice4.getDataPoint(0,0)(1,1)==3);
213     assert(slice4.getDataPoint(0,0)(1,2)==5);
214    
215 jgs 82 }
216    
217     {
218 jgs 537
219     cout << "\tTest set-slicing DataTagged" << endl;
220    
221     //
222 jgs 549 // create a source DataTagged with a scalar default value only
223 jgs 537
224 jgs 82 DataArrayView::ShapeType viewShape;
225 jgs 537 Data source(10.0,viewShape,FunctionSpace(),false);
226     source.tag();
227    
228 jgs 549 //cout << "source:\n" << source.toString() << endl;
229 jgs 537
230 jgs 82 //
231 jgs 549 // create a target DataTagged with a rank 2 default value only
232 jgs 537
233 jgs 82 viewShape.push_back(2);
234     viewShape.push_back(3);
235 jgs 537 Data target(1.3,viewShape,FunctionSpace(),false);
236     target.tag();
237    
238 jgs 549 //cout << "target:\n" << target.toString() << endl;
239 jgs 537
240 jgs 82 //
241 jgs 537 // set a slice in target from source
242    
243     DataArrayView::RegionType region;
244     region.push_back(DataArrayView::RegionType::value_type(1,1));
245     region.push_back(DataArrayView::RegionType::value_type(1,1));
246    
247     target.setSlice(source,region);
248    
249 jgs 549 //cout << "target:\n" << target.toString() << endl;
250 jgs 537
251     assert(target.isTagged());
252     assert(target.getDataPointRank()==2);
253     assert(target.getDataPoint(0,0)(0,0)==1.3);
254     assert(target.getDataPoint(0,0)(0,1)==1.3);
255     assert(target.getDataPoint(0,0)(0,2)==1.3);
256     assert(target.getDataPoint(0,0)(1,0)==1.3);
257     assert(target.getDataPoint(0,0)(1,1)==source.getDataPoint(0,0)());
258     assert(target.getDataPoint(0,0)(1,2)==1.3);
259    
260     //
261 jgs 549 // add a value for tag "1" to target
262 jgs 537
263     DataArrayView::ValueType viewData(6);
264     for (int i=0;i<viewData.size();i++) {
265     viewData[i]=i;
266     }
267     DataArrayView dataView(viewData,viewShape);
268    
269     target.setTaggedValueFromCPP(1, dataView);
270    
271 jgs 549 //cout << "target:\n" << target.toString() << endl;
272    
273 jgs 537 //
274     // set a slice in target from source
275    
276     region.clear();
277     region.push_back(DataArrayView::RegionType::value_type(0,0));
278     region.push_back(DataArrayView::RegionType::value_type(1,1));
279    
280     target.setSlice(source,region);
281    
282 jgs 549 //cout << "target:\n" << target.toString() << endl;
283 jgs 537
284     assert(target.isTagged());
285     assert(target.getDataPointRank()==2);
286     assert(target.getDataPoint(0,0)(0,0)==0);
287     assert(target.getDataPoint(0,0)(0,1)==source.getDataPoint(0,0)());
288     assert(target.getDataPoint(0,0)(0,2)==4);
289     assert(target.getDataPoint(0,0)(1,0)==1);
290     assert(target.getDataPoint(0,0)(1,1)==3);
291     assert(target.getDataPoint(0,0)(1,2)==5);
292    
293 jgs 549 //
294     // add a value for tag "2" to source
295    
296     DataArrayView::ShapeType viewShape2;
297     DataArrayView::ValueType viewData2(1);
298     viewData2[0]=6;
299     DataArrayView dataView2(viewData2,viewShape2);
300    
301     source.setTaggedValueFromCPP(2, dataView2);
302    
303     //cout << "source:\n" << source.toString() << endl;
304    
305     //
306     // set a slice in target from source
307    
308     region.clear();
309     region.push_back(DataArrayView::RegionType::value_type(0,0));
310     region.push_back(DataArrayView::RegionType::value_type(1,1));
311    
312     target.setSlice(source,region);
313    
314     //cout << "target:\n" << target.toString() << endl;
315    
316     assert(target.isTagged());
317     assert(target.getDataPointRank()==2);
318    
319     // use a non-existant tag so we get a pointer to the default value
320     // ie: the first element in the data array
321     DataAbstract::ValueType::value_type* targetData=target.getSampleDataByTag(9);
322     for (int i=0; i<target.getLength(); i++) {
323     assert(targetData[i]>=0);
324     }
325     assert(targetData[0]==1.3);
326     assert(targetData[1]==1.3);
327     assert(targetData[2]==10);
328     assert(targetData[3]==10);
329     assert(targetData[4]==1.3);
330     assert(targetData[5]==1.3);
331     assert(targetData[6]==0);
332     assert(targetData[7]==1);
333     assert(targetData[8]==10);
334     assert(targetData[9]==3);
335     assert(targetData[10]==4);
336     assert(targetData[11]==5);
337     assert(targetData[12]==1.3);
338     assert(targetData[13]==1.3);
339     assert(targetData[14]==6);
340     assert(targetData[15]==10);
341     assert(targetData[16]==1.3);
342     assert(targetData[17]==1.3);
343    
344 jgs 537 }
345    
346     {
347    
348     cout << "\tTest get-slicing DataExpanded" << endl;
349    
350     DataArrayView::ShapeType viewShape;
351     viewShape.push_back(2);
352     viewShape.push_back(3);
353     Data temp(1.3,viewShape,FunctionSpace(),true);
354    
355 jgs 82 temp.getDataPoint(0,0)(0,0)=0.0;
356     temp.getDataPoint(0,0)(1,1)=1.0;
357 jgs 537
358 jgs 82 DataArrayView::RegionType region;
359     region.push_back(DataArrayView::RegionType::value_type(0,0));
360     region.push_back(DataArrayView::RegionType::value_type(0,0));
361 jgs 537
362 jgs 82 Data slice(temp.getSlice(region));
363 jgs 537
364 jgs 82 assert(slice.getDataPointRank()==0);
365     assert(slice.getDataPoint(0,0)()==0.0);
366 jgs 537
367 jgs 82 region.clear();
368     region.push_back(DataArrayView::RegionType::value_type(0,1));
369     region.push_back(DataArrayView::RegionType::value_type(0,1));
370 jgs 537
371 jgs 82 slice=temp.getSlice(region);
372 jgs 537
373 jgs 82 assert(slice.getDataPointRank()==2);
374     assert(slice.getDataPoint(0,0)(0,0)==0.0);
375 jgs 537
376 jgs 82 region.clear();
377     region.push_back(DataArrayView::RegionType::value_type(0,2));
378     region.push_back(DataArrayView::RegionType::value_type(0,2));
379 jgs 537
380 jgs 82 slice=temp.getSlice(region);
381 jgs 537
382 jgs 82 assert(slice.getDataPoint(0,0)(0,0)==0.0);
383     assert(slice.getDataPoint(0,0)(1,1)==1.0);
384 jgs 537
385 jgs 82 }
386    
387     {
388    
389 jgs 537 cout << "\tTest set-slicing DataExpanded" << endl;
390    
391 jgs 82 DataArrayView::ShapeType viewShape;
392     Data source(10.0,viewShape,FunctionSpace(),true);
393 jgs 537
394 jgs 82 viewShape.push_back(2);
395     viewShape.push_back(3);
396     Data target(1.3,viewShape,FunctionSpace(),true);
397 jgs 537
398 jgs 82 DataArrayView::RegionType region;
399     region.push_back(DataArrayView::RegionType::value_type(0,0));
400     region.push_back(DataArrayView::RegionType::value_type(0,0));
401 jgs 537
402 jgs 82 target.setSlice(source,region);
403 jgs 537
404 jgs 82 assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)());
405    
406     }
407    
408     }
409    
410 jgs 538 void DataTestCase::testAll() {
411 jgs 82
412     cout << endl;
413    
414     cout << "\tCreate a Data object from a DataArrayView" << endl;
415    
416     DataArrayView::ShapeType viewShape;
417     viewShape.push_back(3);
418 jgs 121 DataArrayView::ValueType viewData(3);
419 jgs 82 for (int i=0;i<viewShape[0];++i) {
420 jgs 121 viewData[i]=i;
421 jgs 82 }
422     DataArrayView myView(viewData,viewShape);
423    
424     bool expanded=true;
425     Data exData(myView,FunctionSpace(),expanded);
426     Data cData(myView);
427     Data result;
428    
429     assert(exData.isExpanded());
430     assert(cData.isConstant());
431     assert(result.isEmpty());
432    
433     cout << "\tTest some basic operations" << endl;
434     result=exData*cData;
435     assert(result.isExpanded());
436    
437     }
438    
439 jgs 538 void DataTestCase::testMore() {
440 jgs 82
441     cout << endl;
442    
443     cout << "\tCreate a Data object from a DataArrayView" << endl;
444    
445     DataArrayView::ShapeType viewShape;
446     viewShape.push_back(3);
447 jgs 121 DataArrayView::ValueType viewData(3);
448 jgs 82 for (int i=0;i<viewShape[0];++i) {
449 jgs 121 viewData[i]=i;
450 jgs 82 }
451     DataArrayView myView(viewData,viewShape);
452    
453     bool expanded=true;
454     Data exData(myView,FunctionSpace(),expanded);
455     Data cData(myView);
456     Data result;
457 jgs 123
458 jgs 82 assert(exData.isExpanded());
459     assert(cData.isConstant());
460     assert(result.isEmpty());
461    
462     cout << "\tTest some basic operations" << endl;
463     result=exData*cData;
464     assert(result.isExpanded());
465    
466 jgs 538 assert(result.Lsup()==4);
467     assert(result.sup()==4);
468     assert(result.inf()==0);
469    
470     result=exData+cData;
471     result=exData-cData;
472     result=exData/cData;
473    
474     cout << "\tExercise wherePositive method" << endl;
475     assert(!exData.wherePositive().isEmpty());
476    
477     cout << "\tExercise copyWithMask method" << endl;
478     exData.copyWithMask(result, exData.wherePositive());
479     assert(!exData.wherePositive().isEmpty());
480    
481 jgs 82 }
482    
483     void DataTestCase::testDataConstant() {
484    
485     cout << endl;
486    
487     cout << "\tCreate a DataConstant object from a DataArrayView" << endl;
488    
489     DataArrayView::ShapeType viewShape;
490     viewShape.push_back(2);
491     viewShape.push_back(3);
492     viewShape.push_back(4);
493 jgs 121 DataArrayView::ValueType viewData(2*3*4);
494 jgs 82 for (int i=0;i<DataArrayView::noValues(viewShape);++i) {
495 jgs 121 viewData[i]=i;
496 jgs 82 }
497     DataArrayView myView(viewData,viewShape);
498    
499     Data left(myView);
500     Data right(myView);
501     Data result;
502    
503     cout << "\tTest some basic operations" << endl;
504    
505     result=left-right;
506    
507     assert(left.isConstant());
508     assert(right.isConstant());
509     assert(result.isConstant());
510    
511     result=left+right;
512    
513     assert(left.isConstant());
514     assert(right.isConstant());
515     assert(result.isConstant());
516    
517     assert(!result.isExpanded());
518     assert(!result.isTagged());
519    
520     }
521    
522     void DataTestCase::testDataTagged() {
523    
524     cout << endl;
525    
526 jgs 539 {
527 jgs 82
528 jgs 539 cout << "\tCreate a DataTagged object with a default value only." << endl;
529 jgs 511
530 jgs 539 DataTagged::TagListType keys;
531 jgs 511
532 jgs 539 DataTagged::ValueListType values;
533 jgs 511
534 jgs 539 DataArrayView::ShapeType viewShape;
535     viewShape.push_back(3);
536 jgs 82
537 jgs 539 DataArrayView::ValueType viewData(3);
538     for (int i=0;i<viewShape[0];i++) {
539     viewData[i]=i;
540     }
541     DataArrayView defaultValue(viewData,viewShape);
542 jgs 82
543 jgs 539 bool expanded=false;
544    
545     Data myData(keys,values,defaultValue,FunctionSpace(),expanded);
546 jgs 511
547 jgs 539 // cout << myData.toString() << endl;
548 jgs 511
549 jgs 539 assert(!myData.isEmpty());
550     assert(myData.isTagged());
551     assert(myData.getTagNumber(0)==1);
552     assert(myData.getDataPointRank()==1);
553     assert(myData.getLength()==3);
554 jgs 82
555 jgs 539 DataArrayView myDataView = myData.getPointDataView();
556     assert(!myDataView.isEmpty());
557     assert(myDataView.getOffset()==0);
558     assert(myDataView.getRank()==1);
559     assert(myDataView.noValues()==3);
560     assert(myDataView.getShape().size()==1);
561     assert(myDataView(0)==0.0);
562     assert(myDataView(1)==1.0);
563     assert(myDataView(2)==2.0);
564 jgs 82
565 jgs 539 myDataView = myData.getDataPoint(0,0);
566     assert(!myDataView.isEmpty());
567     assert(myDataView.getOffset()==0);
568     assert(myDataView.getRank()==1);
569     assert(myDataView.noValues()==3);
570     assert(myDataView.getShape().size()==1);
571     assert(myDataView(0)==0.0);
572     assert(myDataView(1)==1.0);
573     assert(myDataView(2)==2.0);
574 jgs 82
575 jgs 539 double* sampleData=myData.getSampleData(0);
576     for (int i=0; i<myDataView.noValues(); i++) {
577     assert(sampleData[i]==i);
578     }
579     // use a non-existent tag so we get a pointer to
580     // the first element of the data array
581     sampleData=myData.getSampleDataByTag(9);
582     for (int i=0; i<myData.getLength(); i++) {
583     assert(sampleData[i]==i);
584     }
585 jgs 511
586 jgs 539 cout << "\tTest setting of a tag and associated value." << endl;
587 jgs 511
588 jgs 539 // value for tag "1"
589     DataArray eTwo(defaultValue);
590     for (int i=0;i<eTwo.getView().getShape()[0];i++) {
591     eTwo.getView()(i)=i+2.0;
592     }
593    
594     myData.setTaggedValueFromCPP(1,eTwo.getView());
595    
596     assert(myData.getLength()==6);
597    
598     myDataView = myData.getDataPoint(0,0);
599     assert(myDataView==eTwo.getView());
600     assert(!myDataView.isEmpty());
601     assert(myDataView.getOffset()==3);
602     assert(myDataView.getRank()==1);
603     assert(myDataView.noValues()==3);
604     assert(myDataView.getShape().size()==1);
605     assert(myDataView(0)==2);
606     assert(myDataView(1)==3);
607     assert(myDataView(2)==4);
608    
609     sampleData=myData.getSampleDataByTag(1);
610     for (int i=0; i<myDataView.noValues(); i++) {
611     assert(sampleData[i]==i+2);
612     }
613    
614 jgs 511 }
615    
616 jgs 539 {
617 jgs 511
618 jgs 539 cout << "\tCreate a DataTagged object via tag() method." << endl;
619 jgs 511
620 jgs 539 DataArrayView::ShapeType viewShape;
621     viewShape.push_back(2);
622     viewShape.push_back(3);
623     Data myData(1.3,viewShape,FunctionSpace(),false);
624     myData.tag();
625 jgs 511
626 jgs 539 //cout << myData.toString() << endl;
627    
628     assert(!myData.isEmpty());
629     assert(myData.isTagged());
630     assert(myData.getTagNumber(0)==1);
631     assert(myData.getDataPointRank()==2);
632     assert(myData.getLength()==6);
633    
634     // check default value
635     DataArrayView myDataView = myData.getPointDataView();
636     assert(!myDataView.isEmpty());
637     assert(myDataView.getOffset()==0);
638     assert(myDataView.getRank()==2);
639     assert(myDataView.noValues()==6);
640     assert(myDataView.getShape().size()==2);
641     assert(myDataView(0,0)==1.3);
642     assert(myDataView(0,1)==1.3);
643     assert(myDataView(0,2)==1.3);
644     assert(myDataView(1,0)==1.3);
645     assert(myDataView(1,1)==1.3);
646     assert(myDataView(1,2)==1.3);
647    
648     // check value for data-point (0,0).
649     myDataView = myData.getDataPoint(0,0);
650     assert(!myDataView.isEmpty());
651     assert(myDataView.getOffset()==0);
652     assert(myDataView.getRank()==2);
653     assert(myDataView.noValues()==6);
654     assert(myDataView.getShape().size()==2);
655     assert(myDataView(0,0)==1.3);
656     assert(myDataView(0,1)==1.3);
657     assert(myDataView(0,2)==1.3);
658     assert(myDataView(1,0)==1.3);
659     assert(myDataView(1,1)==1.3);
660     assert(myDataView(1,2)==1.3);
661    
662 jgs 511 }
663    
664 jgs 82 }
665    
666 jgs 538 void DataTestCase::testDataTaggedExceptions() {
667    
668     cout << endl;
669    
670     cout << "\tTest DataTagged exceptions." << endl;
671    
672     Data myData;
673     DataArrayView myView;
674    
675     try {
676     myData.getSampleDataByTag(0);;
677     assert(false);
678     }
679     catch (EsysException& e) {
680     //cout << e.what() << endl;
681     assert(true);
682     }
683    
684     try {
685     myData.setTaggedValueFromCPP(0,myView);;
686     assert(false);
687     }
688     catch (EsysException& e) {
689     //cout << e.what() << endl;
690     assert(true);
691     }
692    
693     }
694    
695 jgs 82 void DataTestCase::testConstructors() {
696    
697     cout << endl;
698    
699     DataArrayView::ShapeType viewShape;
700     {
701     cout << "\tCreate an Empty Data object" << endl;
702     Data temp(1.3,viewShape,FunctionSpace(),false);
703     }
704     {
705     cout << "\tCreate a rank 2 Data object" << endl;
706     viewShape.push_back(2);
707     viewShape.push_back(3);
708     Data temp(1.3,viewShape,FunctionSpace(),false);
709     }
710     }
711    
712     void DataTestCase::testOperations() {
713 jgs 113
714 jgs 82 cout << endl;
715    
716 jgs 113 // define the shape for the DataArrayView test data
717     DataArrayView::ShapeType shape;
718     shape.push_back(2);
719     shape.push_back(3);
720 jgs 82
721 jgs 113 // allocate the data for the DataArrayView
722     DataArrayView::ValueType data(DataArrayView::noValues(shape),0);
723 jgs 82
724 jgs 113 // construct DataArrayView
725     DataArrayView dataView(data,shape);
726 jgs 82
727 jgs 113 // assign values to the data
728     for (int i=0;i<shape[0];i++) {
729     for (int j=0;j<shape[1];j++) {
730     dataView(i,j)=dataView.index(i,j);
731     }
732     }
733    
734 jgs 563 Data baseEx(dataView,FunctionSpace(),true);
735     Data baseCon(dataView,FunctionSpace(),false);
736     Data baseTag(dataView,FunctionSpace(),false);
737     baseTag.tag();
738 jgs 113
739 jgs 563 assert(baseEx.isExpanded());
740     assert(baseCon.isConstant());
741     assert(baseTag.isTagged());
742    
743     Data resultEx;
744     Data resultCon;
745     Data resultTag;
746    
747 jgs 113 // test unary operations
748    
749     cout << "\tTest Data::pow." << endl;
750     Data power(3.0,shape,FunctionSpace(),true);
751 jgs 563 resultEx.copy(baseEx.powD(power));
752     resultCon.copy(baseCon.powD(power));
753     resultTag.copy(baseTag.powD(power));
754 jgs 113 for (int i=0;i<shape[0];i++) {
755     for (int j=0;j<shape[1];j++) {
756 jgs 563 assert(resultEx.getPointDataView()(i,j) == pow(dataView.index(i,j),3.0));
757     assert(resultCon.getPointDataView()(i,j) == pow(dataView.index(i,j),3.0));
758     assert(resultTag.getPointDataView()(i,j) == pow(dataView.index(i,j),3.0));
759 jgs 113 }
760     }
761 jgs 82
762 jgs 113 cout << "\tTest Data::sin." << endl;
763 jgs 563 resultEx.copy(baseEx.sin());
764     resultCon.copy(baseCon.sin());
765     resultTag.copy(baseTag.sin());
766 jgs 102 assert(true);
767    
768 jgs 113 cout << "\tTest Data::cos." << endl;
769 jgs 563 resultEx.copy(baseEx.cos());
770     resultCon.copy(baseCon.cos());
771     resultTag.copy(baseTag.cos());
772 jgs 102 assert(true);
773    
774 jgs 113 cout << "\tTest Data::tan." << endl;
775 jgs 563 resultEx.copy(baseEx.tan());
776     resultCon.copy(baseCon.tan());
777     resultTag.copy(baseTag.tan());
778 jgs 102 assert(true);
779    
780 jgs 150 cout << "\tTest Data::asin." << endl;
781 jgs 563 resultEx.copy(baseEx.asin());
782     resultCon.copy(baseCon.asin());
783     resultTag.copy(baseTag.asin());
784 jgs 150 assert(true);
785    
786     cout << "\tTest Data::acos." << endl;
787 jgs 563 resultEx.copy(baseEx.acos());
788     resultCon.copy(baseCon.acos());
789     resultTag.copy(baseTag.acos());
790 jgs 150 assert(true);
791    
792     cout << "\tTest Data::atan." << endl;
793 jgs 563 resultEx.copy(baseEx.atan());
794     resultCon.copy(baseCon.atan());
795     resultTag.copy(baseTag.atan());
796 jgs 150 assert(true);
797    
798     cout << "\tTest Data::sinh." << endl;
799 jgs 563 resultEx.copy(baseEx.sinh());
800     resultCon.copy(baseCon.sinh());
801     resultTag.copy(baseTag.sinh());
802 jgs 150 assert(true);
803    
804     cout << "\tTest Data::cosh." << endl;
805 jgs 563 resultEx.copy(baseEx.cosh());
806     resultCon.copy(baseCon.cosh());
807     resultTag.copy(baseTag.cosh());
808 jgs 150 assert(true);
809    
810     cout << "\tTest Data::tanh." << endl;
811 jgs 563 resultEx.copy(baseEx.tanh());
812     resultCon.copy(baseCon.tanh());
813     resultTag.copy(baseTag.tanh());
814 jgs 150 assert(true);
815    
816     cout << "\tTest Data::asinh." << endl;
817 jgs 563 resultEx.copy(baseEx.asinh());
818     resultCon.copy(baseCon.asinh());
819     resultTag.copy(baseTag.asinh());
820 jgs 150 assert(true);
821    
822     cout << "\tTest Data::acosh." << endl;
823 jgs 563 resultEx.copy(baseEx.acosh());
824     resultCon.copy(baseCon.acosh());
825     resultTag.copy(baseTag.acosh());
826 jgs 150 assert(true);
827    
828     cout << "\tTest Data::atanh." << endl;
829 jgs 563 resultEx.copy(baseEx.atanh());
830     resultCon.copy(baseCon.atanh());
831     resultTag.copy(baseTag.atanh());
832 jgs 150 assert(true);
833    
834 jgs 113 cout << "\tTest Data::log." << endl;
835 jgs 563 resultEx.copy(baseEx.log());
836     resultCon.copy(baseCon.log());
837     resultTag.copy(baseTag.log());
838 jgs 102 assert(true);
839    
840 jgs 113 cout << "\tTest Data::abs." << endl;
841 jgs 563 resultEx.copy(baseEx.abs());
842     resultCon.copy(baseCon.abs());
843     resultTag.copy(baseTag.abs());
844 jgs 102 assert(true);
845    
846 jgs 113 cout << "\tTest Data::sign." << endl;
847 jgs 563 resultEx.copy(baseEx.sign());
848     resultCon.copy(baseCon.sign());
849     resultTag.copy(baseTag.sign());
850 jgs 102 assert(true);
851    
852 jgs 113 cout << "\tTest Data::exp." << endl;
853 jgs 563 resultEx.copy(baseEx.exp());
854     resultCon.copy(baseCon.exp());
855     resultTag.copy(baseTag.exp());
856 jgs 102 assert(true);
857    
858 jgs 113 cout << "\tTest Data::sqrt." << endl;
859 jgs 563 resultEx.copy(baseEx.sqrt());
860     resultCon.copy(baseCon.sqrt());
861     resultTag.copy(baseTag.sqrt());
862 jgs 102 assert(true);
863    
864 jgs 113 cout << "\tTest Data::neg." << endl;
865 jgs 563 resultEx.copy(baseEx.neg());
866     resultCon.copy(baseCon.neg());
867     resultTag.copy(baseTag.neg());
868 jgs 102 assert(true);
869    
870 jgs 113 cout << "\tTest Data::pos." << endl;
871 jgs 563 resultEx.copy(baseEx.pos());
872     resultCon.copy(baseCon.pos());
873     resultTag.copy(baseTag.pos());
874 jgs 113 for (int i=0;i<shape[0];i++) {
875     for (int j=0;j<shape[1];j++) {
876 jgs 563 assert(resultEx.getPointDataView()(i,j) == dataView.index(i,j));
877     assert(resultCon.getPointDataView()(i,j) == dataView.index(i,j));
878     assert(resultTag.getPointDataView()(i,j) == dataView.index(i,j));
879 jgs 113 }
880     }
881 jgs 102
882 jgs 113 // test reduction operations
883    
884     cout << "\tTest Data::Lsup." << endl;
885 jgs 563 assert(baseEx.Lsup() == 5);
886     assert(baseCon.Lsup() == 5);
887     assert(baseTag.Lsup() == 5);
888 jgs 113
889     cout << "\tTest Data::sup." << endl;
890 jgs 563 assert(baseEx.sup() == 5);
891     assert(baseCon.sup() == 5);
892     assert(baseTag.sup() == 5);
893 jgs 113
894     cout << "\tTest Data::inf." << endl;
895 jgs 563 assert(baseEx.inf() == 0);
896     assert(baseCon.inf() == 0);
897     assert(baseTag.inf() == 0);
898 jgs 113
899     // test data-point reduction operations
900    
901     cout << "\tTest Data::minval." << endl;
902 jgs 563 resultEx.copy(baseEx.minval());
903     resultCon.copy(baseCon.minval());
904     resultTag.copy(baseTag.minval());
905     assert(resultEx.getPointDataView()() == 0);
906     assert(resultCon.getPointDataView()() == 0);
907     assert(resultTag.getPointDataView()() == 0);
908 jgs 102
909 jgs 113 cout << "\tTest Data::maxval." << endl;
910 jgs 563 resultEx.copy(baseEx.maxval());
911     resultCon.copy(baseCon.maxval());
912     resultTag.copy(baseTag.maxval());
913     assert(resultEx.getPointDataView()() == 5);
914     assert(resultCon.getPointDataView()() == 5);
915     assert(resultTag.getPointDataView()() == 5);
916 jgs 102
917 jgs 113 cout << "\tTest Data::trace." << endl;
918 jgs 563 resultEx.copy(baseEx.trace());
919     resultCon.copy(baseCon.trace());
920     resultTag.copy(baseTag.trace());
921     assert(resultEx.getPointDataView()() == 15);
922     assert(resultCon.getPointDataView()() == 15);
923     assert(resultTag.getPointDataView()() == 15);
924 jgs 102
925 jgs 82 }
926    
927 jgs 110 void DataTestCase::testRefValue() {
928    
929     //
930     // Note - this test can't be run as boost::python::numeric::array
931 jgs 113 // objects can only be created and used from within a python thread!
932 jgs 110 //
933    
934     cout << endl;
935    
936     cout << "\tTest Data object RefValue methods." << endl;
937    
938     // Create three Data object - DataExpanded, DataConstant and DataEmpty
939     DataArrayView::ShapeType viewShape;
940     viewShape.push_back(3);
941 jgs 121 DataArrayView::ValueType viewData(3);
942 jgs 110 for (int i=0;i<viewShape[0];++i) {
943 jgs 121 viewData[i]=i;
944 jgs 110 }
945     DataArrayView myView(viewData,viewShape);
946    
947     bool expanded=true;
948    
949     Data expandedData(myView,FunctionSpace(),expanded);
950     Data constantData(myView);
951     Data emptyData;
952    
953     assert(expandedData.isExpanded());
954     assert(constantData.isConstant());
955     assert(emptyData.isEmpty());
956    
957     // Check assertions are thrown for RefValue methods on DataEmpty
958    
959     int ref = 0;
960     boost::python::numeric::array num_array(1.0);
961    
962     try {
963     emptyData.getRefValue(ref,num_array);
964     assert(false);
965     }
966     catch (EsysException& e) {
967     assert(true);
968     }
969     try {
970     emptyData.setRefValue(ref,num_array);
971     assert(false);
972     }
973     catch (EsysException& e) {
974     assert(true);
975     }
976    
977     // Check assertions are thrown for RefValue methods on DataConstant
978     try {
979     constantData.getRefValue(ref,num_array);
980     assert(false);
981     }
982     catch (EsysException& e) {
983     assert(true);
984     }
985     try {
986     constantData.setRefValue(ref,num_array);
987     assert(false);
988     }
989     catch (EsysException& e) {
990     assert(true);
991     }
992    
993     // Check calls to RefValue methods on DataExpanded
994     expandedData.getRefValue(ref,num_array);
995     expandedData.setRefValue(ref,num_array);
996    
997     }
998    
999 jgs 151 void DataTestCase::testMemAlloc() {
1000    
1001     //
1002     // Simple little sanity check for the memory allocator
1003    
1004     cout << endl;
1005    
1006     Data *testData;
1007     for (int i=0; i<1000; i++) {
1008     testData = new Data(0.0, DataArrayView::ShapeType(), FunctionSpace(), true);
1009     delete testData;
1010     }
1011    
1012     DataArrayView::ShapeType viewShape;
1013     viewShape.push_back(10);
1014     viewShape.push_back(10);
1015     viewShape.push_back(10);
1016    
1017     Data *testData2;
1018     Data *testData3 = new Data(0.0, viewShape, FunctionSpace(), true);
1019     for (int i=0; i<1000; i++) {
1020     testData2 = new Data(0.0, viewShape, FunctionSpace(), true);
1021     delete testData2;
1022     }
1023     delete testData3;
1024    
1025     }
1026    
1027 jgs 82 TestSuite* DataTestCase::suite ()
1028     {
1029     //
1030     // create the suite of tests to perform.
1031     TestSuite *testSuite = new TestSuite ("DataTestCase");
1032    
1033     testSuite->addTest (new TestCaller< DataTestCase>("testAll",&DataTestCase::testAll));
1034     testSuite->addTest (new TestCaller< DataTestCase>("testMore",&DataTestCase::testMore));
1035     testSuite->addTest (new TestCaller< DataTestCase>("testDataConstant",&DataTestCase::testDataConstant));
1036     testSuite->addTest (new TestCaller< DataTestCase>("testDataTagged",&DataTestCase::testDataTagged));
1037     testSuite->addTest (new TestCaller< DataTestCase>("testDataTaggedExceptions",&DataTestCase::testDataTaggedExceptions));
1038     testSuite->addTest (new TestCaller< DataTestCase>("testConstructors",&DataTestCase::testConstructors));
1039     testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));
1040     testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));
1041 jgs 110 //testSuite->addTest (new TestCaller< DataTestCase>("testRefValue",&DataTestCase::testRefValue));
1042 jgs 151 testSuite->addTest (new TestCaller< DataTestCase>("testMemAlloc",&DataTestCase::testMemAlloc));
1043 jgs 82
1044     return testSuite;
1045     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26