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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2005 - (hide annotations)
Mon Nov 10 01:21:39 2008 UTC (10 years, 11 months ago) by jfenwick
File size: 34550 byte(s)
Bringing all changes across from schroedinger.
(Note this does not mean development is done, just that it will happen
on the trunk for now).
If anyone notices any problems please contact me.


1 ksteube 1312
2     /*******************************************************
3 ksteube 1811 *
4     * Copyright (c) 2003-2008 by University of Queensland
5     * Earth Systems Science Computational Center (ESSCC)
6     * http://www.uq.edu.au/esscc
7     *
8     * Primary Business: Queensland, Australia
9     * Licensed under the Open Software License version 3.0
10     * http://www.opensource.org/licenses/osl-3.0.php
11     *
12     *******************************************************/
13 ksteube 1312
14 ksteube 1811
15 woo409 757 #include <iostream>
16 phornby 1026 #if (defined _WIN32) && (defined __INTEL_COMPILER)
17 woo409 757 #include <mathimf.h>
18     #else
19     #include <math.h>
20     #endif
21 jgs 511
22     #include "DataTestCase.h"
23    
24 robwdcock 670 #include "escript/FunctionSpace.h"
25 robwdcock 638 #include "esysUtils/EsysException.h"
26 jgs 82
27 robwdcock 670 #include "escript/Data.h"
28 jfenwick 2005 #include "escript/DataLazy.h"
29 jgs 537
30 jgs 82
31     using namespace std;
32     using namespace CppUnitTest;
33     using namespace escript;
34     using namespace esysUtils;
35 jfenwick 1796 using namespace escript::DataTypes;
36 jgs 82
37     void DataTestCase::setUp() {
38     //
39     // This is called before each test is run
40     }
41    
42     void DataTestCase::tearDown() {
43     //
44     // This is called after each test has been run
45     }
46    
47 jfenwick 1796
48    
49     namespace
50     {
51    
52     inline
53     DataTypes::ValueType::reference
54     getRef(Data& d,int s1, int p1, int x, int y)
55     {
56     return d.getDataAtOffset(d.getDataOffset(s1,p1)+getRelIndex(d.getDataPointShape(),x,y));
57     }
58    
59     inline
60     DataTypes::ValueType::reference
61     getRef(Data& d, int x, int y)
62     {
63     return d.getDataAtOffset(getRelIndex(d.getDataPointShape(),x,y));
64     }
65    
66     }
67    
68 jfenwick 2005
69     void DataTestCase::testCopyingWorker(bool delayed)
70 jfenwick 1799 {
71 jfenwick 2005
72 jfenwick 1799 using namespace escript::DataTypes;
73     cout << endl;
74 jfenwick 2005
75     DataTypes::ShapeType shape;
76     shape.push_back(2);
77     shape.push_back(3);
78     DataTypes::ValueType data(DataTypes::noValues(shape),1);
79     const int NUMDATS=3;
80     Data* dats[NUMDATS];
81     const char* strs[]={"DataConstant", "DataTagged", "DataExpanded"};
82     dats[0]=new Data(new DataConstant(FunctionSpace(),shape,data));
83     dats[1]=new Data(new DataTagged(FunctionSpace(),shape,data));
84     dats[2]=new Data(new DataExpanded(FunctionSpace(),shape,data));
85     if (delayed)
86 jfenwick 1799 {
87 jfenwick 2005 dats[0]->delaySelf();
88     dats[1]->delaySelf();
89     dats[2]->delaySelf();
90 jfenwick 1799 }
91    
92 jfenwick 2005 for (int k=0;k<NUMDATS;++k)
93 jfenwick 1799 {
94 jfenwick 2005 cout << "\tTest deep copy " << strs[k] << endl;
95     Data* d=dats[k];
96     Data* deep=d->copySelf(); // test self copy
97     if (delayed)
98 jfenwick 1799 {
99 jfenwick 2005 assert(deep->isLazy());
100 jfenwick 1799 }
101     for (int i=0;i<DataTypes::noValues(shape);++i)
102     {
103 jfenwick 2005 if (d->getDataAtOffset(i)!=deep->getDataAtOffset(i))
104 jfenwick 1799 assert(false);
105     }
106 jfenwick 2005 if (delayed)
107 jfenwick 1799 {
108 jfenwick 2005 d->delaySelf();
109 jfenwick 1799 }
110 jfenwick 2005 d->setToZero();
111     if (delayed)
112 jfenwick 1799 {
113 jfenwick 2005 assert(d->isLazy());
114 jfenwick 1799 }
115     for (int i=0;i<DataTypes::noValues(shape);++i)
116     {
117 jfenwick 2005 if (d->getDataAtOffset(i)==deep->getDataAtOffset(i))
118 jfenwick 1799 assert(false);
119     }
120 jfenwick 2005 if (delayed)
121 jfenwick 1799 {
122 jfenwick 2005 d->delaySelf();
123     deep->delaySelf();
124 jfenwick 1799 }
125 jfenwick 2005 d->copy(*deep); // test copy from object
126     if (delayed)
127     {
128     assert(d->isLazy());
129     }
130 jfenwick 1799 for (int i=0;i<DataTypes::noValues(shape);++i)
131     {
132 jfenwick 2005 if (d->getDataAtOffset(i)!=deep->getDataAtOffset(i))
133 jfenwick 1799 assert(false);
134     }
135 jfenwick 2005 d->setToZero();
136 jfenwick 1799 for (int i=0;i<DataTypes::noValues(shape);++i)
137     {
138 jfenwick 2005 if (d->getDataAtOffset(i)==deep->getDataAtOffset(i))
139 jfenwick 1799 assert(false);
140     }
141     delete deep;
142 jfenwick 2005 delete dats[k];
143 jfenwick 1799 }
144    
145    
146 jgs 82
147    
148 jgs 537
149    
150 jfenwick 2005 }
151 jgs 537
152    
153 jfenwick 2005 void DataTestCase::testSlicingWorker(bool delayed)
154     {
155 jgs 537
156 jfenwick 2005 using namespace escript::DataTypes;
157     cout << endl;
158     {
159     DataTypes::ShapeType viewShape;
160     viewShape.push_back(2);
161     viewShape.push_back(3);
162 jgs 537
163 jfenwick 2005 const int NUMDATS=3;
164     const char* strs[]={"DataConstant", "DataTagged","DataExpanded"};
165     bool tags[]={false,true,false}; // is the slice of this data supposed to be tagged
166     Data* dats[NUMDATS];
167     for (int k=0;k<NUMDATS;++k)
168     {
169     dats[k]=new Data(1.3, viewShape);
170     }
171     dats[1]->tag();
172     dats[2]->expand();
173     for (int k=0;k<NUMDATS;++k)
174     {
175     Data* temp=dats[k];
176     dats[k]=new Data(dats[k]->delay());
177     delete temp;
178     }
179     for (int k=0;k<NUMDATS;++k)
180     {
181     cout << "\t\tTest get-slicing " << strs[k] << endl;
182     dats[k]->getDataAtOffset(dats[k]->getDataOffset(0,0)+getRelIndex(viewShape,0,0))=1.0;
183     dats[k]->getDataAtOffset(dats[k]->getDataOffset(0,0)+getRelIndex(viewShape,1,1))=2.0;
184 jgs 537
185 jfenwick 2005 DataTypes::RegionType region;
186     region.push_back(DataTypes::RegionType::value_type(0,0));
187     region.push_back(DataTypes::RegionType::value_type(0,0));
188 jgs 537
189 jfenwick 2005 Data slice1(dats[k]->getSlice(region));
190 jgs 537
191 jfenwick 2005 if (tags[k]) {assert(slice1.isTagged());}
192     assert(slice1.getDataPointRank()==0);
193     assert(slice1.getDataPoint(0,0)==1.0);
194 jgs 537
195 jfenwick 2005 //
196     // create a rank 2 slice with one value
197    
198     region.clear();
199     region.push_back(DataTypes::RegionType::value_type(0,1));
200     region.push_back(DataTypes::RegionType::value_type(0,1));
201    
202     Data slice2(dats[k]->getSlice(region));
203    
204     //cout << slice2.toString() << endl;
205    
206     if (tags[k]) {assert(slice2.isTagged());}
207     assert(slice2.getDataPointRank()==2);
208    
209     assert(slice2.getDataAtOffset(slice2.getDataOffset(0,0)+getRelIndex(slice2.getDataPointShape(),0,0))==1.0);
210 jgs 537
211 jfenwick 2005 //
212     // create a rank 2 slice with four values
213    
214     region.clear();
215     region.push_back(DataTypes::RegionType::value_type(0,2));
216     region.push_back(DataTypes::RegionType::value_type(0,2));
217    
218     Data slice3(dats[k]->getSlice(region));
219    
220     //cout << slice3.toString() << endl;
221    
222     if (tags[k]) {assert(slice3.isTagged());}
223     assert(slice3.getDataPointRank()==2);
224     assert(getRef(slice3,0,0,0,0)==1.0);
225     assert(getRef(slice3,0,0,0,1)==1.3);
226     assert(getRef(slice3,0,0,1,0)==1.3);
227     assert(getRef(slice3,0,0,1,1)==2.0);
228     }
229 jgs 537
230 jfenwick 2005 // now some extra tests for tagged data (dats[1])
231 jgs 537
232 jfenwick 2005 //
233     // add a value for tag "1"
234 jgs 537
235 jfenwick 2005 DataTypes::ValueType viewData(6);
236     for (int i=0;i<viewData.size();i++) {
237     viewData[i]=i;
238     }
239     dats[1]->setTaggedValueFromCPP(1, viewShape, viewData);
240 jgs 537
241 jfenwick 2005 //
242     // create a full slice
243 jgs 537
244 jfenwick 2005 DataTypes::RegionType region;
245     region.push_back(DataTypes::RegionType::value_type(0,2));
246     region.push_back(DataTypes::RegionType::value_type(0,3));
247 jgs 82
248 jfenwick 2005 Data slice4(dats[1]->getSlice(region));
249 jgs 537
250 jfenwick 2005 assert(slice4.isTagged());
251     assert(slice4.getDataPointRank()==2);
252     assert(getRef(slice4,0,0,0,0)==0);
253     assert(getRef(slice4,0,0,0,1)==2);
254     assert(getRef(slice4,0,0,0,2)==4);
255     assert(getRef(slice4,0,0,1,0)==1);
256     assert(getRef(slice4,0,0,1,1)==3);
257     assert(getRef(slice4,0,0,1,2)==5);
258 jgs 537
259 jfenwick 2005 for (int k=0;k<NUMDATS;++k)
260     {
261     delete dats[k];
262     }
263     }
264 jgs 537
265 jfenwick 2005 {
266     DataTypes::ShapeType viewShape;
267     viewShape.push_back(2);
268     viewShape.push_back(3);
269 jgs 537
270 jfenwick 2005 const int NUMDATS=3;
271     const char* strs[]={"DataConstant", "DataTagged","DataExpanded"};
272     bool tags[]={false,true,false}; // is the slice of this data supposed to be tagged
273     Data* dats[NUMDATS];
274     Data* src[NUMDATS];
275     for (int k=0;k<NUMDATS;++k)
276     {
277     dats[k]=new Data(1.3, viewShape);
278     src[k]=new Data(10,DataTypes::scalarShape);
279 jgs 537 }
280 jfenwick 2005 dats[1]->tag();
281     src[1]->tag();
282     dats[2]->expand();
283     src[2]->expand();
284     if (delayed)
285 jgs 537 {
286 jfenwick 2005 for(int k=0;k<NUMDATS;++k)
287     {
288     if (delayed)
289     {
290     Data* temp=dats[k];
291     dats[k]=new Data(dats[k]->delay()); // coz delay returns an object not a pointer
292     delete temp;
293     temp=src[k];
294     src[k]=new Data(src[k]->delay());
295     delete temp;
296     }
297 jgs 537 }
298 jgs 82 }
299 jfenwick 2005 for (int k=0;k<NUMDATS;++k)
300 jgs 82 {
301 jfenwick 2005 cout << "\t\tTest set-slicing " << strs[k] << endl;
302     Data target(1.3,viewShape);
303     if (k==2) {target.expand();}
304     DataTypes::RegionType region;
305     region.push_back(DataTypes::RegionType::value_type(1,1));
306     region.push_back(DataTypes::RegionType::value_type(1,1));
307     target.setSlice(*(src[k]),region);
308     assert(getRef(target,0,0,1,1)==src[k]->getDataPoint(0,0));
309     }
310    
311     // some extra tests on tagged data
312 jgs 537
313 jfenwick 2005 //
314     // add a value for tag "1" to target
315 jgs 537
316 jfenwick 2005 DataTypes::ValueType viewData(6);
317     for (int i=0;i<viewData.size();i++) {
318     viewData[i]=i;
319     }
320 jgs 537
321 jfenwick 2005 Data target(1.3,viewShape,FunctionSpace(),false);
322     target.tag();
323     target.setTaggedValueFromCPP(1, viewShape, viewData);
324 jgs 537
325 jgs 549 //cout << "target:\n" << target.toString() << endl;
326 jgs 537
327 jgs 82 //
328 jgs 537 // set a slice in target from source
329    
330 jfenwick 2005 DataTypes::RegionType region;
331     region.push_back(DataTypes::RegionType::value_type(0,0));
332     region.push_back(DataTypes::RegionType::value_type(1,1));
333 jgs 537
334 jfenwick 2005 target.setSlice(*src[1],region);
335 jgs 537
336 jfenwick 2005 assert(target.isTagged());
337     assert(target.getDataPointRank()==2);
338     assert(getRef(target,0,0,0,0)==0);
339     assert(getRef(target,0,0,0,1)==src[1]->getDataPoint(0,0));
340     assert(getRef(target,0,0,0,2)==4);
341     assert(getRef(target,0,0,1,0)==1);
342     assert(getRef(target,0,0,1,1)==3);
343     assert(getRef(target,0,0,1,2)==5);
344 jgs 537
345 jfenwick 2005 //
346     // add a value for tag "2" to source
347 jgs 537
348 jfenwick 2005 DataTypes::ShapeType viewShape2;
349     DataTypes::ValueType viewData2(1);
350     viewData2[0]=6;
351     src[1]->setTaggedValueFromCPP(2, viewShape2, viewData2);
352 jgs 537
353 jfenwick 2005 region.clear();
354     region.push_back(DataTypes::RegionType::value_type(0,0));
355     region.push_back(DataTypes::RegionType::value_type(1,1));
356 jgs 537
357 jfenwick 2005 target.setSlice(*src[1],region);
358 jgs 549
359 jfenwick 2005 assert(target.isTagged());
360     assert(target.getDataPointRank()==2);
361 jgs 537
362 jgs 549 // use a non-existant tag so we get a pointer to the default value
363     // ie: the first element in the data array
364 jfenwick 2005 DataAbstract::ValueType::value_type* targetData=target.getSampleDataByTag(9);
365     for (int i=0; i<target.getLength(); i++) {
366 jgs 549 assert(targetData[i]>=0);
367 jgs 537 }
368 jfenwick 2005 assert(targetData[0]==1.3);
369     assert(targetData[1]==1.3);
370     assert(targetData[2]==10);
371     assert(targetData[3]==1.3);
372     assert(targetData[4]==1.3);
373     assert(targetData[5]==1.3);
374     assert(targetData[6]==0);
375     assert(targetData[7]==1);
376     assert(targetData[8]==10);
377     assert(targetData[9]==3);
378     assert(targetData[10]==4);
379     assert(targetData[11]==5);
380     assert(targetData[12]==1.3);
381     assert(targetData[13]==1.3);
382     assert(targetData[14]==6);
383     assert(targetData[15]==1.3);
384     assert(targetData[16]==1.3);
385     assert(targetData[17]==1.3);
386 jgs 537
387 jfenwick 2005
388     for (int k=0;k<NUMDATS;++k)
389 jgs 537 {
390 jfenwick 2005 delete dats[k];
391     delete src[k];
392 jgs 82 }
393    
394 jfenwick 2005 }
395 jgs 82
396 jfenwick 2005 }
397 jgs 537
398 jfenwick 2005 // This is to test new copy routines, existing tests should remain where they are
399     void DataTestCase::testCopying()
400     {
401     cout << "\n\tReadyData." << endl;
402     testCopyingWorker(false);
403     cout << "\n\tLazyData." << endl;
404     testCopyingWorker(true);
405 jgs 82 }
406    
407 jfenwick 2005 void DataTestCase::testSlicing() {
408     cout << "\n\tReadyData." << endl;
409     testSlicingWorker(false);
410     cout << "\n\tLazyData." << endl;
411     testSlicingWorker(true);
412 jgs 82 }
413    
414 jfenwick 2005 void DataTestCase::testSome() {
415 jgs 82
416     cout << endl;
417    
418 jfenwick 2005 cout << "\tCreate a Data object." << endl;
419 jgs 82
420 jfenwick 1796 DataTypes::ShapeType viewShape;
421 jgs 82 viewShape.push_back(3);
422 jfenwick 1796 DataTypes::ValueType viewData(3);
423 jgs 82 for (int i=0;i<viewShape[0];++i) {
424 jgs 121 viewData[i]=i;
425 jgs 82 }
426    
427     bool expanded=true;
428 jfenwick 1796 Data exData(viewData,viewShape,FunctionSpace(),expanded);
429     Data cData(viewData,viewShape);
430 jgs 82 Data result;
431 jgs 123
432 jgs 82 assert(exData.isExpanded());
433     assert(cData.isConstant());
434     assert(result.isEmpty());
435    
436     cout << "\tTest some basic operations" << endl;
437     result=exData*cData;
438     assert(result.isExpanded());
439    
440 jgs 538 assert(result.Lsup()==4);
441     assert(result.sup()==4);
442     assert(result.inf()==0);
443    
444     result=exData+cData;
445     result=exData-cData;
446     result=exData/cData;
447    
448     cout << "\tExercise wherePositive method" << endl;
449     assert(!exData.wherePositive().isEmpty());
450    
451     cout << "\tExercise copyWithMask method" << endl;
452     exData.copyWithMask(result, exData.wherePositive());
453     assert(!exData.wherePositive().isEmpty());
454    
455 jgs 82 }
456    
457 jfenwick 2005
458    
459     // This method tests to see if resolve() produces results of the correct type
460     void DataTestCase::testResolveType()
461     {
462     cout << endl;
463     cout << "\tTesting resolve()\n";
464     DataTypes::ShapeType viewShape;
465     viewShape.push_back(2);
466     viewShape.push_back(3);
467     viewShape.push_back(4);
468     DataTypes::ValueType viewData(2*3*4);
469     for (int i=0;i<DataTypes::noValues(viewShape);++i) {
470     viewData[i]=i;
471     }
472     Data c1(viewData,viewShape);
473     Data t1(viewData,viewShape);
474     Data e1(viewData,viewShape);
475     t1.tag();
476     e1.expand();
477     c1.delaySelf();
478     t1.delaySelf();
479     e1.delaySelf();
480     Data d1=c1+c1;
481     assert(d1.isLazy());
482     assert((d1.resolve(),d1.isConstant()));
483     d1=c1+t1;
484     assert(d1.isLazy());
485     assert((d1.resolve(),d1.isTagged()));
486     d1=t1+c1;
487     assert(d1.isLazy());
488     assert((d1.resolve(),d1.isTagged()));
489     d1=t1+t1;
490     assert(d1.isLazy());
491     assert((d1.resolve(),d1.isTagged()));
492     d1=c1+e1;
493     assert(d1.isLazy());
494     assert((d1.resolve(),d1.isExpanded()));
495     d1=e1+c1;
496     assert(d1.isLazy());
497     assert((d1.resolve(),d1.isExpanded()));
498     d1=e1+t1;
499     assert(d1.isLazy());
500     assert((d1.resolve(),d1.isExpanded()));
501     d1=t1+e1;
502     assert(d1.isLazy());
503     assert((d1.resolve(),d1.isExpanded()));
504     d1=e1+e1;
505     assert(d1.isLazy());
506     assert((d1.resolve(),d1.isExpanded()));
507     cout << "\tTesting tag()\n";
508     c1.tag();
509     assert(c1.isTagged());
510     t1.tag();
511     assert(t1.isTagged());
512     try
513     {
514     e1.tag();
515     assert(false); // this should have thrown
516     } catch(...) {}
517     cout << "\tTesting expand()\n";
518     Data c2(viewData,viewShape);
519     Data t2(viewData,viewShape);
520     Data e2(viewData,viewShape);
521     t2.tag();
522     e2.expand();
523     c2.delaySelf();
524     t2.delaySelf();
525     e2.delaySelf();
526     c2.expand();
527     assert(c2.isExpanded());
528     t2.expand();
529     assert(t2.isExpanded());
530     e2.expand();
531     assert(e2.isExpanded());
532     }
533    
534 jgs 82 void DataTestCase::testDataConstant() {
535    
536     cout << endl;
537    
538 jfenwick 2005 cout << "\tCreate a DataConstant object." << endl;
539 jgs 82
540 jfenwick 1796 DataTypes::ShapeType viewShape;
541 jgs 82 viewShape.push_back(2);
542     viewShape.push_back(3);
543     viewShape.push_back(4);
544 jfenwick 1796 DataTypes::ValueType viewData(2*3*4);
545     for (int i=0;i<DataTypes::noValues(viewShape);++i) {
546 jgs 121 viewData[i]=i;
547 jgs 82 }
548    
549 jfenwick 1796 Data left(viewData,viewShape);
550     Data right(viewData,viewShape);
551 jgs 82 Data result;
552    
553     cout << "\tTest some basic operations" << endl;
554    
555     result=left-right;
556    
557     assert(left.isConstant());
558     assert(right.isConstant());
559     assert(result.isConstant());
560    
561     result=left+right;
562    
563     assert(left.isConstant());
564     assert(right.isConstant());
565     assert(result.isConstant());
566    
567     assert(!result.isExpanded());
568     assert(!result.isTagged());
569    
570     }
571    
572     void DataTestCase::testDataTagged() {
573    
574     cout << endl;
575    
576 jgs 539 {
577 jgs 82
578 jgs 539 cout << "\tCreate a DataTagged object with a default value only." << endl;
579 jgs 511
580 jfenwick 1796 DataTypes::ShapeType viewShape;
581 jgs 539 viewShape.push_back(3);
582 jgs 82
583 jfenwick 1796 DataTypes::ValueType viewData(3);
584 jgs 539 for (int i=0;i<viewShape[0];i++) {
585     viewData[i]=i;
586     }
587 jfenwick 1796 int arr[1]={1}; // iso c++ does not like empty arrays
588     DataTagged* dt=new DataTagged(FunctionSpace(),viewShape,arr,viewData);
589     Data myData(dt);
590 jgs 511
591 jgs 539 assert(!myData.isEmpty());
592     assert(myData.isTagged());
593     assert(myData.getTagNumber(0)==1);
594     assert(myData.getDataPointRank()==1);
595     assert(myData.getLength()==3);
596 jfenwick 1796
597     assert(myData.getNoValues()==3);
598     assert(myData.getDataAtOffset(0)==0.0);
599     assert(myData.getDataAtOffset(1)==1.0);
600     assert(myData.getDataAtOffset(2)==2.0);
601 jgs 82
602 jgs 539 double* sampleData=myData.getSampleData(0);
603 jfenwick 1796 for (int i=0; i<myData.getNoValues(); i++) {
604 jgs 539 assert(sampleData[i]==i);
605     }
606     // use a non-existent tag so we get a pointer to
607     // the first element of the data array
608     sampleData=myData.getSampleDataByTag(9);
609     for (int i=0; i<myData.getLength(); i++) {
610     assert(sampleData[i]==i);
611     }
612 jgs 511
613 jgs 539 cout << "\tTest setting of a tag and associated value." << endl;
614 jgs 511
615 jgs 539 // value for tag "1"
616 jfenwick 1796 DataTypes::ValueType eTwoData(viewData);
617     // DataArrayView eTwoView(eTwoData, viewShape);
618     for (int i=0;i<viewShape[0];i++) {
619     eTwoData[i]=i+2.0;
620 jgs 539 }
621    
622 jfenwick 1796 myData.setTaggedValueFromCPP(1,viewShape, eTwoData);
623 jgs 539
624     assert(myData.getLength()==6);
625    
626 jfenwick 1796 int offset=myData.getDataOffset(0,0);
627     assert(offset==3);
628     assert(myData.getDataPointRank()==1);
629     assert(myData.getNoValues()==3);
630 jgs 539
631 jfenwick 1796 assert(myData.getDataAtOffset(offset+0)==2);
632     assert(myData.getDataAtOffset(offset+1)==3);
633     assert(myData.getDataAtOffset(offset+2)==4);
634    
635 jgs 539 sampleData=myData.getSampleDataByTag(1);
636 jfenwick 1796 for (int i=0; i<myData.getNoValues(); i++) {
637 jgs 539 assert(sampleData[i]==i+2);
638     }
639    
640 jgs 511 }
641    
642 jgs 539 {
643 jgs 511
644 jgs 539 cout << "\tCreate a DataTagged object via tag() method." << endl;
645 jgs 511
646 jfenwick 1796 DataTypes::ShapeType viewShape;
647 jgs 539 viewShape.push_back(2);
648     viewShape.push_back(3);
649     Data myData(1.3,viewShape,FunctionSpace(),false);
650     myData.tag();
651 jgs 511
652 jgs 539 assert(!myData.isEmpty());
653     assert(myData.isTagged());
654     assert(myData.getTagNumber(0)==1);
655     assert(myData.getDataPointRank()==2);
656     assert(myData.getLength()==6);
657    
658     // check default value
659 jfenwick 1796 assert(!myData.isEmpty());
660     assert(myData.getDataPointRank()==2);
661     assert(myData.getNoValues()==6);
662     assert(myData.getDataPointShape().size()==2);
663     assert(getRef(myData,0,0)==1.3);
664     assert(getRef(myData,0,1)==1.3);
665     assert(getRef(myData,0,2)==1.3);
666     assert(getRef(myData,1,0)==1.3);
667     assert(getRef(myData,1,1)==1.3);
668     assert(getRef(myData,1,2)==1.3);
669 jgs 539
670     // check value for data-point (0,0).
671 jfenwick 1796 // myDataView = myData.getDataPoint(0,0);
672     assert(!myData.isEmpty());
673     // assert(myDataView.getOffset()==0);
674     assert(myData.getDataPointRank()==2);
675     assert(myData.getNoValues()==6);
676     assert(myData.getDataPointShape().size()==2);
677     assert(getRef(myData,0,0)==1.3);
678     assert(getRef(myData,0,1)==1.3);
679     assert(getRef(myData,0,2)==1.3);
680     assert(getRef(myData,1,0)==1.3);
681     assert(getRef(myData,1,1)==1.3);
682     assert(getRef(myData,1,2)==1.3);
683 jgs 539
684 jgs 511 }
685    
686 jgs 82 }
687    
688 jgs 538 void DataTestCase::testDataTaggedExceptions() {
689    
690     cout << endl;
691    
692     cout << "\tTest DataTagged exceptions." << endl;
693    
694     Data myData;
695    
696     try {
697     myData.getSampleDataByTag(0);;
698     assert(false);
699     }
700 phornby 1455 catch (EsysException&) {
701 jgs 538 //cout << e.what() << endl;
702     assert(true);
703     }
704    
705     try {
706 jfenwick 1796 myData.setTaggedValueFromCPP(0,DataTypes::ShapeType(), DataTypes::ValueType());;
707 jgs 538 assert(false);
708     }
709 phornby 1455 catch (EsysException&) {
710 jgs 538 //cout << e.what() << endl;
711     assert(true);
712     }
713    
714     }
715    
716 jgs 82 void DataTestCase::testConstructors() {
717    
718     cout << endl;
719    
720 jfenwick 1796 DataTypes::ShapeType viewShape;
721 jgs 82 {
722     cout << "\tCreate an Empty Data object" << endl;
723     Data temp(1.3,viewShape,FunctionSpace(),false);
724     }
725     {
726     cout << "\tCreate a rank 2 Data object" << endl;
727     viewShape.push_back(2);
728     viewShape.push_back(3);
729     Data temp(1.3,viewShape,FunctionSpace(),false);
730     }
731     }
732    
733 jgs 113
734 jfenwick 2005 void DataTestCase::testOperations()
735     {
736    
737 jgs 82 cout << endl;
738    
739 jfenwick 2005 // define the shape for the test data
740 jfenwick 1796 DataTypes::ShapeType shape;
741 jgs 113 shape.push_back(2);
742     shape.push_back(3);
743 jgs 82
744 jfenwick 2005 // allocate the data
745 jfenwick 1796 DataTypes::ValueType data(DataTypes::noValues(shape),0);
746 jgs 82
747 jgs 113 // assign values to the data
748     for (int i=0;i<shape[0];i++) {
749     for (int j=0;j<shape[1];j++) {
750 jfenwick 1796 data[getRelIndex(shape,i,j)]=getRelIndex(shape,i,j);
751 jgs 113 }
752     }
753    
754 jfenwick 2005
755    
756     Data dats[]={Data(data,shape,FunctionSpace(),false),
757     Data(data,shape,FunctionSpace(),false),
758     Data(data,shape,FunctionSpace(),true),
759     Data(data,shape,FunctionSpace(),false),
760     Data(data,shape,FunctionSpace(),false),
761     Data(data,shape,FunctionSpace(),true)};
762     const int NUMDATS=6;
763     const int LAZY=3; // where do the lazy objects start?
764    
765     // Data baseEx(data,shape,FunctionSpace(),true);
766     // Data baseCon(data,shape,FunctionSpace(),false);
767     // Data baseTag(data,shape,FunctionSpace(),false);
768     Data& baseCon=dats[0];
769     Data& baseTag=dats[1];
770     Data& baseEx=dats[2];
771 jgs 563 baseTag.tag();
772 jfenwick 2005 dats[4].tag();
773     dats[3].delaySelf();
774     dats[4].delaySelf();
775     dats[5].delaySelf();
776 jgs 113
777 jgs 563 assert(baseEx.isExpanded());
778     assert(baseCon.isConstant());
779     assert(baseTag.isTagged());
780    
781 jfenwick 2005 Data results[NUMDATS];
782     Data& resultEx=results[0];
783     Data& resultCon=results[1];
784     Data& resultTag=results[2];
785 jgs 563
786 jfenwick 2005 // create 0 <= smalldata <= 1 for testing trig functions
787    
788     DataTypes::ValueType smalldata(DataTypes::noValues(shape),0);
789    
790     // assign values to the data
791     for (int i=0;i<shape[0];i++) {
792     for (int j=0;j<shape[1];j++) {
793     smalldata[getRelIndex(shape,i,j)]=(i==0 && j==0)?0:1.0/(getRelIndex(shape,i,j)+1);
794     }
795     }
796     Data sdats[]={Data(smalldata,shape,FunctionSpace(),false),
797     Data(smalldata,shape,FunctionSpace(),false),
798     Data(smalldata,shape,FunctionSpace(),true),
799     Data(smalldata,shape,FunctionSpace(),false),
800     Data(smalldata,shape,FunctionSpace(),false),
801     Data(smalldata,shape,FunctionSpace(),true)};
802     sdats[1].tag();
803     sdats[4].tag();
804     sdats[3].delaySelf();
805     sdats[4].delaySelf();
806     sdats[5].delaySelf();
807    
808    
809    
810 jgs 113 // test unary operations
811    
812 gross 713 double tmp;
813 jgs 113 cout << "\tTest Data::pow." << endl;
814     Data power(3.0,shape,FunctionSpace(),true);
815 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
816     {
817     results[z].copy(dats[z].powD(power));
818     if (z>=LAZY)
819     {
820     assert(results[z].isLazy());
821     }
822     }
823 jgs 113 for (int i=0;i<shape[0];i++) {
824     for (int j=0;j<shape[1];j++) {
825 jfenwick 1796 tmp=pow((double)data[getRelIndex(shape,i,j)],(double)3.0);
826 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
827     {
828     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
829     }
830 jgs 113 }
831     }
832 jgs 82
833 jgs 113 cout << "\tTest Data::sin." << endl;
834 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
835     {
836     results[z].copy(dats[z].sin());
837     if (z>=LAZY)
838     {
839     assert(results[z].isLazy());
840     }
841     }
842 gross 713 for (int i=0;i<shape[0];i++) {
843     for (int j=0;j<shape[1];j++) {
844 jfenwick 1796 tmp=sin((double)data[getRelIndex(shape,i,j)]);
845 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
846     {
847     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
848     }
849 gross 713 }
850     }
851 jgs 102
852 jgs 113 cout << "\tTest Data::cos." << endl;
853 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
854     {
855     results[z].copy(dats[z].cos());
856     if (z>=LAZY)
857     {
858     assert(results[z].isLazy());
859     }
860     }
861 gross 713 for (int i=0;i<shape[0];i++) {
862     for (int j=0;j<shape[1];j++) {
863 jfenwick 1796 tmp=cos((double)data[getRelIndex(shape,i,j)]);
864 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
865     {
866     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
867     }
868 gross 713 }
869     }
870 jgs 102
871 jgs 113 cout << "\tTest Data::tan." << endl;
872 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
873     {
874     results[z].copy(dats[z].tan());
875     if (z>=LAZY)
876     {
877     assert(results[z].isLazy());
878     }
879     }
880 gross 713 for (int i=0;i<shape[0];i++) {
881     for (int j=0;j<shape[1];j++) {
882 jfenwick 1796 tmp=tan((double)data[getRelIndex(shape,i,j)]);
883 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
884     {
885     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
886     }
887 gross 713 }
888     }
889 jgs 102
890 jgs 150 cout << "\tTest Data::asin." << endl;
891 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
892     {
893     results[z].copy(sdats[z].asin());
894     if (z>=LAZY)
895     {
896     assert(results[z].isLazy());
897     }
898     }
899     for (int i=0;i<shape[0];i++) {
900     for (int j=0;j<shape[1];j++) {
901     tmp=asin((double)smalldata[getRelIndex(shape,i,j)]);
902     for (int z=0;z<NUMDATS;++z)
903     {
904     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
905     }
906     }
907     }
908 jgs 150
909     cout << "\tTest Data::acos." << endl;
910 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
911     {
912     results[z].copy(sdats[z].acos());
913     if (z>=LAZY)
914     {
915     assert(results[z].isLazy());
916     }
917     }
918     for (int i=0;i<shape[0];i++) {
919     for (int j=0;j<shape[1];j++) {
920     tmp=acos((double)smalldata[getRelIndex(shape,i,j)]);
921     for (int z=0;z<NUMDATS;++z)
922     {
923     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
924     }
925     }
926     }
927 jgs 150
928     cout << "\tTest Data::atan." << endl;
929 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
930     {
931     results[z].copy(sdats[z].atan());
932     if (z>=LAZY)
933     {
934     assert(results[z].isLazy());
935     }
936     }
937 gross 713 for (int i=0;i<shape[0];i++) {
938     for (int j=0;j<shape[1];j++) {
939 jfenwick 2005 tmp=atan((double)smalldata[getRelIndex(shape,i,j)]);
940     for (int z=0;z<NUMDATS;++z)
941     {
942     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
943     }
944 gross 713 }
945     }
946 jgs 150
947     cout << "\tTest Data::sinh." << endl;
948 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
949     {
950     results[z].copy(dats[z].sinh());
951     if (z>=LAZY)
952     {
953     assert(results[z].isLazy());
954     }
955     }
956 gross 713 for (int i=0;i<shape[0];i++) {
957     for (int j=0;j<shape[1];j++) {
958 jfenwick 1796 tmp=sinh((double)data[getRelIndex(shape,i,j)]);
959 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
960     {
961     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
962     }
963 gross 713 }
964     }
965 jgs 150
966     cout << "\tTest Data::cosh." << endl;
967 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
968     {
969     results[z].copy(dats[z].cosh());
970     if (z>=LAZY)
971     {
972     assert(results[z].isLazy());
973     }
974     }
975 gross 713 for (int i=0;i<shape[0];i++) {
976     for (int j=0;j<shape[1];j++) {
977 jfenwick 1796 tmp=cosh((double)data[getRelIndex(shape,i,j)]);
978 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
979     {
980     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
981     }
982 gross 713 }
983     }
984 jgs 150
985     cout << "\tTest Data::tanh." << endl;
986 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
987     {
988     results[z].copy(dats[z].tanh());
989     if (z>=LAZY)
990     {
991     assert(results[z].isLazy());
992     }
993     }
994 gross 713 for (int i=0;i<shape[0];i++) {
995     for (int j=0;j<shape[1];j++) {
996 jfenwick 1796 tmp=tanh((double)data[getRelIndex(shape,i,j)]);
997 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
998     {
999     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1000     }
1001 gross 713 }
1002     }
1003 jgs 150
1004 jfenwick 2005 // rather than accomodate the different windows operations directly I'll just use inverse functions
1005 jgs 150 cout << "\tTest Data::asinh." << endl;
1006 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1007     {
1008     results[z].copy(dats[z].asinh().sinh());
1009     if (z>=LAZY)
1010     {
1011     assert(results[z].isLazy());
1012     }
1013     }
1014     for (int i=0;i<shape[0];i++) {
1015     for (int j=0;j<shape[1];j++) {
1016     tmp=data[getRelIndex(shape,i,j)];
1017     for (int z=0;z<NUMDATS;++z)
1018     {
1019     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1020     }
1021     }
1022     }
1023 jgs 150
1024     cout << "\tTest Data::acosh." << endl;
1025 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1026     {
1027     results[z].copy(dats[z].acosh().cosh());
1028     if (z>=LAZY)
1029     {
1030     assert(results[z].isLazy());
1031     }
1032     }
1033     for (int i=0;i<shape[0];i++) {
1034     for (int j=0;j<shape[1];j++) {
1035     if (i==0 && j==0) break;
1036     tmp=data[getRelIndex(shape,i,j)];
1037     for (int z=0;z<NUMDATS;++z)
1038     {
1039     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1040     }
1041     }
1042     }
1043 jgs 150
1044     cout << "\tTest Data::atanh." << endl;
1045 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1046     {
1047     results[z].copy(dats[z].tanh().atanh()); // if these are the other way around the results are
1048     if (z>=LAZY) // undefined
1049     {
1050     assert(results[z].isLazy());
1051     }
1052     }
1053     for (int i=0;i<shape[0];i++) {
1054     for (int j=0;j<shape[1];j++) {
1055     tmp=data[getRelIndex(shape,i,j)];
1056     for (int z=0;z<NUMDATS;++z)
1057     {
1058     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1059     }
1060     }
1061     }
1062 jgs 150
1063 jgs 113 cout << "\tTest Data::log." << endl;
1064 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1065     {
1066     results[z].copy(dats[z].log());
1067     if (z>=LAZY)
1068     {
1069     assert(results[z].isLazy());
1070     }
1071     }
1072     for (int i=0;i<shape[0];i++) {
1073     for (int j=0;j<shape[1];j++) {
1074     if (i==0 && j==0) break;
1075     tmp=log((double)data[getRelIndex(shape,i,j)]);
1076     for (int z=0;z<NUMDATS;++z)
1077     {
1078     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1079     }
1080     }
1081     }
1082 jgs 102
1083 jfenwick 2005 cout << "\tTest Data::log10." << endl;
1084     for (int z=0;z<NUMDATS;++z)
1085     {
1086     results[z].copy(dats[z].log10());
1087     if (z>=LAZY)
1088     {
1089     assert(results[z].isLazy());
1090     }
1091     }
1092     for (int i=0;i<shape[0];i++) {
1093     for (int j=0;j<shape[1];j++) {
1094     if (i==0 && j==0) break;
1095     tmp=log10((double)data[getRelIndex(shape,i,j)]);
1096     for (int z=0;z<NUMDATS;++z)
1097     {
1098     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1099     }
1100     }
1101     }
1102     #ifndef _WIN32
1103     cout << "\tTest Data::erf." << endl;
1104     for (int z=0;z<NUMDATS;++z)
1105     {
1106     results[z].copy(dats[z].erf());
1107     if (z>=LAZY)
1108     {
1109     assert(results[z].isLazy());
1110     }
1111     }
1112     for (int i=0;i<shape[0];i++) {
1113     for (int j=0;j<shape[1];j++) {
1114     if (i==0 && j==0) break;
1115     tmp=erf((double)data[getRelIndex(shape,i,j)]);
1116     for (int z=0;z<NUMDATS;++z)
1117     {
1118     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1119     }
1120     }
1121     }
1122     #endif
1123    
1124    
1125 jgs 113 cout << "\tTest Data::abs." << endl;
1126 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1127     {
1128     results[z].copy(dats[z].abs());
1129     if (z>=LAZY)
1130     {
1131     assert(results[z].isLazy());
1132     }
1133     }
1134 gross 713 for (int i=0;i<shape[0];i++) {
1135     for (int j=0;j<shape[1];j++) {
1136 jfenwick 1796 tmp=abs((double)data[getRelIndex(shape,i,j)]);
1137 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1138     {
1139     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1140     }
1141 gross 713 }
1142     }
1143 jgs 102
1144 jfenwick 2005 cout << "\tTest Data::sign (positive)." << endl;
1145     for (int z=0;z<NUMDATS;++z)
1146     {
1147     results[z].copy(dats[z].sign());
1148     if (z>=LAZY)
1149     {
1150     assert(results[z].isLazy());
1151     }
1152     }
1153     for (int i=0;i<shape[0];i++) {
1154     for (int j=0;j<shape[1];j++) {
1155     tmp=(i==0 && j==0)?0:1;
1156     for (int z=0;z<NUMDATS;++z)
1157     {
1158     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1159     }
1160     }
1161     }
1162 jgs 102
1163 jfenwick 2005 cout << "\tTest Data::sign (negative)." << endl;
1164     for (int z=0;z<NUMDATS;++z)
1165     {
1166     results[z].copy(dats[z].neg().sign());
1167     if (z>=LAZY)
1168     {
1169     assert(results[z].isLazy());
1170     }
1171     }
1172     for (int i=0;i<shape[0];i++) {
1173     for (int j=0;j<shape[1];j++) {
1174     tmp=(i==0 && j==0)?0:-1;
1175     for (int z=0;z<NUMDATS;++z)
1176     {
1177     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1178     }
1179     }
1180     }
1181    
1182    
1183 jgs 113 cout << "\tTest Data::exp." << endl;
1184 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1185     {
1186     results[z].copy(dats[z].exp());
1187     if (z>=LAZY)
1188     {
1189     assert(results[z].isLazy());
1190     }
1191     }
1192 gross 713 for (int i=0;i<shape[0];i++) {
1193     for (int j=0;j<shape[1];j++) {
1194 jfenwick 1796 tmp=exp((double)data[getRelIndex(shape,i,j)]);
1195 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1196     {
1197     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1198     }
1199 gross 713 }
1200     }
1201 jgs 102
1202 jgs 113 cout << "\tTest Data::sqrt." << endl;
1203 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1204     {
1205     results[z].copy(dats[z].sqrt());
1206     if (z>=LAZY)
1207     {
1208     assert(results[z].isLazy());
1209     }
1210     }
1211 gross 713 for (int i=0;i<shape[0];i++) {
1212     for (int j=0;j<shape[1];j++) {
1213 jfenwick 1796 tmp=sqrt((double)data[getRelIndex(shape,i,j)]);
1214 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1215     {
1216     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1217     }
1218 gross 713 }
1219     }
1220 jgs 102
1221 jgs 113 cout << "\tTest Data::neg." << endl;
1222 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1223     {
1224     results[z].copy(dats[z].neg());
1225     if (z>=LAZY)
1226     {
1227     assert(results[z].isLazy());
1228     }
1229     }
1230     for (int i=0;i<shape[0];i++) {
1231     for (int j=0;j<shape[1];j++) {
1232     tmp=-data[getRelIndex(shape,i,j)];
1233     for (int z=0;z<NUMDATS;++z)
1234     {
1235     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1236     }
1237     }
1238     }
1239 jgs 102
1240 jgs 113 cout << "\tTest Data::pos." << endl;
1241 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1242     {
1243     results[z].copy(dats[z].pos());
1244     if (z>=LAZY)
1245     {
1246     assert(results[z].isLazy());
1247     }
1248     }
1249 jgs 113 for (int i=0;i<shape[0];i++) {
1250     for (int j=0;j<shape[1];j++) {
1251 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1252     {
1253     assert(std::abs(getRef(results[z],i,j) - getRelIndex(shape,i,j)) <= REL_TOL*std::abs(data[getRelIndex(shape,i,j)]));
1254     }
1255 jgs 113 }
1256     }
1257 jgs 102
1258 jgs 113 // test reduction operations
1259    
1260     cout << "\tTest Data::Lsup." << endl;
1261 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1262     {
1263     assert(std::abs(dats[z].Lsup() - 5) <= REL_TOL*5);
1264     }
1265 jgs 113
1266     cout << "\tTest Data::sup." << endl;
1267 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1268     {
1269     assert(std::abs(dats[z].sup() - 5) <= REL_TOL*5);
1270     }
1271 jgs 113
1272     cout << "\tTest Data::inf." << endl;
1273 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1274     {
1275     assert(std::abs(dats[z].inf() - 0) <= REL_TOL*0);
1276     }
1277 jgs 113
1278     // test data-point reduction operations
1279    
1280     cout << "\tTest Data::minval." << endl;
1281 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1282     {
1283     results[z].copy(dats[z].minval());
1284     }
1285     for (int z=0;z<NUMDATS;++z)
1286     {
1287     assert(std::abs(results[z].getDataAtOffset(0) - 0) <= REL_TOL*0);
1288     }
1289    
1290 jgs 102
1291 jgs 113 cout << "\tTest Data::maxval." << endl;
1292 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1293     {
1294     results[z].copy(dats[z].maxval());
1295     }
1296     for (int z=0;z<NUMDATS;++z)
1297     {
1298     assert(std::abs(results[z].getDataAtOffset(0) - 5) <= REL_TOL*5);
1299     }
1300 jgs 102
1301 jgs 82 }
1302    
1303 jgs 110
1304 jfenwick 2005 // Here we test the binary operators in complex expressions
1305     void DataTestCase::testBinary()
1306     {
1307    
1308     cout << endl;
1309    
1310     // define the shape for the test data
1311     DataTypes::ShapeType shape;
1312     shape.push_back(2);
1313     shape.push_back(3);
1314    
1315     // allocate the data
1316     DataTypes::ValueType data(DataTypes::noValues(shape),0);
1317    
1318     // assign values to the data
1319     for (int i=0;i<shape[0];i++) {
1320     for (int j=0;j<shape[1];j++) {
1321     data[getRelIndex(shape,i,j)]=getRelIndex(shape,i,j)+2; // so we get no zeros
1322     }
1323     }
1324    
1325    
1326     Data one(1.0,DataTypes::scalarShape,FunctionSpace());
1327     Data two(2.0,DataTypes::scalarShape,FunctionSpace());
1328     Data dats[]={Data(data,shape,FunctionSpace(),false),
1329     Data(data,shape,FunctionSpace(),false),
1330     Data(data,shape,FunctionSpace(),true),
1331     Data(data,shape,FunctionSpace(),false),
1332     Data(data,shape,FunctionSpace(),false),
1333     Data(data,shape,FunctionSpace(),true)};
1334     dats[1].tag();
1335     dats[4].tag();
1336     const int NUMDATS=6;
1337     const int LAZY=3;
1338     dats[3].delaySelf();
1339     dats[4].delaySelf();
1340     dats[5].delaySelf();
1341     for (int z=0;z<NUMDATS;++z)
1342     {
1343     Data& a=dats[z];
1344     Data r1=(((a+a)/two)+a-a)*one; // scalar/*, matrix+-
1345     Data r2=(((a*a)/a+one)-one); // scalar+-, matrix*/
1346     Data r3=(a.powD(two)/a.powD(one)); // scalar power
1347     Data r4=a.powD(a); // matrix power
1348     if (z>LAZY)
1349     {
1350     assert(r1.isLazy() && r2.isLazy() && r3.isLazy() && r4.isLazy());
1351     }
1352     for (int i=0;i<DataTypes::noValues(shape);++i)
1353     {
1354     assert(std::abs(r1.getDataAtOffset(i)-data[i]) <= REL_TOL*data[i]);
1355     assert(std::abs(r2.getDataAtOffset(i)-data[i]) <= REL_TOL*data[i]);
1356     assert(std::abs(r3.getDataAtOffset(i)-data[i]) <= REL_TOL*data[i]);
1357     assert(std::abs(r4.getDataAtOffset(i)-pow(data[i],i)) <=REL_TOL*pow(data[i],i));
1358     }
1359     }
1360     }
1361    
1362    
1363 jgs 151 void DataTestCase::testMemAlloc() {
1364    
1365     //
1366     // Simple little sanity check for the memory allocator
1367    
1368     cout << endl;
1369    
1370     Data *testData;
1371     for (int i=0; i<1000; i++) {
1372 jfenwick 1796 testData = new Data(0.0, DataTypes::ShapeType(), FunctionSpace(), true);
1373 jgs 151 delete testData;
1374     }
1375    
1376 jfenwick 1796 DataTypes::ShapeType viewShape;
1377 jgs 151 viewShape.push_back(10);
1378     viewShape.push_back(10);
1379     viewShape.push_back(10);
1380    
1381     Data *testData2;
1382     Data *testData3 = new Data(0.0, viewShape, FunctionSpace(), true);
1383     for (int i=0; i<1000; i++) {
1384     testData2 = new Data(0.0, viewShape, FunctionSpace(), true);
1385     delete testData2;
1386     }
1387     delete testData3;
1388    
1389     }
1390    
1391 jgs 82 TestSuite* DataTestCase::suite ()
1392     {
1393     //
1394     // create the suite of tests to perform.
1395     TestSuite *testSuite = new TestSuite ("DataTestCase");
1396 jfenwick 1799 testSuite->addTest (new TestCaller< DataTestCase>("testCopying",&DataTestCase::testCopying));
1397 jfenwick 2005 testSuite->addTest (new TestCaller< DataTestCase>("testSome",&DataTestCase::testSome));
1398 jgs 82 testSuite->addTest (new TestCaller< DataTestCase>("testDataConstant",&DataTestCase::testDataConstant));
1399     testSuite->addTest (new TestCaller< DataTestCase>("testDataTagged",&DataTestCase::testDataTagged));
1400     testSuite->addTest (new TestCaller< DataTestCase>("testDataTaggedExceptions",&DataTestCase::testDataTaggedExceptions));
1401     testSuite->addTest (new TestCaller< DataTestCase>("testConstructors",&DataTestCase::testConstructors));
1402     testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));
1403     testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));
1404 jgs 110 //testSuite->addTest (new TestCaller< DataTestCase>("testRefValue",&DataTestCase::testRefValue));
1405 jgs 151 testSuite->addTest (new TestCaller< DataTestCase>("testMemAlloc",&DataTestCase::testMemAlloc));
1406 jfenwick 2005 testSuite->addTest (new TestCaller< DataTestCase>("Resolving",&DataTestCase::testResolveType));
1407 jgs 82
1408     return testSuite;
1409     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26