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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 537 - (hide annotations)
Mon Feb 20 02:00:18 2006 UTC (14 years ago) by jgs
File size: 22610 byte(s)
refine/extend tests for slicing, particularly those for DataTagged

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26