/[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 539 - (hide annotations)
Mon Feb 20 04:12:51 2006 UTC (14 years, 1 month ago) by jgs
Original Path: trunk/escript/test/Data/DataTestCase.cpp
File size: 24154 byte(s)
add a test case for tag() method

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 539 {
474 jgs 82
475 jgs 539 cout << "\tCreate a DataTagged object with a default value only." << endl;
476 jgs 511
477 jgs 539 DataTagged::TagListType keys;
478 jgs 511
479 jgs 539 DataTagged::ValueListType values;
480 jgs 511
481 jgs 539 DataArrayView::ShapeType viewShape;
482     viewShape.push_back(3);
483 jgs 82
484 jgs 539 DataArrayView::ValueType viewData(3);
485     for (int i=0;i<viewShape[0];i++) {
486     viewData[i]=i;
487     }
488     DataArrayView defaultValue(viewData,viewShape);
489 jgs 82
490 jgs 539 bool expanded=false;
491    
492     Data myData(keys,values,defaultValue,FunctionSpace(),expanded);
493 jgs 511
494 jgs 539 // cout << myData.toString() << endl;
495 jgs 511
496 jgs 539 assert(!myData.isEmpty());
497     assert(myData.isTagged());
498     assert(myData.getTagNumber(0)==1);
499     assert(myData.getDataPointRank()==1);
500     assert(myData.getLength()==3);
501 jgs 82
502 jgs 539 DataArrayView myDataView = myData.getPointDataView();
503     assert(!myDataView.isEmpty());
504     assert(myDataView.getOffset()==0);
505     assert(myDataView.getRank()==1);
506     assert(myDataView.noValues()==3);
507     assert(myDataView.getShape().size()==1);
508     assert(myDataView(0)==0.0);
509     assert(myDataView(1)==1.0);
510     assert(myDataView(2)==2.0);
511 jgs 82
512 jgs 539 myDataView = myData.getDataPoint(0,0);
513     assert(!myDataView.isEmpty());
514     assert(myDataView.getOffset()==0);
515     assert(myDataView.getRank()==1);
516     assert(myDataView.noValues()==3);
517     assert(myDataView.getShape().size()==1);
518     assert(myDataView(0)==0.0);
519     assert(myDataView(1)==1.0);
520     assert(myDataView(2)==2.0);
521 jgs 82
522 jgs 539 double* sampleData=myData.getSampleData(0);
523     for (int i=0; i<myDataView.noValues(); i++) {
524     assert(sampleData[i]==i);
525     }
526     // use a non-existent tag so we get a pointer to
527     // the first element of the data array
528     sampleData=myData.getSampleDataByTag(9);
529     for (int i=0; i<myData.getLength(); i++) {
530     assert(sampleData[i]==i);
531     }
532 jgs 511
533 jgs 539 cout << "\tTest setting of a tag and associated value." << endl;
534 jgs 511
535 jgs 539 // value for tag "1"
536     DataArray eTwo(defaultValue);
537     for (int i=0;i<eTwo.getView().getShape()[0];i++) {
538     eTwo.getView()(i)=i+2.0;
539     }
540    
541     myData.setTaggedValueFromCPP(1,eTwo.getView());
542    
543     assert(myData.getLength()==6);
544    
545     myDataView = myData.getDataPoint(0,0);
546     assert(myDataView==eTwo.getView());
547     assert(!myDataView.isEmpty());
548     assert(myDataView.getOffset()==3);
549     assert(myDataView.getRank()==1);
550     assert(myDataView.noValues()==3);
551     assert(myDataView.getShape().size()==1);
552     assert(myDataView(0)==2);
553     assert(myDataView(1)==3);
554     assert(myDataView(2)==4);
555    
556     sampleData=myData.getSampleDataByTag(1);
557     for (int i=0; i<myDataView.noValues(); i++) {
558     assert(sampleData[i]==i+2);
559     }
560    
561 jgs 511 }
562    
563 jgs 539 {
564 jgs 511
565 jgs 539 cout << "\tCreate a DataTagged object via tag() method." << endl;
566 jgs 511
567 jgs 539 DataArrayView::ShapeType viewShape;
568     viewShape.push_back(2);
569     viewShape.push_back(3);
570     Data myData(1.3,viewShape,FunctionSpace(),false);
571     myData.tag();
572 jgs 511
573 jgs 539 //cout << myData.toString() << endl;
574    
575     assert(!myData.isEmpty());
576     assert(myData.isTagged());
577     assert(myData.getTagNumber(0)==1);
578     assert(myData.getDataPointRank()==2);
579     assert(myData.getLength()==6);
580    
581     // check default value
582     DataArrayView myDataView = myData.getPointDataView();
583     assert(!myDataView.isEmpty());
584     assert(myDataView.getOffset()==0);
585     assert(myDataView.getRank()==2);
586     assert(myDataView.noValues()==6);
587     assert(myDataView.getShape().size()==2);
588     assert(myDataView(0,0)==1.3);
589     assert(myDataView(0,1)==1.3);
590     assert(myDataView(0,2)==1.3);
591     assert(myDataView(1,0)==1.3);
592     assert(myDataView(1,1)==1.3);
593     assert(myDataView(1,2)==1.3);
594    
595     // check value for data-point (0,0).
596     myDataView = myData.getDataPoint(0,0);
597     assert(!myDataView.isEmpty());
598     assert(myDataView.getOffset()==0);
599     assert(myDataView.getRank()==2);
600     assert(myDataView.noValues()==6);
601     assert(myDataView.getShape().size()==2);
602     assert(myDataView(0,0)==1.3);
603     assert(myDataView(0,1)==1.3);
604     assert(myDataView(0,2)==1.3);
605     assert(myDataView(1,0)==1.3);
606     assert(myDataView(1,1)==1.3);
607     assert(myDataView(1,2)==1.3);
608    
609 jgs 511 }
610    
611 jgs 82 }
612    
613 jgs 538 void DataTestCase::testDataTaggedExceptions() {
614    
615     cout << endl;
616    
617     cout << "\tTest DataTagged exceptions." << endl;
618    
619     Data myData;
620     DataArrayView myView;
621    
622     try {
623     myData.getSampleDataByTag(0);;
624     assert(false);
625     }
626     catch (EsysException& e) {
627     //cout << e.what() << endl;
628     assert(true);
629     }
630    
631     try {
632     myData.setTaggedValueFromCPP(0,myView);;
633     assert(false);
634     }
635     catch (EsysException& e) {
636     //cout << e.what() << endl;
637     assert(true);
638     }
639    
640     }
641    
642 jgs 82 void DataTestCase::testConstructors() {
643    
644     cout << endl;
645    
646     DataArrayView::ShapeType viewShape;
647     {
648     cout << "\tCreate an Empty Data object" << endl;
649     Data temp(1.3,viewShape,FunctionSpace(),false);
650     }
651     {
652     cout << "\tCreate a rank 2 Data object" << endl;
653     viewShape.push_back(2);
654     viewShape.push_back(3);
655     Data temp(1.3,viewShape,FunctionSpace(),false);
656     }
657     }
658    
659     void DataTestCase::testOperations() {
660 jgs 113
661 jgs 82 cout << endl;
662    
663 jgs 113 // define the shape for the DataArrayView test data
664     DataArrayView::ShapeType shape;
665     shape.push_back(2);
666     shape.push_back(3);
667 jgs 82
668 jgs 113 // allocate the data for the DataArrayView
669     DataArrayView::ValueType data(DataArrayView::noValues(shape),0);
670 jgs 82
671 jgs 113 // construct DataArrayView
672     DataArrayView dataView(data,shape);
673 jgs 82
674 jgs 113 // assign values to the data
675     for (int i=0;i<shape[0];i++) {
676     for (int j=0;j<shape[1];j++) {
677     dataView(i,j)=dataView.index(i,j);
678     }
679     }
680    
681     Data base(dataView);
682    
683     // test unary operations
684    
685     cout << "\tTest Data::pow." << endl;
686     Data power(3.0,shape,FunctionSpace(),true);
687 jgs 82 Data result(base.powD(power));
688 jgs 113 for (int i=0;i<shape[0];i++) {
689     for (int j=0;j<shape[1];j++) {
690     assert(result.getPointDataView()(i,j) == pow(dataView.index(i,j),3.0));
691     }
692     }
693 jgs 82
694 jgs 113 cout << "\tTest Data::sin." << endl;
695 jgs 82 result.copy(base.sin());
696 jgs 102 assert(true);
697    
698 jgs 113 cout << "\tTest Data::cos." << endl;
699 jgs 82 result.copy(base.cos());
700 jgs 102 assert(true);
701    
702 jgs 113 cout << "\tTest Data::tan." << endl;
703 jgs 82 result.copy(base.tan());
704 jgs 102 assert(true);
705    
706 jgs 150 cout << "\tTest Data::asin." << endl;
707     result.copy(base.asin());
708     assert(true);
709    
710     cout << "\tTest Data::acos." << endl;
711     result.copy(base.acos());
712     assert(true);
713    
714     cout << "\tTest Data::atan." << endl;
715     result.copy(base.atan());
716     assert(true);
717    
718     cout << "\tTest Data::sinh." << endl;
719     result.copy(base.sinh());
720     assert(true);
721    
722     cout << "\tTest Data::cosh." << endl;
723     result.copy(base.cosh());
724     assert(true);
725    
726     cout << "\tTest Data::tanh." << endl;
727     result.copy(base.tanh());
728     assert(true);
729    
730     cout << "\tTest Data::asinh." << endl;
731     result.copy(base.asinh());
732     assert(true);
733    
734     cout << "\tTest Data::acosh." << endl;
735     result.copy(base.acosh());
736     assert(true);
737    
738     cout << "\tTest Data::atanh." << endl;
739     result.copy(base.atanh());
740     assert(true);
741    
742 jgs 113 cout << "\tTest Data::log." << endl;
743 jgs 82 result.copy(base.log());
744 jgs 102 assert(true);
745    
746 jgs 311 //cout << "\tTest Data::ln." << endl;
747     //result.copy(base.ln());
748     //assert(true);
749 jgs 102
750 jgs 113 cout << "\tTest Data::abs." << endl;
751 jgs 102 result.copy(base.abs());
752     assert(true);
753    
754 jgs 113 cout << "\tTest Data::sign." << endl;
755 jgs 106 result.copy(base.sign());
756 jgs 102 assert(true);
757    
758 jgs 113 cout << "\tTest Data::exp." << endl;
759 jgs 106 result.copy(base.exp());
760 jgs 102 assert(true);
761    
762 jgs 113 cout << "\tTest Data::sqrt." << endl;
763 jgs 106 result.copy(base.sqrt());
764 jgs 102 assert(true);
765    
766 jgs 113 cout << "\tTest Data::neg." << endl;
767 jgs 106 result.copy(base.neg());
768 jgs 102 assert(true);
769    
770 jgs 113 cout << "\tTest Data::pos." << endl;
771 jgs 106 result.copy(base.pos());
772 jgs 113 for (int i=0;i<shape[0];i++) {
773     for (int j=0;j<shape[1];j++) {
774     assert(result.getPointDataView()(i,j) == dataView.index(i,j));
775     }
776     }
777 jgs 102
778 jgs 113 // test reduction operations
779    
780     cout << "\tTest Data::Lsup." << endl;
781     assert(base.Lsup() == 5);
782    
783     cout << "\tTest Data::sup." << endl;
784     assert(base.sup() == 5);
785    
786     cout << "\tTest Data::inf." << endl;
787     assert(base.inf() == 0);
788    
789     // test data-point reduction operations
790    
791     cout << "\tTest Data::minval." << endl;
792 jgs 106 result.copy(base.minval());
793 jgs 113 assert(result.getPointDataView()() == 0);
794 jgs 102
795 jgs 113 cout << "\tTest Data::maxval." << endl;
796 jgs 106 result.copy(base.maxval());
797 jgs 113 assert(result.getPointDataView()() == 5);
798 jgs 102
799 jgs 311 //cout << "\tTest Data::length." << endl;
800     //result.copy(base.length());
801     //assert(pow(result.getPointDataView()(),2.0) == 55);
802 jgs 102
803 jgs 113 cout << "\tTest Data::trace." << endl;
804 jgs 106 result.copy(base.trace());
805 jgs 113 assert(result.getPointDataView()() == 15);
806 jgs 102
807 jgs 106 //result.copy(base.transpose(0));
808     //assert(true);
809    
810 jgs 82 }
811    
812 jgs 110 void DataTestCase::testRefValue() {
813    
814     //
815     // Note - this test can't be run as boost::python::numeric::array
816 jgs 113 // objects can only be created and used from within a python thread!
817 jgs 110 //
818    
819     cout << endl;
820    
821     cout << "\tTest Data object RefValue methods." << endl;
822    
823     // Create three Data object - DataExpanded, DataConstant and DataEmpty
824     DataArrayView::ShapeType viewShape;
825     viewShape.push_back(3);
826 jgs 121 DataArrayView::ValueType viewData(3);
827 jgs 110 for (int i=0;i<viewShape[0];++i) {
828 jgs 121 viewData[i]=i;
829 jgs 110 }
830     DataArrayView myView(viewData,viewShape);
831    
832     bool expanded=true;
833    
834     Data expandedData(myView,FunctionSpace(),expanded);
835     Data constantData(myView);
836     Data emptyData;
837    
838     assert(expandedData.isExpanded());
839     assert(constantData.isConstant());
840     assert(emptyData.isEmpty());
841    
842     // Check assertions are thrown for RefValue methods on DataEmpty
843    
844     int ref = 0;
845     boost::python::numeric::array num_array(1.0);
846    
847     try {
848     emptyData.getRefValue(ref,num_array);
849     assert(false);
850     }
851     catch (EsysException& e) {
852     assert(true);
853     }
854     try {
855     emptyData.setRefValue(ref,num_array);
856     assert(false);
857     }
858     catch (EsysException& e) {
859     assert(true);
860     }
861    
862     // Check assertions are thrown for RefValue methods on DataConstant
863     try {
864     constantData.getRefValue(ref,num_array);
865     assert(false);
866     }
867     catch (EsysException& e) {
868     assert(true);
869     }
870     try {
871     constantData.setRefValue(ref,num_array);
872     assert(false);
873     }
874     catch (EsysException& e) {
875     assert(true);
876     }
877    
878     // Check calls to RefValue methods on DataExpanded
879     expandedData.getRefValue(ref,num_array);
880     expandedData.setRefValue(ref,num_array);
881    
882     }
883    
884 jgs 151 void DataTestCase::testMemAlloc() {
885    
886     //
887     // Simple little sanity check for the memory allocator
888    
889     cout << endl;
890    
891     Data *testData;
892     for (int i=0; i<1000; i++) {
893     testData = new Data(0.0, DataArrayView::ShapeType(), FunctionSpace(), true);
894     delete testData;
895     }
896    
897     DataArrayView::ShapeType viewShape;
898     viewShape.push_back(10);
899     viewShape.push_back(10);
900     viewShape.push_back(10);
901    
902     Data *testData2;
903     Data *testData3 = new Data(0.0, viewShape, FunctionSpace(), true);
904     for (int i=0; i<1000; i++) {
905     testData2 = new Data(0.0, viewShape, FunctionSpace(), true);
906     delete testData2;
907     }
908     delete testData3;
909    
910     }
911    
912 jgs 82 TestSuite* DataTestCase::suite ()
913     {
914     //
915     // create the suite of tests to perform.
916     TestSuite *testSuite = new TestSuite ("DataTestCase");
917    
918     testSuite->addTest (new TestCaller< DataTestCase>("testAll",&DataTestCase::testAll));
919     testSuite->addTest (new TestCaller< DataTestCase>("testMore",&DataTestCase::testMore));
920     testSuite->addTest (new TestCaller< DataTestCase>("testDataConstant",&DataTestCase::testDataConstant));
921     testSuite->addTest (new TestCaller< DataTestCase>("testDataTagged",&DataTestCase::testDataTagged));
922     testSuite->addTest (new TestCaller< DataTestCase>("testDataTaggedExceptions",&DataTestCase::testDataTaggedExceptions));
923     testSuite->addTest (new TestCaller< DataTestCase>("testConstructors",&DataTestCase::testConstructors));
924     testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));
925     testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));
926 jgs 110 //testSuite->addTest (new TestCaller< DataTestCase>("testRefValue",&DataTestCase::testRefValue));
927 jgs 151 testSuite->addTest (new TestCaller< DataTestCase>("testMemAlloc",&DataTestCase::testMemAlloc));
928 jgs 82
929     return testSuite;
930     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26