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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1799 - (hide annotations)
Wed Sep 17 06:33:18 2008 UTC (11 years, 1 month ago) by jfenwick
File size: 34899 byte(s)
Added Data::copySelf() [Note: this is exposed as copy() in python].
This method returns a pointer to a deep copy of the target.
There are c++ tests but no python tests for this yet.

All DataAbstracts now have a deepCopy() which simplifies the 
implementation of the compy methods.


1 ksteube 1312
2     /* $Id$ */
3    
4     /*******************************************************
5     *
6     * Copyright 2003-2007 by ACceSS MNRF
7     * Copyright 2007 by University of Queensland
8     *
9     * http://esscc.uq.edu.au
10     * Primary Business: Queensland, Australia
11     * Licensed under the Open Software License version 3.0
12     * http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16 woo409 757 #include <iostream>
17 phornby 1026 #if (defined _WIN32) && (defined __INTEL_COMPILER)
18 woo409 757 #include <mathimf.h>
19     #else
20     #include <math.h>
21     #endif
22 jgs 511
23     #include "DataTestCase.h"
24    
25 robwdcock 670 #include "escript/FunctionSpace.h"
26 robwdcock 638 #include "esysUtils/EsysException.h"
27 jgs 82
28 robwdcock 670 #include "escript/Data.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 1799 // This is to test new copy routines, existing tests should remain where they are
69     void DataTestCase::testCopying()
70     {
71     using namespace escript::DataTypes;
72     cout << endl;
73     {
74     // first we test the deep copy
75     cout << "\tTest deep copy DataConstant" << endl;
76     DataTypes::ShapeType shape;
77     shape.push_back(2);
78     shape.push_back(3);
79     DataTypes::ValueType data(DataTypes::noValues(shape),1);
80     DataConstant* dc=new DataConstant(FunctionSpace(),shape,data);
81     Data d(dc);
82    
83     Data* deep=d.copySelf(); // test self copy
84     for (int i=0;i<DataTypes::noValues(shape);++i)
85     {
86     if (d.getDataAtOffset(i)!=deep->getDataAtOffset(i))
87     assert(false);
88     }
89     d.setToZero();
90     for (int i=0;i<DataTypes::noValues(shape);++i)
91     {
92     if (d.getDataAtOffset(i)==deep->getDataAtOffset(i))
93     assert(false);
94     }
95     d.copy(*deep); // test copy from object
96     for (int i=0;i<DataTypes::noValues(shape);++i)
97     {
98     if (d.getDataAtOffset(i)!=deep->getDataAtOffset(i))
99     assert(false);
100     }
101     d.setToZero();
102     for (int i=0;i<DataTypes::noValues(shape);++i)
103     {
104     if (d.getDataAtOffset(i)==deep->getDataAtOffset(i))
105     assert(false);
106     }
107     delete deep;
108     }
109    
110     {
111     // first we test the deep copy
112     cout << "\tTest deep copy DataExpanded" << endl;
113     DataTypes::ShapeType shape;
114     shape.push_back(2);
115     shape.push_back(3);
116     DataTypes::ValueType data(DataTypes::noValues(shape),1);
117     DataExpanded* dc=new DataExpanded(FunctionSpace(),shape,data);
118     Data d(dc);
119    
120     Data* deep=d.copySelf(); // test self copy
121     for (int i=0;i<DataTypes::noValues(shape);++i)
122     {
123     if (d.getDataAtOffset(i)!=deep->getDataAtOffset(i))
124     assert(false);
125     }
126     d.setToZero();
127     for (int i=0;i<DataTypes::noValues(shape);++i)
128     {
129     if (d.getDataAtOffset(i)==deep->getDataAtOffset(i))
130     assert(false);
131     }
132     d.copy(*deep); // test copy from object
133     for (int i=0;i<DataTypes::noValues(shape);++i)
134     {
135     if (d.getDataAtOffset(i)!=deep->getDataAtOffset(i))
136     assert(false);
137     }
138     d.setToZero();
139     for (int i=0;i<DataTypes::noValues(shape);++i)
140     {
141     if (d.getDataAtOffset(i)==deep->getDataAtOffset(i))
142     assert(false);
143     }
144     delete deep;
145     }
146     {
147     // first we test the deep copy
148     cout << "\tTest deep copy DataTagged" << endl;
149     DataTypes::ShapeType shape;
150     shape.push_back(2);
151     shape.push_back(3);
152     DataTypes::ValueType data(DataTypes::noValues(shape),1);
153     DataTagged* dc=new DataTagged(FunctionSpace(),shape,data);
154     Data d(dc);
155    
156     Data* deep=d.copySelf(); // test self copy
157     for (int i=0;i<DataTypes::noValues(shape);++i)
158     {
159     if (d.getDataAtOffset(i)!=deep->getDataAtOffset(i))
160     assert(false);
161     }
162     d.setToZero();
163     for (int i=0;i<DataTypes::noValues(shape);++i)
164     {
165     if (d.getDataAtOffset(i)==deep->getDataAtOffset(i))
166     assert(false);
167     }
168     d.copy(*deep); // test copy from object
169     for (int i=0;i<DataTypes::noValues(shape);++i)
170     {
171     if (d.getDataAtOffset(i)!=deep->getDataAtOffset(i))
172     assert(false);
173     }
174     d.setToZero();
175     for (int i=0;i<DataTypes::noValues(shape);++i)
176     {
177     if (d.getDataAtOffset(i)==deep->getDataAtOffset(i))
178     assert(false);
179     }
180     delete deep;
181     }
182    
183     }
184    
185 jgs 82 void DataTestCase::testSlicing() {
186    
187 jfenwick 1796 using namespace escript::DataTypes;
188 jgs 82 cout << endl;
189    
190     {
191 jgs 537
192     cout << "\tTest get-slicing DataConstant" << endl;
193    
194 jfenwick 1796 DataTypes::ShapeType viewShape;
195 jgs 82 viewShape.push_back(2);
196     viewShape.push_back(3);
197 jgs 537 Data data(1.3,viewShape,FunctionSpace(),false);
198    
199     //cout << data.toString() << endl;
200    
201 jfenwick 1796 DataTypes::RegionType region;
202     region.push_back(DataTypes::RegionType::value_type(0,0));
203     region.push_back(DataTypes::RegionType::value_type(0,0));
204 jgs 537
205     Data slice1(data.getSlice(region));
206    
207     //cout << slice1.toString() << endl;
208    
209     assert(slice1.getDataPointRank()==0);
210 jfenwick 1796 assert(slice1.getDataPoint(0,0)==1.3);
211 jgs 537
212 jgs 82 region.clear();
213 jfenwick 1796 region.push_back(DataTypes::RegionType::value_type(0,1));
214     region.push_back(DataTypes::RegionType::value_type(0,1));
215 jgs 537
216     Data slice2(data.getSlice(region));
217    
218     //cout << slice2.toString() << endl;
219    
220     assert(slice2.getDataPointRank()==2);
221 jfenwick 1796 int off1=slice2.getDataOffset(0,0);
222     // assert(slice2.getDataPoint(0,0)(0,0)==1.3);
223     assert(slice2.getDataAtOffset(off1+getRelIndex(slice2.getDataPointShape(),0,0))==1.3);
224 jgs 537
225     region.clear();
226 jfenwick 1796 region.push_back(DataTypes::RegionType::value_type(0,1));
227     region.push_back(DataTypes::RegionType::value_type(0,2));
228 jgs 537
229     Data slice3(data.getSlice(region));
230    
231     //cout << slice3.toString() << endl;
232    
233     assert(slice3.getDataPointRank()==2);
234 jfenwick 1796 off1=slice3.getDataOffset(0,0);
235     // assert(slice3.getDataPoint(0,0)(0,0)==1.3);
236     // assert(slice3.getDataPoint(0,0)(0,1)==1.3);
237     assert(slice3.getDataAtOffset(off1+getRelIndex(slice3.getDataPointShape(),0,0))==1.3);
238     assert(slice3.getDataAtOffset(off1+getRelIndex(slice3.getDataPointShape(),0,1))==1.3);
239 jgs 537
240 jgs 82 }
241    
242     {
243 jgs 537
244     cout << "\tTest set-slicing DataConstant" << endl;
245    
246 jfenwick 1796 DataTypes::ShapeType viewShape;
247 jgs 537 Data source(10.0,viewShape,FunctionSpace(),false);
248    
249     //cout << source.toString() << endl;
250    
251     viewShape.push_back(2);
252     viewShape.push_back(3);
253     Data target(1.3,viewShape,FunctionSpace(),false);
254    
255     //cout << target.toString() << endl;
256    
257 jfenwick 1796 DataTypes::RegionType region;
258     region.push_back(DataTypes::RegionType::value_type(0,0));
259     region.push_back(DataTypes::RegionType::value_type(0,0));
260 jgs 537
261     target.setSlice(source,region);
262    
263     //cout << target.toString() << endl;
264    
265 jfenwick 1796 int off1=target.getDataOffset(0,0);
266     assert(target.getDataAtOffset(off1+getRelIndex(target.getDataPointShape(),0,0)==source.getDataPoint(0,0)));
267 jgs 537
268     }
269    
270     {
271    
272     cout << "\tTest get-slicing DataTagged" << endl;
273 jgs 82 //
274 jgs 537 // create a DataTagged with a default value only
275    
276 jfenwick 1796 DataTypes::ShapeType viewShape;
277 jgs 82 viewShape.push_back(2);
278     viewShape.push_back(3);
279 jgs 537 Data data(1.3,viewShape,FunctionSpace(),false);
280     data.tag();
281 jfenwick 1796 data.getDataAtOffset(data.getDataOffset(0,0)+getRelIndex(viewShape,0,0))=1.0;
282     data.getDataAtOffset(data.getDataOffset(0,0)+getRelIndex(viewShape,1,1))=2.0;
283     // data.getDataPoint(0,0)(0,0)=1.0;
284     // data.getDataPoint(0,0)(1,1)=2.0;
285 jgs 537
286     //cout << data.toString() << endl;
287     //
288     // create a scalar slice
289    
290 jfenwick 1796 DataTypes::RegionType region;
291     region.push_back(DataTypes::RegionType::value_type(0,0));
292     region.push_back(DataTypes::RegionType::value_type(0,0));
293 jgs 537
294     Data slice1(data.getSlice(region));
295     //cout << slice1.toString() << endl;
296    
297     assert(slice1.isTagged());
298     assert(slice1.getDataPointRank()==0);
299 jfenwick 1796 assert(slice1.getDataPoint(0,0)==1.0);
300 jgs 82 //
301 jgs 537 // create a rank 2 slice with one value
302    
303 jgs 82 region.clear();
304 jfenwick 1796 region.push_back(DataTypes::RegionType::value_type(0,1));
305     region.push_back(DataTypes::RegionType::value_type(0,1));
306 jgs 537
307     Data slice2(data.getSlice(region));
308    
309     //cout << slice2.toString() << endl;
310    
311     assert(slice2.isTagged());
312     assert(slice2.getDataPointRank()==2);
313    
314 jfenwick 1796 assert(slice2.getDataAtOffset(slice2.getDataOffset(0,0)+getRelIndex(slice2.getDataPointShape(),0,0))==1.0);
315    
316 jgs 537 //
317     // create a rank 2 slice with four values
318    
319 jgs 82 region.clear();
320 jfenwick 1796 region.push_back(DataTypes::RegionType::value_type(0,2));
321     region.push_back(DataTypes::RegionType::value_type(0,2));
322 jgs 537
323     Data slice3(data.getSlice(region));
324    
325     //cout << slice3.toString() << endl;
326    
327     assert(slice3.isTagged());
328     assert(slice3.getDataPointRank()==2);
329 jfenwick 1796 assert(getRef(slice3,0,0,0,0)==1.0);
330     assert(getRef(slice3,0,0,0,1)==1.3);
331     assert(getRef(slice3,0,0,1,0)==1.3);
332     assert(getRef(slice3,0,0,1,1)==2.0);
333 jgs 537
334     //
335     // add a value for tag "1"
336    
337 jfenwick 1796 DataTypes::ValueType viewData(6);
338 jgs 537 for (int i=0;i<viewData.size();i++) {
339     viewData[i]=i;
340     }
341 jfenwick 1796 // DataArrayView dataView(viewData,viewShape);
342 jgs 537
343 jfenwick 1796 // data.setTaggedValueFromCPP(1, dataView);
344     data.setTaggedValueFromCPP(1, viewShape, viewData);
345 jgs 537
346 jfenwick 1796
347 jgs 537 //
348     // create a full slice
349    
350     region.clear();
351 jfenwick 1796 region.push_back(DataTypes::RegionType::value_type(0,2));
352     region.push_back(DataTypes::RegionType::value_type(0,3));
353 jgs 537
354     Data slice4(data.getSlice(region));
355    
356     //cout << slice4.toString() << endl;
357    
358     assert(slice4.isTagged());
359     assert(slice4.getDataPointRank()==2);
360 jfenwick 1796 assert(getRef(slice4,0,0,0,0)==0);
361     assert(getRef(slice4,0,0,0,1)==2);
362     assert(getRef(slice4,0,0,0,2)==4);
363     assert(getRef(slice4,0,0,1,0)==1);
364     assert(getRef(slice4,0,0,1,1)==3);
365     assert(getRef(slice4,0,0,1,2)==5);
366 jgs 537
367 jgs 82 }
368    
369     {
370 jgs 537
371     cout << "\tTest set-slicing DataTagged" << endl;
372    
373     //
374 jgs 549 // create a source DataTagged with a scalar default value only
375 jgs 537
376 jfenwick 1796 DataTypes::ShapeType viewShape;
377 jgs 537 Data source(10.0,viewShape,FunctionSpace(),false);
378     source.tag();
379    
380 jgs 549 //cout << "source:\n" << source.toString() << endl;
381 jgs 537
382 jgs 82 //
383 jgs 549 // create a target DataTagged with a rank 2 default value only
384 jgs 537
385 jgs 82 viewShape.push_back(2);
386     viewShape.push_back(3);
387 jgs 537 Data target(1.3,viewShape,FunctionSpace(),false);
388     target.tag();
389    
390 jgs 549 //cout << "target:\n" << target.toString() << endl;
391 jgs 537
392 jgs 82 //
393 jgs 537 // set a slice in target from source
394    
395 jfenwick 1796 DataTypes::RegionType region;
396     region.push_back(DataTypes::RegionType::value_type(1,1));
397     region.push_back(DataTypes::RegionType::value_type(1,1));
398 jgs 537
399     target.setSlice(source,region);
400    
401 jgs 549 //cout << "target:\n" << target.toString() << endl;
402 jgs 537
403     assert(target.isTagged());
404     assert(target.getDataPointRank()==2);
405 jfenwick 1796 assert(getRef(target,0,0,0,0)==1.3);
406     assert(getRef(target,0,0,0,1)==1.3);
407     assert(getRef(target,0,0,0,2)==1.3);
408     assert(getRef(target,0,0,1,0)==1.3);
409     assert(getRef(target,0,0,1,1)==source.getDataPoint(0,0));
410     assert(getRef(target,0,0,1,2)==1.3);
411 jgs 537
412     //
413 jgs 549 // add a value for tag "1" to target
414 jgs 537
415 jfenwick 1796 DataTypes::ValueType viewData(6);
416 jgs 537 for (int i=0;i<viewData.size();i++) {
417     viewData[i]=i;
418     }
419 jfenwick 1796 // DataArrayView dataView(viewData,viewShape);
420     //
421     // target.setTaggedValueFromCPP(1, dataView);
422     target.setTaggedValueFromCPP(1, viewShape, viewData);
423 jgs 537
424 jgs 549 //cout << "target:\n" << target.toString() << endl;
425    
426 jgs 537 //
427     // set a slice in target from source
428    
429     region.clear();
430 jfenwick 1796 region.push_back(DataTypes::RegionType::value_type(0,0));
431     region.push_back(DataTypes::RegionType::value_type(1,1));
432 jgs 537
433     target.setSlice(source,region);
434    
435 jgs 549 //cout << "target:\n" << target.toString() << endl;
436 jgs 537
437     assert(target.isTagged());
438     assert(target.getDataPointRank()==2);
439 jfenwick 1796 assert(getRef(target,0,0,0,0)==0);
440     assert(getRef(target,0,0,0,1)==source.getDataPoint(0,0));
441     assert(getRef(target,0,0,0,2)==4);
442     assert(getRef(target,0,0,1,0)==1);
443     assert(getRef(target,0,0,1,1)==3);
444     assert(getRef(target,0,0,1,2)==5);
445 jgs 537
446 jgs 549 //
447     // add a value for tag "2" to source
448    
449 jfenwick 1796 DataTypes::ShapeType viewShape2;
450     DataTypes::ValueType viewData2(1);
451 jgs 549 viewData2[0]=6;
452 jfenwick 1796 // DataArrayView dataView2(viewData2,viewShape2);
453     //
454     // source.setTaggedValueFromCPP(2, dataView2);
455     source.setTaggedValueFromCPP(2, viewShape2, viewData2);
456 jgs 549
457     //cout << "source:\n" << source.toString() << endl;
458    
459     //
460     // set a slice in target from source
461    
462     region.clear();
463 jfenwick 1796 region.push_back(DataTypes::RegionType::value_type(0,0));
464     region.push_back(DataTypes::RegionType::value_type(1,1));
465 jgs 549
466     target.setSlice(source,region);
467    
468     //cout << "target:\n" << target.toString() << endl;
469    
470     assert(target.isTagged());
471     assert(target.getDataPointRank()==2);
472    
473     // use a non-existant tag so we get a pointer to the default value
474     // ie: the first element in the data array
475     DataAbstract::ValueType::value_type* targetData=target.getSampleDataByTag(9);
476     for (int i=0; i<target.getLength(); i++) {
477     assert(targetData[i]>=0);
478     }
479     assert(targetData[0]==1.3);
480     assert(targetData[1]==1.3);
481     assert(targetData[2]==10);
482     assert(targetData[3]==10);
483     assert(targetData[4]==1.3);
484     assert(targetData[5]==1.3);
485     assert(targetData[6]==0);
486     assert(targetData[7]==1);
487     assert(targetData[8]==10);
488     assert(targetData[9]==3);
489     assert(targetData[10]==4);
490     assert(targetData[11]==5);
491     assert(targetData[12]==1.3);
492     assert(targetData[13]==1.3);
493     assert(targetData[14]==6);
494     assert(targetData[15]==10);
495     assert(targetData[16]==1.3);
496     assert(targetData[17]==1.3);
497    
498 jgs 537 }
499    
500     {
501    
502     cout << "\tTest get-slicing DataExpanded" << endl;
503    
504 jfenwick 1796 DataTypes::ShapeType viewShape;
505 jgs 537 viewShape.push_back(2);
506     viewShape.push_back(3);
507     Data temp(1.3,viewShape,FunctionSpace(),true);
508    
509 jfenwick 1796 getRef(temp,0,0,0,0)=0.0;
510     getRef(temp,0,0,1,1)=1.0;
511 jgs 537
512 jfenwick 1796 DataTypes::RegionType region;
513     region.push_back(DataTypes::RegionType::value_type(0,0));
514     region.push_back(DataTypes::RegionType::value_type(0,0));
515 jgs 537
516 jgs 82 Data slice(temp.getSlice(region));
517 jgs 537
518 jgs 82 assert(slice.getDataPointRank()==0);
519 jfenwick 1796 assert(slice.getDataPoint(0,0)==0.0);
520 jgs 537
521 jgs 82 region.clear();
522 jfenwick 1796 region.push_back(DataTypes::RegionType::value_type(0,1));
523     region.push_back(DataTypes::RegionType::value_type(0,1));
524 jgs 537
525 jgs 82 slice=temp.getSlice(region);
526 jgs 537
527 jgs 82 assert(slice.getDataPointRank()==2);
528 jfenwick 1796 assert(getRef(slice,0,0,0,0)==0.0);
529 jgs 537
530 jgs 82 region.clear();
531 jfenwick 1796 region.push_back(DataTypes::RegionType::value_type(0,2));
532     region.push_back(DataTypes::RegionType::value_type(0,2));
533 jgs 537
534 jgs 82 slice=temp.getSlice(region);
535 jgs 537
536 jfenwick 1796 assert(getRef(slice,0,0,0,0)==0.0);
537     assert(getRef(slice,0,0,1,1)==1.0);
538 jgs 537
539 jgs 82 }
540    
541     {
542    
543 jgs 537 cout << "\tTest set-slicing DataExpanded" << endl;
544    
545 jfenwick 1796 DataTypes::ShapeType viewShape;
546 jgs 82 Data source(10.0,viewShape,FunctionSpace(),true);
547 jgs 537
548 jgs 82 viewShape.push_back(2);
549     viewShape.push_back(3);
550     Data target(1.3,viewShape,FunctionSpace(),true);
551 jgs 537
552 jfenwick 1796 DataTypes::RegionType region;
553     region.push_back(DataTypes::RegionType::value_type(0,0));
554     region.push_back(DataTypes::RegionType::value_type(0,0));
555 jgs 537
556 jgs 82 target.setSlice(source,region);
557 jgs 537
558 jfenwick 1796 assert(getRef(target,0,0,0,0)==source.getDataPoint(0,0));
559 jgs 82
560     }
561    
562     }
563    
564 jgs 538 void DataTestCase::testAll() {
565 jgs 82
566     cout << endl;
567    
568     cout << "\tCreate a Data object from a DataArrayView" << endl;
569    
570 jfenwick 1796 DataTypes::ShapeType viewShape;
571 jgs 82 viewShape.push_back(3);
572 jfenwick 1796 DataTypes::ValueType viewData(3);
573 jgs 82 for (int i=0;i<viewShape[0];++i) {
574 jgs 121 viewData[i]=i;
575 jgs 82 }
576 jfenwick 1796 // DataArrayView myView(viewData,viewShape);
577 jgs 82
578     bool expanded=true;
579 jfenwick 1796 Data exData(viewData,viewShape,FunctionSpace(),expanded);
580     // Data cData(myView);
581     Data cData(viewData,viewShape,FunctionSpace());
582 jgs 82 Data result;
583    
584     assert(exData.isExpanded());
585     assert(cData.isConstant());
586     assert(result.isEmpty());
587    
588     cout << "\tTest some basic operations" << endl;
589     result=exData*cData;
590     assert(result.isExpanded());
591    
592     }
593    
594 jgs 538 void DataTestCase::testMore() {
595 jgs 82
596     cout << endl;
597    
598     cout << "\tCreate a Data object from a DataArrayView" << endl;
599    
600 jfenwick 1796 DataTypes::ShapeType viewShape;
601 jgs 82 viewShape.push_back(3);
602 jfenwick 1796 DataTypes::ValueType viewData(3);
603 jgs 82 for (int i=0;i<viewShape[0];++i) {
604 jgs 121 viewData[i]=i;
605 jgs 82 }
606 jfenwick 1796 // DataArrayView myView(viewData,viewShape);
607 jgs 82
608     bool expanded=true;
609 jfenwick 1796 Data exData(viewData,viewShape,FunctionSpace(),expanded);
610     Data cData(viewData,viewShape);
611 jgs 82 Data result;
612 jgs 123
613 jgs 82 assert(exData.isExpanded());
614     assert(cData.isConstant());
615     assert(result.isEmpty());
616    
617     cout << "\tTest some basic operations" << endl;
618     result=exData*cData;
619     assert(result.isExpanded());
620    
621 jgs 538 assert(result.Lsup()==4);
622     assert(result.sup()==4);
623     assert(result.inf()==0);
624    
625     result=exData+cData;
626     result=exData-cData;
627     result=exData/cData;
628    
629     cout << "\tExercise wherePositive method" << endl;
630     assert(!exData.wherePositive().isEmpty());
631    
632     cout << "\tExercise copyWithMask method" << endl;
633     exData.copyWithMask(result, exData.wherePositive());
634     assert(!exData.wherePositive().isEmpty());
635    
636 jgs 82 }
637    
638     void DataTestCase::testDataConstant() {
639    
640     cout << endl;
641    
642     cout << "\tCreate a DataConstant object from a DataArrayView" << endl;
643    
644 jfenwick 1796 DataTypes::ShapeType viewShape;
645 jgs 82 viewShape.push_back(2);
646     viewShape.push_back(3);
647     viewShape.push_back(4);
648 jfenwick 1796 DataTypes::ValueType viewData(2*3*4);
649     for (int i=0;i<DataTypes::noValues(viewShape);++i) {
650 jgs 121 viewData[i]=i;
651 jgs 82 }
652 jfenwick 1796 // DataArrayView myView(viewData,viewShape);
653 jgs 82
654 jfenwick 1796 Data left(viewData,viewShape);
655     Data right(viewData,viewShape);
656 jgs 82 Data result;
657    
658     cout << "\tTest some basic operations" << endl;
659    
660     result=left-right;
661    
662     assert(left.isConstant());
663     assert(right.isConstant());
664     assert(result.isConstant());
665    
666     result=left+right;
667    
668     assert(left.isConstant());
669     assert(right.isConstant());
670     assert(result.isConstant());
671    
672     assert(!result.isExpanded());
673     assert(!result.isTagged());
674    
675     }
676    
677     void DataTestCase::testDataTagged() {
678    
679     cout << endl;
680    
681 jgs 539 {
682 jgs 82
683 jgs 539 cout << "\tCreate a DataTagged object with a default value only." << endl;
684 jgs 511
685 jfenwick 1796 // DataTagged::TagListType keys;
686 jgs 511
687 jfenwick 1796 // DataTagged::ValueListType values;
688 jgs 511
689 jfenwick 1796 DataTypes::ShapeType viewShape;
690 jgs 539 viewShape.push_back(3);
691 jgs 82
692 jfenwick 1796 DataTypes::ValueType viewData(3);
693 jgs 539 for (int i=0;i<viewShape[0];i++) {
694     viewData[i]=i;
695     }
696 jfenwick 1796 /* DataArrayView defaultValue(viewData,viewShape);
697 jgs 82
698 jgs 539 bool expanded=false;
699 matt 1325
700 jfenwick 1796 Data myData(keys,values,defaultValue,FunctionSpace(),expanded);*/
701     int arr[1]={1}; // iso c++ does not like empty arrays
702     DataTagged* dt=new DataTagged(FunctionSpace(),viewShape,arr,viewData);
703     Data myData(dt);
704 jgs 511
705 jgs 539 // cout << myData.toString() << endl;
706 jgs 511
707 jgs 539 assert(!myData.isEmpty());
708     assert(myData.isTagged());
709     assert(myData.getTagNumber(0)==1);
710     assert(myData.getDataPointRank()==1);
711     assert(myData.getLength()==3);
712 jfenwick 1796
713     assert(myData.getNoValues()==3);
714     assert(myData.getDataAtOffset(0)==0.0);
715     assert(myData.getDataAtOffset(1)==1.0);
716     assert(myData.getDataAtOffset(2)==2.0);
717 jgs 82
718 jfenwick 1796 // DataArrayView myDataView = myData.getPointDataView();
719     // assert(!myDataView.isEmpty());
720     // assert(myDataView.getOffset()==0);
721     // assert(myDataView.getRank()==1);
722     // assert(myDataView.noValues()==3);
723     // assert(myDataView.getShape().size()==1);
724     // assert(myDataView(0)==0.0);
725     // assert(myDataView(1)==1.0);
726     // assert(myDataView(2)==2.0);
727 jgs 82
728 jfenwick 1796 // myDataView = myData.getDataPoint(0,0);
729     // assert(!myDataView.isEmpty());
730     // assert(myDataView.getOffset()==0);
731     // assert(myDataView.getRank()==1);
732     // assert(myDataView.noValues()==3);
733     // assert(myDataView.getShape().size()==1);
734     // assert(myDataView(0)==0.0);
735     // assert(myDataView(1)==1.0);
736     // assert(myDataView(2)==2.0);
737 jgs 82
738 jgs 539 double* sampleData=myData.getSampleData(0);
739 jfenwick 1796 for (int i=0; i<myData.getNoValues(); i++) {
740 jgs 539 assert(sampleData[i]==i);
741     }
742     // use a non-existent tag so we get a pointer to
743     // the first element of the data array
744     sampleData=myData.getSampleDataByTag(9);
745     for (int i=0; i<myData.getLength(); i++) {
746     assert(sampleData[i]==i);
747     }
748 jgs 511
749 jgs 539 cout << "\tTest setting of a tag and associated value." << endl;
750 jgs 511
751 jgs 539 // value for tag "1"
752 jfenwick 1796 DataTypes::ValueType eTwoData(viewData);
753     // DataArrayView eTwoView(eTwoData, viewShape);
754     for (int i=0;i<viewShape[0];i++) {
755     eTwoData[i]=i+2.0;
756 jgs 539 }
757    
758 jfenwick 1796 myData.setTaggedValueFromCPP(1,viewShape, eTwoData);
759 jgs 539
760     assert(myData.getLength()==6);
761    
762 jfenwick 1796 int offset=myData.getDataOffset(0,0);
763     // myDataView = myData.getDataPoint(0,0);
764     // assert(myDataView==eTwoView);
765     // assert(!myDataView.isEmpty());
766     assert(offset==3);
767     assert(myData.getDataPointRank()==1);
768     assert(myData.getNoValues()==3);
769     // assert(myDataView.getShape().size()==1);
770 jgs 539
771 jfenwick 1796 assert(myData.getDataAtOffset(offset+0)==2);
772     assert(myData.getDataAtOffset(offset+1)==3);
773     assert(myData.getDataAtOffset(offset+2)==4);
774    
775 jgs 539 sampleData=myData.getSampleDataByTag(1);
776 jfenwick 1796 for (int i=0; i<myData.getNoValues(); i++) {
777 jgs 539 assert(sampleData[i]==i+2);
778     }
779    
780 jgs 511 }
781    
782 jgs 539 {
783 jgs 511
784 jgs 539 cout << "\tCreate a DataTagged object via tag() method." << endl;
785 jgs 511
786 jfenwick 1796 DataTypes::ShapeType viewShape;
787 jgs 539 viewShape.push_back(2);
788     viewShape.push_back(3);
789     Data myData(1.3,viewShape,FunctionSpace(),false);
790     myData.tag();
791 jgs 511
792 jgs 539 //cout << myData.toString() << endl;
793    
794     assert(!myData.isEmpty());
795     assert(myData.isTagged());
796     assert(myData.getTagNumber(0)==1);
797     assert(myData.getDataPointRank()==2);
798     assert(myData.getLength()==6);
799    
800     // check default value
801 jfenwick 1796 // DataArrayView myDataView = myData.getPointDataView();
802     assert(!myData.isEmpty());
803     // assert(myDataView.getOffset()==0);
804     assert(myData.getDataPointRank()==2);
805     assert(myData.getNoValues()==6);
806     assert(myData.getDataPointShape().size()==2);
807     assert(getRef(myData,0,0)==1.3);
808     assert(getRef(myData,0,1)==1.3);
809     assert(getRef(myData,0,2)==1.3);
810     assert(getRef(myData,1,0)==1.3);
811     assert(getRef(myData,1,1)==1.3);
812     assert(getRef(myData,1,2)==1.3);
813 jgs 539
814     // check value for data-point (0,0).
815 jfenwick 1796 // myDataView = myData.getDataPoint(0,0);
816     assert(!myData.isEmpty());
817     // assert(myDataView.getOffset()==0);
818     assert(myData.getDataPointRank()==2);
819     assert(myData.getNoValues()==6);
820     assert(myData.getDataPointShape().size()==2);
821     assert(getRef(myData,0,0)==1.3);
822     assert(getRef(myData,0,1)==1.3);
823     assert(getRef(myData,0,2)==1.3);
824     assert(getRef(myData,1,0)==1.3);
825     assert(getRef(myData,1,1)==1.3);
826     assert(getRef(myData,1,2)==1.3);
827 jgs 539
828 jgs 511 }
829    
830 jgs 82 }
831    
832 jgs 538 void DataTestCase::testDataTaggedExceptions() {
833    
834     cout << endl;
835    
836     cout << "\tTest DataTagged exceptions." << endl;
837    
838     Data myData;
839    
840     try {
841     myData.getSampleDataByTag(0);;
842     assert(false);
843     }
844 phornby 1455 catch (EsysException&) {
845 jgs 538 //cout << e.what() << endl;
846     assert(true);
847     }
848    
849     try {
850 jfenwick 1796 myData.setTaggedValueFromCPP(0,DataTypes::ShapeType(), DataTypes::ValueType());;
851 jgs 538 assert(false);
852     }
853 phornby 1455 catch (EsysException&) {
854 jgs 538 //cout << e.what() << endl;
855     assert(true);
856     }
857    
858     }
859    
860 jgs 82 void DataTestCase::testConstructors() {
861    
862     cout << endl;
863    
864 jfenwick 1796 DataTypes::ShapeType viewShape;
865 jgs 82 {
866     cout << "\tCreate an Empty Data object" << endl;
867     Data temp(1.3,viewShape,FunctionSpace(),false);
868     }
869     {
870     cout << "\tCreate a rank 2 Data object" << endl;
871     viewShape.push_back(2);
872     viewShape.push_back(3);
873     Data temp(1.3,viewShape,FunctionSpace(),false);
874     }
875     }
876    
877     void DataTestCase::testOperations() {
878 jgs 113
879 jgs 82 cout << endl;
880    
881 jgs 113 // define the shape for the DataArrayView test data
882 jfenwick 1796 DataTypes::ShapeType shape;
883 jgs 113 shape.push_back(2);
884     shape.push_back(3);
885 jgs 82
886 jgs 113 // allocate the data for the DataArrayView
887 jfenwick 1796 DataTypes::ValueType data(DataTypes::noValues(shape),0);
888 jgs 82
889 jgs 113 // construct DataArrayView
890 jfenwick 1796 // DataArrayView dataView(data,shape);
891 jgs 82
892 jgs 113 // assign values to the data
893     for (int i=0;i<shape[0];i++) {
894     for (int j=0;j<shape[1];j++) {
895 jfenwick 1796 data[getRelIndex(shape,i,j)]=getRelIndex(shape,i,j);
896 jgs 113 }
897     }
898    
899 jfenwick 1796 Data baseEx(data,shape,FunctionSpace(),true);
900     Data baseCon(data,shape,FunctionSpace(),false);
901     Data baseTag(data,shape,FunctionSpace(),false);
902 jgs 563 baseTag.tag();
903 jgs 113
904 jgs 563 assert(baseEx.isExpanded());
905     assert(baseCon.isConstant());
906     assert(baseTag.isTagged());
907    
908     Data resultEx;
909     Data resultCon;
910     Data resultTag;
911    
912 jgs 113 // test unary operations
913    
914 gross 713 double tmp;
915 jgs 113 cout << "\tTest Data::pow." << endl;
916     Data power(3.0,shape,FunctionSpace(),true);
917 jgs 563 resultEx.copy(baseEx.powD(power));
918     resultCon.copy(baseCon.powD(power));
919     resultTag.copy(baseTag.powD(power));
920 jgs 113 for (int i=0;i<shape[0];i++) {
921     for (int j=0;j<shape[1];j++) {
922 jfenwick 1796 tmp=pow((double)data[getRelIndex(shape,i,j)],(double)3.0);
923     assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
924     assert(std::abs(getRef(resultCon,i,j) - tmp) <= REL_TOL*std::abs(tmp));
925     assert(std::abs(getRef(resultTag,i,j) - tmp) <= REL_TOL*std::abs(tmp));
926 jgs 113 }
927     }
928 jgs 82
929 jgs 113 cout << "\tTest Data::sin." << endl;
930 jgs 563 resultEx.copy(baseEx.sin());
931     resultCon.copy(baseCon.sin());
932     resultTag.copy(baseTag.sin());
933 gross 713 for (int i=0;i<shape[0];i++) {
934     for (int j=0;j<shape[1];j++) {
935 jfenwick 1796 tmp=sin((double)data[getRelIndex(shape,i,j)]);
936     assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
937     assert(std::abs(getRef(resultCon,i,j) - tmp) <= REL_TOL*std::abs(tmp));
938     assert(std::abs(getRef(resultTag,i,j) - tmp) <= REL_TOL*std::abs(tmp));
939 gross 713 }
940     }
941 jgs 102
942 jgs 113 cout << "\tTest Data::cos." << endl;
943 jgs 563 resultEx.copy(baseEx.cos());
944     resultCon.copy(baseCon.cos());
945     resultTag.copy(baseTag.cos());
946 gross 713 for (int i=0;i<shape[0];i++) {
947     for (int j=0;j<shape[1];j++) {
948 jfenwick 1796 tmp=cos((double)data[getRelIndex(shape,i,j)]);
949     assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
950     assert(std::abs(getRef(resultCon,i,j) - tmp) <= REL_TOL*std::abs(tmp));
951     assert(std::abs(getRef(resultTag,i,j) - tmp) <= REL_TOL*std::abs(tmp));
952 gross 713 }
953     }
954 jgs 102
955 jgs 113 cout << "\tTest Data::tan." << endl;
956 jgs 563 resultEx.copy(baseEx.tan());
957     resultCon.copy(baseCon.tan());
958     resultTag.copy(baseTag.tan());
959 gross 713 for (int i=0;i<shape[0];i++) {
960     for (int j=0;j<shape[1];j++) {
961 jfenwick 1796 tmp=tan((double)data[getRelIndex(shape,i,j)]);
962     assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
963     assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
964     assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
965 gross 713 }
966     }
967 jgs 102
968 jgs 150 cout << "\tTest Data::asin." << endl;
969 jgs 563 resultEx.copy(baseEx.asin());
970     resultCon.copy(baseCon.asin());
971     resultTag.copy(baseTag.asin());
972 jgs 150 assert(true);
973    
974     cout << "\tTest Data::acos." << endl;
975 jgs 563 resultEx.copy(baseEx.acos());
976     resultCon.copy(baseCon.acos());
977     resultTag.copy(baseTag.acos());
978 jgs 150 assert(true);
979    
980     cout << "\tTest Data::atan." << endl;
981 jgs 563 resultEx.copy(baseEx.atan());
982     resultCon.copy(baseCon.atan());
983     resultTag.copy(baseTag.atan());
984 gross 713 for (int i=0;i<shape[0];i++) {
985     for (int j=0;j<shape[1];j++) {
986 jfenwick 1796 tmp=atan((double)data[getRelIndex(shape,i,j)]);
987     assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
988     assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
989     assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
990 gross 713 }
991     }
992 jgs 150
993     cout << "\tTest Data::sinh." << endl;
994 jgs 563 resultEx.copy(baseEx.sinh());
995     resultCon.copy(baseCon.sinh());
996     resultTag.copy(baseTag.sinh());
997 gross 713 for (int i=0;i<shape[0];i++) {
998     for (int j=0;j<shape[1];j++) {
999 jfenwick 1796 tmp=sinh((double)data[getRelIndex(shape,i,j)]);
1000     assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
1001     assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1002     assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1003 gross 713 }
1004     }
1005 jgs 150
1006     cout << "\tTest Data::cosh." << endl;
1007 jgs 563 resultEx.copy(baseEx.cosh());
1008     resultCon.copy(baseCon.cosh());
1009     resultTag.copy(baseTag.cosh());
1010 gross 713 for (int i=0;i<shape[0];i++) {
1011     for (int j=0;j<shape[1];j++) {
1012 jfenwick 1796 tmp=cosh((double)data[getRelIndex(shape,i,j)]);
1013     assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
1014     assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1015     assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1016 gross 713 }
1017     }
1018 jgs 150
1019     cout << "\tTest Data::tanh." << endl;
1020 jgs 563 resultEx.copy(baseEx.tanh());
1021     resultCon.copy(baseCon.tanh());
1022     resultTag.copy(baseTag.tanh());
1023 gross 713 for (int i=0;i<shape[0];i++) {
1024     for (int j=0;j<shape[1];j++) {
1025 jfenwick 1796 tmp=tanh((double)data[getRelIndex(shape,i,j)]);
1026     assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
1027     assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1028     assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1029 gross 713 }
1030     }
1031 jgs 150
1032     cout << "\tTest Data::asinh." << endl;
1033 jgs 563 resultEx.copy(baseEx.asinh());
1034     resultCon.copy(baseCon.asinh());
1035     resultTag.copy(baseTag.asinh());
1036 jgs 150 assert(true);
1037    
1038     cout << "\tTest Data::acosh." << endl;
1039 jgs 563 resultEx.copy(baseEx.acosh());
1040     resultCon.copy(baseCon.acosh());
1041     resultTag.copy(baseTag.acosh());
1042 jgs 150 assert(true);
1043    
1044     cout << "\tTest Data::atanh." << endl;
1045 jgs 563 resultEx.copy(baseEx.atanh());
1046     resultCon.copy(baseCon.atanh());
1047     resultTag.copy(baseTag.atanh());
1048 jgs 150 assert(true);
1049    
1050 jgs 113 cout << "\tTest Data::log." << endl;
1051 jgs 563 resultEx.copy(baseEx.log());
1052     resultCon.copy(baseCon.log());
1053     resultTag.copy(baseTag.log());
1054 jgs 102 assert(true);
1055    
1056 jgs 113 cout << "\tTest Data::abs." << endl;
1057 jgs 563 resultEx.copy(baseEx.abs());
1058     resultCon.copy(baseCon.abs());
1059     resultTag.copy(baseTag.abs());
1060 gross 713 for (int i=0;i<shape[0];i++) {
1061     for (int j=0;j<shape[1];j++) {
1062 jfenwick 1796 tmp=abs((double)data[getRelIndex(shape,i,j)]);
1063     assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
1064     assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1065     assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1066 gross 713 }
1067     }
1068 jgs 102
1069 jgs 113 cout << "\tTest Data::sign." << endl;
1070 jgs 563 resultEx.copy(baseEx.sign());
1071     resultCon.copy(baseCon.sign());
1072     resultTag.copy(baseTag.sign());
1073 jgs 102 assert(true);
1074    
1075 jgs 113 cout << "\tTest Data::exp." << endl;
1076 jgs 563 resultEx.copy(baseEx.exp());
1077     resultCon.copy(baseCon.exp());
1078     resultTag.copy(baseTag.exp());
1079 gross 713 for (int i=0;i<shape[0];i++) {
1080     for (int j=0;j<shape[1];j++) {
1081 jfenwick 1796 tmp=exp((double)data[getRelIndex(shape,i,j)]);
1082     assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
1083     assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1084     assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1085 gross 713 }
1086     }
1087 jgs 102
1088 jgs 113 cout << "\tTest Data::sqrt." << endl;
1089 jgs 563 resultEx.copy(baseEx.sqrt());
1090     resultCon.copy(baseCon.sqrt());
1091     resultTag.copy(baseTag.sqrt());
1092 gross 713 for (int i=0;i<shape[0];i++) {
1093     for (int j=0;j<shape[1];j++) {
1094 jfenwick 1796 tmp=sqrt((double)data[getRelIndex(shape,i,j)]);
1095     assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
1096     assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1097     assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1098 gross 713 }
1099     }
1100 jgs 102
1101 jgs 113 cout << "\tTest Data::neg." << endl;
1102 jgs 563 resultEx.copy(baseEx.neg());
1103     resultCon.copy(baseCon.neg());
1104     resultTag.copy(baseTag.neg());
1105 jgs 102 assert(true);
1106    
1107 jgs 113 cout << "\tTest Data::pos." << endl;
1108 jgs 563 resultEx.copy(baseEx.pos());
1109     resultCon.copy(baseCon.pos());
1110     resultTag.copy(baseTag.pos());
1111 jgs 113 for (int i=0;i<shape[0];i++) {
1112     for (int j=0;j<shape[1];j++) {
1113 jfenwick 1796 assert(std::abs(getRef(resultEx,i,j) - getRelIndex(shape,i,j)) <= REL_TOL*std::abs(data[getRelIndex(shape,i,j)]));
1114     assert(std::abs(getRef(resultCon,i,j) - getRelIndex(shape,i,j)) <= REL_TOL*std::abs(data[getRelIndex(shape,i,j)]));
1115     assert(std::abs(getRef(resultTag,i,j) - getRelIndex(shape,i,j)) <= REL_TOL*std::abs(data[getRelIndex(shape,i,j)]));
1116 jgs 113 }
1117     }
1118 jgs 102
1119 jgs 113 // test reduction operations
1120    
1121     cout << "\tTest Data::Lsup." << endl;
1122 gross 713 assert(std::abs(baseEx.Lsup() - 5) <= REL_TOL*5);
1123     assert(std::abs(baseCon.Lsup() - 5) <= REL_TOL*5);
1124     assert(std::abs(baseTag.Lsup() - 5) <= REL_TOL*5);
1125 jgs 113
1126     cout << "\tTest Data::sup." << endl;
1127 gross 713 assert(std::abs(baseEx.sup() - 5) <= REL_TOL*5);
1128     assert(std::abs(baseCon.sup() - 5) <= REL_TOL*5);
1129     assert(std::abs(baseTag.sup() - 5) <= REL_TOL*5);
1130 jgs 113
1131     cout << "\tTest Data::inf." << endl;
1132 gross 713 assert(std::abs(baseEx.inf() - 0) <= REL_TOL*0);
1133     assert(std::abs(baseCon.inf() - 0) <= REL_TOL*0);
1134     assert(std::abs(baseTag.inf() - 0) <= REL_TOL*0);
1135 jgs 113
1136     // test data-point reduction operations
1137    
1138     cout << "\tTest Data::minval." << endl;
1139 jgs 563 resultEx.copy(baseEx.minval());
1140     resultCon.copy(baseCon.minval());
1141     resultTag.copy(baseTag.minval());
1142 jfenwick 1796 // assert(std::abs(resultEx.getPointDataView()() - 0) <= REL_TOL*0);
1143     // assert(std::abs(resultCon.getPointDataView()() - 0) <= REL_TOL*0);
1144     // assert(std::abs(resultTag.getPointDataView()() - 0) <= REL_TOL*0);
1145     assert(std::abs(resultEx.getDataAtOffset(0) - 0) <= REL_TOL*0);
1146     assert(std::abs(resultCon.getDataAtOffset(0) - 0) <= REL_TOL*0);
1147     assert(std::abs(resultTag.getDataAtOffset(0) - 0) <= REL_TOL*0);
1148 jgs 102
1149 jgs 113 cout << "\tTest Data::maxval." << endl;
1150 jgs 563 resultEx.copy(baseEx.maxval());
1151     resultCon.copy(baseCon.maxval());
1152     resultTag.copy(baseTag.maxval());
1153 jfenwick 1796 assert(std::abs(resultEx.getDataAtOffset(0) - 5) <= REL_TOL*5);
1154     assert(std::abs(resultCon.getDataAtOffset(0) - 5) <= REL_TOL*5);
1155     assert(std::abs(resultTag.getDataAtOffset(0) - 5) <= REL_TOL*5);
1156 jgs 102
1157 jgs 82 }
1158    
1159 jgs 110
1160 jgs 151 void DataTestCase::testMemAlloc() {
1161    
1162     //
1163     // Simple little sanity check for the memory allocator
1164    
1165     cout << endl;
1166    
1167     Data *testData;
1168     for (int i=0; i<1000; i++) {
1169 jfenwick 1796 testData = new Data(0.0, DataTypes::ShapeType(), FunctionSpace(), true);
1170 jgs 151 delete testData;
1171     }
1172    
1173 jfenwick 1796 DataTypes::ShapeType viewShape;
1174 jgs 151 viewShape.push_back(10);
1175     viewShape.push_back(10);
1176     viewShape.push_back(10);
1177    
1178     Data *testData2;
1179     Data *testData3 = new Data(0.0, viewShape, FunctionSpace(), true);
1180     for (int i=0; i<1000; i++) {
1181     testData2 = new Data(0.0, viewShape, FunctionSpace(), true);
1182     delete testData2;
1183     }
1184     delete testData3;
1185    
1186     }
1187    
1188 jgs 82 TestSuite* DataTestCase::suite ()
1189     {
1190     //
1191     // create the suite of tests to perform.
1192     TestSuite *testSuite = new TestSuite ("DataTestCase");
1193 jfenwick 1799 testSuite->addTest (new TestCaller< DataTestCase>("testCopying",&DataTestCase::testCopying));
1194 jgs 82 testSuite->addTest (new TestCaller< DataTestCase>("testAll",&DataTestCase::testAll));
1195     testSuite->addTest (new TestCaller< DataTestCase>("testMore",&DataTestCase::testMore));
1196     testSuite->addTest (new TestCaller< DataTestCase>("testDataConstant",&DataTestCase::testDataConstant));
1197     testSuite->addTest (new TestCaller< DataTestCase>("testDataTagged",&DataTestCase::testDataTagged));
1198     testSuite->addTest (new TestCaller< DataTestCase>("testDataTaggedExceptions",&DataTestCase::testDataTaggedExceptions));
1199     testSuite->addTest (new TestCaller< DataTestCase>("testConstructors",&DataTestCase::testConstructors));
1200     testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));
1201     testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));
1202 jgs 110 //testSuite->addTest (new TestCaller< DataTestCase>("testRefValue",&DataTestCase::testRefValue));
1203 jgs 151 testSuite->addTest (new TestCaller< DataTestCase>("testMemAlloc",&DataTestCase::testMemAlloc));
1204 jgs 82
1205     return testSuite;
1206     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26