/[escript]/branches/ROBW_XPLATFORM/escript/test/DataTestCase.cpp
ViewVC logotype

Annotation of /branches/ROBW_XPLATFORM/escript/test/DataTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 538 - (hide annotations)
Mon Feb 20 03:43:25 2006 UTC (14 years, 1 month ago) by jgs
Original Path: trunk/escript/test/Data/DataTestCase.cpp
File size: 22568 byte(s)
minor formatting changes

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 jgs 474 #include "FunctionSpace.h"
19 jgs 511 #include "EsysException.h"
20 jgs 82
21 jgs 537 #include "Data.h"
22    
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     // create a DataTagged with a scalar default value only
223    
224 jgs 82 DataArrayView::ShapeType viewShape;
225 jgs 537 Data source(10.0,viewShape,FunctionSpace(),false);
226     source.tag();
227    
228     //cout << source.toString() << endl;
229    
230 jgs 82 //
231 jgs 537 // create a DataTagged with a rank 2 default value only
232    
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     //cout << target.toString() << endl;
239    
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     //cout << target.toString() << endl;
250    
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     // add a value for tag "1"
262    
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     //
272     // set a slice in target from source
273    
274     region.clear();
275     region.push_back(DataArrayView::RegionType::value_type(0,0));
276     region.push_back(DataArrayView::RegionType::value_type(1,1));
277    
278     target.setSlice(source,region);
279    
280     //cout << target.toString() << endl;
281    
282     assert(target.isTagged());
283     assert(target.getDataPointRank()==2);
284     assert(target.getDataPoint(0,0)(0,0)==0);
285     assert(target.getDataPoint(0,0)(0,1)==source.getDataPoint(0,0)());
286     assert(target.getDataPoint(0,0)(0,2)==4);
287     assert(target.getDataPoint(0,0)(1,0)==1);
288     assert(target.getDataPoint(0,0)(1,1)==3);
289     assert(target.getDataPoint(0,0)(1,2)==5);
290    
291     }
292    
293     {
294    
295     cout << "\tTest get-slicing DataExpanded" << endl;
296    
297     DataArrayView::ShapeType viewShape;
298     viewShape.push_back(2);
299     viewShape.push_back(3);
300     Data temp(1.3,viewShape,FunctionSpace(),true);
301    
302 jgs 82 temp.getDataPoint(0,0)(0,0)=0.0;
303     temp.getDataPoint(0,0)(1,1)=1.0;
304 jgs 537
305 jgs 82 DataArrayView::RegionType region;
306     region.push_back(DataArrayView::RegionType::value_type(0,0));
307     region.push_back(DataArrayView::RegionType::value_type(0,0));
308 jgs 537
309 jgs 82 Data slice(temp.getSlice(region));
310 jgs 537
311 jgs 82 assert(slice.getDataPointRank()==0);
312     assert(slice.getDataPoint(0,0)()==0.0);
313 jgs 537
314 jgs 82 region.clear();
315     region.push_back(DataArrayView::RegionType::value_type(0,1));
316     region.push_back(DataArrayView::RegionType::value_type(0,1));
317 jgs 537
318 jgs 82 slice=temp.getSlice(region);
319 jgs 537
320 jgs 82 assert(slice.getDataPointRank()==2);
321     assert(slice.getDataPoint(0,0)(0,0)==0.0);
322 jgs 537
323 jgs 82 region.clear();
324     region.push_back(DataArrayView::RegionType::value_type(0,2));
325     region.push_back(DataArrayView::RegionType::value_type(0,2));
326 jgs 537
327 jgs 82 slice=temp.getSlice(region);
328 jgs 537
329 jgs 82 assert(slice.getDataPoint(0,0)(0,0)==0.0);
330     assert(slice.getDataPoint(0,0)(1,1)==1.0);
331 jgs 537
332 jgs 82 }
333    
334     {
335    
336 jgs 537 cout << "\tTest set-slicing DataExpanded" << endl;
337    
338 jgs 82 DataArrayView::ShapeType viewShape;
339     Data source(10.0,viewShape,FunctionSpace(),true);
340 jgs 537
341 jgs 82 viewShape.push_back(2);
342     viewShape.push_back(3);
343     Data target(1.3,viewShape,FunctionSpace(),true);
344 jgs 537
345 jgs 82 DataArrayView::RegionType region;
346     region.push_back(DataArrayView::RegionType::value_type(0,0));
347     region.push_back(DataArrayView::RegionType::value_type(0,0));
348 jgs 537
349 jgs 82 target.setSlice(source,region);
350 jgs 537
351 jgs 82 assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)());
352    
353     }
354    
355     }
356    
357 jgs 538 void DataTestCase::testAll() {
358 jgs 82
359     cout << endl;
360    
361     cout << "\tCreate a Data object from a DataArrayView" << endl;
362    
363     DataArrayView::ShapeType viewShape;
364     viewShape.push_back(3);
365 jgs 121 DataArrayView::ValueType viewData(3);
366 jgs 82 for (int i=0;i<viewShape[0];++i) {
367 jgs 121 viewData[i]=i;
368 jgs 82 }
369     DataArrayView myView(viewData,viewShape);
370    
371     bool expanded=true;
372     Data exData(myView,FunctionSpace(),expanded);
373     Data cData(myView);
374     Data result;
375    
376     assert(exData.isExpanded());
377     assert(cData.isConstant());
378     assert(result.isEmpty());
379    
380     cout << "\tTest some basic operations" << endl;
381     result=exData*cData;
382     assert(result.isExpanded());
383    
384     }
385    
386 jgs 538 void DataTestCase::testMore() {
387 jgs 82
388     cout << endl;
389    
390     cout << "\tCreate a Data object from a DataArrayView" << endl;
391    
392     DataArrayView::ShapeType viewShape;
393     viewShape.push_back(3);
394 jgs 121 DataArrayView::ValueType viewData(3);
395 jgs 82 for (int i=0;i<viewShape[0];++i) {
396 jgs 121 viewData[i]=i;
397 jgs 82 }
398     DataArrayView myView(viewData,viewShape);
399    
400     bool expanded=true;
401     Data exData(myView,FunctionSpace(),expanded);
402     Data cData(myView);
403     Data result;
404 jgs 123
405 jgs 82 assert(exData.isExpanded());
406     assert(cData.isConstant());
407     assert(result.isEmpty());
408    
409     cout << "\tTest some basic operations" << endl;
410     result=exData*cData;
411     assert(result.isExpanded());
412    
413 jgs 538 assert(result.Lsup()==4);
414     assert(result.sup()==4);
415     assert(result.inf()==0);
416    
417     result=exData+cData;
418     result=exData-cData;
419     result=exData/cData;
420    
421     cout << "\tExercise wherePositive method" << endl;
422     assert(!exData.wherePositive().isEmpty());
423    
424     cout << "\tExercise copyWithMask method" << endl;
425     exData.copyWithMask(result, exData.wherePositive());
426     assert(!exData.wherePositive().isEmpty());
427    
428 jgs 82 }
429    
430     void DataTestCase::testDataConstant() {
431    
432     cout << endl;
433    
434     cout << "\tCreate a DataConstant object from a DataArrayView" << endl;
435    
436     DataArrayView::ShapeType viewShape;
437     viewShape.push_back(2);
438     viewShape.push_back(3);
439     viewShape.push_back(4);
440 jgs 121 DataArrayView::ValueType viewData(2*3*4);
441 jgs 82 for (int i=0;i<DataArrayView::noValues(viewShape);++i) {
442 jgs 121 viewData[i]=i;
443 jgs 82 }
444     DataArrayView myView(viewData,viewShape);
445    
446     Data left(myView);
447     Data right(myView);
448     Data result;
449    
450     cout << "\tTest some basic operations" << endl;
451    
452     result=left-right;
453    
454     assert(left.isConstant());
455     assert(right.isConstant());
456     assert(result.isConstant());
457    
458     result=left+right;
459    
460     assert(left.isConstant());
461     assert(right.isConstant());
462     assert(result.isConstant());
463    
464     assert(!result.isExpanded());
465     assert(!result.isTagged());
466    
467     }
468    
469     void DataTestCase::testDataTagged() {
470    
471     cout << endl;
472    
473 jgs 511 cout << "\tCreate a DataTagged object with a default value only." << endl;
474 jgs 82
475     DataTagged::TagListType keys;
476 jgs 511
477 jgs 82 DataTagged::ValueListType values;
478 jgs 511
479 jgs 82 DataArrayView::ShapeType viewShape;
480     viewShape.push_back(3);
481 jgs 511
482 jgs 121 DataArrayView::ValueType viewData(3);
483 jgs 538 for (int i=0;i<viewShape[0];i++) {
484 jgs 121 viewData[i]=i;
485 jgs 82 }
486 jgs 538 DataArrayView defaultValue(viewData,viewShape);
487 jgs 82
488     bool expanded=false;
489    
490 jgs 538 Data myData(keys,values,defaultValue,FunctionSpace(),expanded);
491 jgs 511
492     // cout << myData.toString() << endl;
493    
494     assert(!myData.isEmpty());
495 jgs 82 assert(myData.isTagged());
496 jgs 511 assert(myData.getTagNumber(0)==1);
497     assert(myData.getDataPointRank()==1);
498     assert(myData.getLength()==3);
499 jgs 82
500 jgs 511 DataArrayView myDataView = myData.getPointDataView();
501     assert(!myDataView.isEmpty());
502     assert(myDataView.getOffset()==0);
503     assert(myDataView.getRank()==1);
504     assert(myDataView.noValues()==3);
505     assert(myDataView.getShape().size()==1);
506     assert(myDataView(0)==0.0);
507     assert(myDataView(1)==1.0);
508     assert(myDataView(2)==2.0);
509 jgs 82
510 jgs 511 myDataView = myData.getDataPoint(0,0);
511     assert(!myDataView.isEmpty());
512     assert(myDataView.getOffset()==0);
513     assert(myDataView.getRank()==1);
514     assert(myDataView.noValues()==3);
515     assert(myDataView.getShape().size()==1);
516     assert(myDataView(0)==0.0);
517     assert(myDataView(1)==1.0);
518     assert(myDataView(2)==2.0);
519 jgs 82
520 jgs 511 double* sampleData=myData.getSampleData(0);
521     for (int i=0; i<myDataView.noValues(); i++) {
522     assert(sampleData[i]==i);
523     }
524     // use a non-existent tag so we get a pointer to
525     // the first element of the data array
526     sampleData=myData.getSampleDataByTag(9);
527     for (int i=0; i<myData.getLength(); i++) {
528     assert(sampleData[i]==i);
529     }
530    
531     cout << "\tTest setting of a tag and associated value." << endl;
532    
533     // value for tag "1"
534 jgs 538 DataArray eTwo(defaultValue);
535 jgs 511 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
536     eTwo.getView()(i)=i+2.0;
537     }
538    
539     myData.setTaggedValueFromCPP(1,eTwo.getView());
540    
541     assert(myData.getLength()==6);
542    
543     myDataView = myData.getDataPoint(0,0);
544     assert(myDataView==eTwo.getView());
545     assert(!myDataView.isEmpty());
546     assert(myDataView.getOffset()==3);
547     assert(myDataView.getRank()==1);
548     assert(myDataView.noValues()==3);
549     assert(myDataView.getShape().size()==1);
550     assert(myDataView(0)==2);
551     assert(myDataView(1)==3);
552     assert(myDataView(2)==4);
553    
554     sampleData=myData.getSampleDataByTag(1);
555     for (int i=0; i<myDataView.noValues(); i++) {
556     assert(sampleData[i]==i+2);
557     }
558    
559 jgs 82 }
560    
561 jgs 538 void DataTestCase::testDataTaggedExceptions() {
562    
563     cout << endl;
564    
565     cout << "\tTest DataTagged exceptions." << endl;
566    
567     Data myData;
568     DataArrayView myView;
569    
570     try {
571     myData.getSampleDataByTag(0);;
572     assert(false);
573     }
574     catch (EsysException& e) {
575     //cout << e.what() << endl;
576     assert(true);
577     }
578    
579     try {
580     myData.setTaggedValueFromCPP(0,myView);;
581     assert(false);
582     }
583     catch (EsysException& e) {
584     //cout << e.what() << endl;
585     assert(true);
586     }
587    
588     }
589    
590 jgs 82 void DataTestCase::testConstructors() {
591    
592     cout << endl;
593    
594     DataArrayView::ShapeType viewShape;
595     {
596     cout << "\tCreate an Empty Data object" << endl;
597     Data temp(1.3,viewShape,FunctionSpace(),false);
598     }
599     {
600     cout << "\tCreate a rank 2 Data object" << endl;
601     viewShape.push_back(2);
602     viewShape.push_back(3);
603     Data temp(1.3,viewShape,FunctionSpace(),false);
604     }
605     }
606    
607     void DataTestCase::testOperations() {
608 jgs 113
609 jgs 82 cout << endl;
610    
611 jgs 113 // define the shape for the DataArrayView test data
612     DataArrayView::ShapeType shape;
613     shape.push_back(2);
614     shape.push_back(3);
615 jgs 82
616 jgs 113 // allocate the data for the DataArrayView
617     DataArrayView::ValueType data(DataArrayView::noValues(shape),0);
618 jgs 82
619 jgs 113 // construct DataArrayView
620     DataArrayView dataView(data,shape);
621 jgs 82
622 jgs 113 // assign values to the data
623     for (int i=0;i<shape[0];i++) {
624     for (int j=0;j<shape[1];j++) {
625     dataView(i,j)=dataView.index(i,j);
626     }
627     }
628    
629     Data base(dataView);
630    
631     // test unary operations
632    
633     cout << "\tTest Data::pow." << endl;
634     Data power(3.0,shape,FunctionSpace(),true);
635 jgs 82 Data result(base.powD(power));
636 jgs 113 for (int i=0;i<shape[0];i++) {
637     for (int j=0;j<shape[1];j++) {
638     assert(result.getPointDataView()(i,j) == pow(dataView.index(i,j),3.0));
639     }
640     }
641 jgs 82
642 jgs 113 cout << "\tTest Data::sin." << endl;
643 jgs 82 result.copy(base.sin());
644 jgs 102 assert(true);
645    
646 jgs 113 cout << "\tTest Data::cos." << endl;
647 jgs 82 result.copy(base.cos());
648 jgs 102 assert(true);
649    
650 jgs 113 cout << "\tTest Data::tan." << endl;
651 jgs 82 result.copy(base.tan());
652 jgs 102 assert(true);
653    
654 jgs 150 cout << "\tTest Data::asin." << endl;
655     result.copy(base.asin());
656     assert(true);
657    
658     cout << "\tTest Data::acos." << endl;
659     result.copy(base.acos());
660     assert(true);
661    
662     cout << "\tTest Data::atan." << endl;
663     result.copy(base.atan());
664     assert(true);
665    
666     cout << "\tTest Data::sinh." << endl;
667     result.copy(base.sinh());
668     assert(true);
669    
670     cout << "\tTest Data::cosh." << endl;
671     result.copy(base.cosh());
672     assert(true);
673    
674     cout << "\tTest Data::tanh." << endl;
675     result.copy(base.tanh());
676     assert(true);
677    
678     cout << "\tTest Data::asinh." << endl;
679     result.copy(base.asinh());
680     assert(true);
681    
682     cout << "\tTest Data::acosh." << endl;
683     result.copy(base.acosh());
684     assert(true);
685    
686     cout << "\tTest Data::atanh." << endl;
687     result.copy(base.atanh());
688     assert(true);
689    
690 jgs 113 cout << "\tTest Data::log." << endl;
691 jgs 82 result.copy(base.log());
692 jgs 102 assert(true);
693    
694 jgs 311 //cout << "\tTest Data::ln." << endl;
695     //result.copy(base.ln());
696     //assert(true);
697 jgs 102
698 jgs 113 cout << "\tTest Data::abs." << endl;
699 jgs 102 result.copy(base.abs());
700     assert(true);
701    
702 jgs 113 cout << "\tTest Data::sign." << endl;
703 jgs 106 result.copy(base.sign());
704 jgs 102 assert(true);
705    
706 jgs 113 cout << "\tTest Data::exp." << endl;
707 jgs 106 result.copy(base.exp());
708 jgs 102 assert(true);
709    
710 jgs 113 cout << "\tTest Data::sqrt." << endl;
711 jgs 106 result.copy(base.sqrt());
712 jgs 102 assert(true);
713    
714 jgs 113 cout << "\tTest Data::neg." << endl;
715 jgs 106 result.copy(base.neg());
716 jgs 102 assert(true);
717    
718 jgs 113 cout << "\tTest Data::pos." << endl;
719 jgs 106 result.copy(base.pos());
720 jgs 113 for (int i=0;i<shape[0];i++) {
721     for (int j=0;j<shape[1];j++) {
722     assert(result.getPointDataView()(i,j) == dataView.index(i,j));
723     }
724     }
725 jgs 102
726 jgs 113 // test reduction operations
727    
728     cout << "\tTest Data::Lsup." << endl;
729     assert(base.Lsup() == 5);
730    
731     cout << "\tTest Data::sup." << endl;
732     assert(base.sup() == 5);
733    
734     cout << "\tTest Data::inf." << endl;
735     assert(base.inf() == 0);
736    
737     // test data-point reduction operations
738    
739     cout << "\tTest Data::minval." << endl;
740 jgs 106 result.copy(base.minval());
741 jgs 113 assert(result.getPointDataView()() == 0);
742 jgs 102
743 jgs 113 cout << "\tTest Data::maxval." << endl;
744 jgs 106 result.copy(base.maxval());
745 jgs 113 assert(result.getPointDataView()() == 5);
746 jgs 102
747 jgs 311 //cout << "\tTest Data::length." << endl;
748     //result.copy(base.length());
749     //assert(pow(result.getPointDataView()(),2.0) == 55);
750 jgs 102
751 jgs 113 cout << "\tTest Data::trace." << endl;
752 jgs 106 result.copy(base.trace());
753 jgs 113 assert(result.getPointDataView()() == 15);
754 jgs 102
755 jgs 106 //result.copy(base.transpose(0));
756     //assert(true);
757    
758 jgs 82 }
759    
760 jgs 110 void DataTestCase::testRefValue() {
761    
762     //
763     // Note - this test can't be run as boost::python::numeric::array
764 jgs 113 // objects can only be created and used from within a python thread!
765 jgs 110 //
766    
767     cout << endl;
768    
769     cout << "\tTest Data object RefValue methods." << endl;
770    
771     // Create three Data object - DataExpanded, DataConstant and DataEmpty
772     DataArrayView::ShapeType viewShape;
773     viewShape.push_back(3);
774 jgs 121 DataArrayView::ValueType viewData(3);
775 jgs 110 for (int i=0;i<viewShape[0];++i) {
776 jgs 121 viewData[i]=i;
777 jgs 110 }
778     DataArrayView myView(viewData,viewShape);
779    
780     bool expanded=true;
781    
782     Data expandedData(myView,FunctionSpace(),expanded);
783     Data constantData(myView);
784     Data emptyData;
785    
786     assert(expandedData.isExpanded());
787     assert(constantData.isConstant());
788     assert(emptyData.isEmpty());
789    
790     // Check assertions are thrown for RefValue methods on DataEmpty
791    
792     int ref = 0;
793     boost::python::numeric::array num_array(1.0);
794    
795     try {
796     emptyData.getRefValue(ref,num_array);
797     assert(false);
798     }
799     catch (EsysException& e) {
800     assert(true);
801     }
802     try {
803     emptyData.setRefValue(ref,num_array);
804     assert(false);
805     }
806     catch (EsysException& e) {
807     assert(true);
808     }
809    
810     // Check assertions are thrown for RefValue methods on DataConstant
811     try {
812     constantData.getRefValue(ref,num_array);
813     assert(false);
814     }
815     catch (EsysException& e) {
816     assert(true);
817     }
818     try {
819     constantData.setRefValue(ref,num_array);
820     assert(false);
821     }
822     catch (EsysException& e) {
823     assert(true);
824     }
825    
826     // Check calls to RefValue methods on DataExpanded
827     expandedData.getRefValue(ref,num_array);
828     expandedData.setRefValue(ref,num_array);
829    
830     }
831    
832 jgs 151 void DataTestCase::testMemAlloc() {
833    
834     //
835     // Simple little sanity check for the memory allocator
836    
837     cout << endl;
838    
839     Data *testData;
840     for (int i=0; i<1000; i++) {
841     testData = new Data(0.0, DataArrayView::ShapeType(), FunctionSpace(), true);
842     delete testData;
843     }
844    
845     DataArrayView::ShapeType viewShape;
846     viewShape.push_back(10);
847     viewShape.push_back(10);
848     viewShape.push_back(10);
849    
850     Data *testData2;
851     Data *testData3 = new Data(0.0, viewShape, FunctionSpace(), true);
852     for (int i=0; i<1000; i++) {
853     testData2 = new Data(0.0, viewShape, FunctionSpace(), true);
854     delete testData2;
855     }
856     delete testData3;
857    
858     }
859    
860 jgs 82 TestSuite* DataTestCase::suite ()
861     {
862     //
863     // create the suite of tests to perform.
864     TestSuite *testSuite = new TestSuite ("DataTestCase");
865    
866     testSuite->addTest (new TestCaller< DataTestCase>("testAll",&DataTestCase::testAll));
867     testSuite->addTest (new TestCaller< DataTestCase>("testMore",&DataTestCase::testMore));
868     testSuite->addTest (new TestCaller< DataTestCase>("testDataConstant",&DataTestCase::testDataConstant));
869     testSuite->addTest (new TestCaller< DataTestCase>("testDataTagged",&DataTestCase::testDataTagged));
870     testSuite->addTest (new TestCaller< DataTestCase>("testDataTaggedExceptions",&DataTestCase::testDataTaggedExceptions));
871     testSuite->addTest (new TestCaller< DataTestCase>("testConstructors",&DataTestCase::testConstructors));
872     testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));
873     testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));
874 jgs 110 //testSuite->addTest (new TestCaller< DataTestCase>("testRefValue",&DataTestCase::testRefValue));
875 jgs 151 testSuite->addTest (new TestCaller< DataTestCase>("testMemAlloc",&DataTestCase::testMemAlloc));
876 jgs 82
877     return testSuite;
878     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26