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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/esys2/escript/test/Data/DataTestCase.cpp revision 97 by jgs, Tue Dec 14 05:39:33 2004 UTC trunk/escript/test/Data/DataTestCase.cpp revision 538 by jgs, Mon Feb 20 03:43:25 2006 UTC
# Line 12  Line 12 
12   *                                                                           *   *                                                                           *
13   *****************************************************************************   *****************************************************************************
14  */  */
 #include "esysUtils/EsysException.h"  
 #include "escript/Data/Data.h"  
 #include "escript/Data/FunctionSpace.h"  
15    
16  #include "DataTestCase.h"  #include "DataTestCase.h"
17    
18    #include "FunctionSpace.h"
19    #include "EsysException.h"
20    
21    #include "Data.h"
22    
23  #include <iostream>  #include <iostream>
24    #include <math.h>
25    
26  using namespace std;  using namespace std;
27  using namespace CppUnitTest;  using namespace CppUnitTest;
# Line 40  void DataTestCase::testSlicing() { Line 43  void DataTestCase::testSlicing() {
43    cout << endl;    cout << endl;
44    
45    {    {
46    
47        cout << "\tTest get-slicing DataConstant" << endl;
48    
49      DataArrayView::ShapeType viewShape;      DataArrayView::ShapeType viewShape;
     //  
     // weak tests for slicing DataConstant  
     cout << "\tTest slicing DataConstant" << endl;  
50      viewShape.push_back(2);      viewShape.push_back(2);
51      viewShape.push_back(3);      viewShape.push_back(3);
52      Data temp(1.3,viewShape,FunctionSpace(),false);      Data data(1.3,viewShape,FunctionSpace(),false);
53    
54        //cout << data.toString() << endl;
55    
56      DataArrayView::RegionType region;      DataArrayView::RegionType region;
57      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataArrayView::RegionType::value_type(0,0));
58      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataArrayView::RegionType::value_type(0,0));
59      Data slice(temp.getSlice(region));  
60      assert(slice.getDataPointRank()==0);      Data slice1(data.getSlice(region));
61      assert(slice.getDataPoint(0,0)()==1.3);  
62      //      //cout << slice1.toString() << endl;
63      // try the same but this time to produce a matrix containing one value  
64        assert(slice1.getDataPointRank()==0);
65        assert(slice1.getDataPoint(0,0)()==1.3);
66    
67      region.clear();      region.clear();
68      region.push_back(DataArrayView::RegionType::value_type(0,1));      region.push_back(DataArrayView::RegionType::value_type(0,1));
69      region.push_back(DataArrayView::RegionType::value_type(0,1));      region.push_back(DataArrayView::RegionType::value_type(0,1));
70      slice=temp.getSlice(region);  
71      assert(slice.getDataPointRank()==2);      Data slice2(data.getSlice(region));
72      assert(slice.getDataPoint(0,0)(0,0)==1.3);  
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    }    }
91    
92    {    {
93    
94        cout << "\tTest set-slicing DataConstant" << endl;
95    
96      DataArrayView::ShapeType viewShape;      DataArrayView::ShapeType viewShape;
97        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      //      //
124      // weak tests for slicing DataExpanded      // create a DataTagged with a default value only
125      cout << "\tTest slicing DataExpanded" << endl;  
126        DataArrayView::ShapeType viewShape;
127      viewShape.push_back(2);      viewShape.push_back(2);
128      viewShape.push_back(3);      viewShape.push_back(3);
129      Data temp(1.3,viewShape,FunctionSpace(),true);      Data data(1.3,viewShape,FunctionSpace(),false);
130      temp.getDataPoint(0,0)(0,0)=0.0;      data.tag();
131      temp.getDataPoint(0,0)(1,1)=1.0;      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      DataArrayView::RegionType region;      DataArrayView::RegionType region;
140      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataArrayView::RegionType::value_type(0,0));
141      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataArrayView::RegionType::value_type(0,0));
142      Data slice(temp.getSlice(region));  
143      assert(slice.getDataPointRank()==0);      Data slice1(data.getSlice(region));
144      assert(slice.getDataPoint(0,0)()==0.0);  
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      //      //
152      // try the same but this time to produce a matrix containing one value      // create a rank 2 slice with one value
153    
154      region.clear();      region.clear();
155      region.push_back(DataArrayView::RegionType::value_type(0,1));      region.push_back(DataArrayView::RegionType::value_type(0,1));
156      region.push_back(DataArrayView::RegionType::value_type(0,1));      region.push_back(DataArrayView::RegionType::value_type(0,1));
157      slice=temp.getSlice(region);  
158      assert(slice.getDataPointRank()==2);      Data slice2(data.getSlice(region));
159      assert(slice.getDataPoint(0,0)(0,0)==0.0);  
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      region.clear();      region.clear();
170      region.push_back(DataArrayView::RegionType::value_type(0,2));      region.push_back(DataArrayView::RegionType::value_type(0,2));
171      region.push_back(DataArrayView::RegionType::value_type(0,2));      region.push_back(DataArrayView::RegionType::value_type(0,2));
172      slice=temp.getSlice(region);  
173      assert(slice.getDataPoint(0,0)(0,0)==0.0);      Data slice3(data.getSlice(region));
174      assert(slice.getDataPoint(0,0)(1,1)==1.0);  
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    }    }
216    
217    {    {
218    
219        cout << "\tTest set-slicing DataTagged" << endl;
220    
221        //
222        // create a DataTagged with a scalar default value only
223    
224      DataArrayView::ShapeType viewShape;      DataArrayView::ShapeType viewShape;
225        Data source(10.0,viewShape,FunctionSpace(),false);
226        source.tag();
227    
228        //cout << source.toString() << endl;
229    
230      //      //
231      // weak tests for slicing DataTagged      // create a DataTagged with a rank 2 default value only
232      cout << "\tTest slicing DataTagged" << endl;  
233      viewShape.push_back(2);      viewShape.push_back(2);
234      viewShape.push_back(3);      viewShape.push_back(3);
235      Data temp(1.3,viewShape,FunctionSpace(),false);      Data target(1.3,viewShape,FunctionSpace(),false);
236        target.tag();
237    
238        //cout << target.toString() << endl;
239    
240        //
241        // 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      // convert the data to tagged      // set a slice in target from source
273      temp.tag();  
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      temp.getDataPoint(0,0)(0,0)=0.0;      temp.getDataPoint(0,0)(0,0)=0.0;
303      temp.getDataPoint(0,0)(1,1)=1.0;      temp.getDataPoint(0,0)(1,1)=1.0;
304    
305      DataArrayView::RegionType region;      DataArrayView::RegionType region;
306      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataArrayView::RegionType::value_type(0,0));
307      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataArrayView::RegionType::value_type(0,0));
308    
309      Data slice(temp.getSlice(region));      Data slice(temp.getSlice(region));
310    
311      assert(slice.getDataPointRank()==0);      assert(slice.getDataPointRank()==0);
312      assert(slice.getDataPoint(0,0)()==0.0);      assert(slice.getDataPoint(0,0)()==0.0);
313      //  
     // try the same but this time to produce a matrix containing one value  
314      region.clear();      region.clear();
315      region.push_back(DataArrayView::RegionType::value_type(0,1));      region.push_back(DataArrayView::RegionType::value_type(0,1));
316      region.push_back(DataArrayView::RegionType::value_type(0,1));      region.push_back(DataArrayView::RegionType::value_type(0,1));
317    
318      slice=temp.getSlice(region);      slice=temp.getSlice(region);
319    
320      assert(slice.getDataPointRank()==2);      assert(slice.getDataPointRank()==2);
321      assert(slice.getDataPoint(0,0)(0,0)==0.0);      assert(slice.getDataPoint(0,0)(0,0)==0.0);
322    
323      region.clear();      region.clear();
324      region.push_back(DataArrayView::RegionType::value_type(0,2));      region.push_back(DataArrayView::RegionType::value_type(0,2));
325      region.push_back(DataArrayView::RegionType::value_type(0,2));      region.push_back(DataArrayView::RegionType::value_type(0,2));
326    
327      slice=temp.getSlice(region);      slice=temp.getSlice(region);
328    
329      assert(slice.getDataPoint(0,0)(0,0)==0.0);      assert(slice.getDataPoint(0,0)(0,0)==0.0);
330      assert(slice.getDataPoint(0,0)(1,1)==1.0);      assert(slice.getDataPoint(0,0)(1,1)==1.0);
   }  
331    
   {  
     DataArrayView::ShapeType viewShape;  
     Data source(10.0,viewShape,FunctionSpace(),false);  
     //  
     // weak tests for setting a slice of DataConstant  
     cout << "\tTest slicing DataConstant" << endl;  
     viewShape.push_back(2);  
     viewShape.push_back(3);  
     Data target(1.3,viewShape,FunctionSpace(),false);  
     DataArrayView::RegionType region;  
     region.push_back(DataArrayView::RegionType::value_type(0,0));  
     region.push_back(DataArrayView::RegionType::value_type(0,0));  
     target.setSlice(source,region);  
     assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)());  
332    }    }
333    
334    {    {
335    
336        cout << "\tTest set-slicing DataExpanded" << endl;
337    
338      DataArrayView::ShapeType viewShape;      DataArrayView::ShapeType viewShape;
339      Data source(10.0,viewShape,FunctionSpace(),true);      Data source(10.0,viewShape,FunctionSpace(),true);
340      //  
     // weak tests for setting a slice of DataConstant  
341      viewShape.push_back(2);      viewShape.push_back(2);
342      viewShape.push_back(3);      viewShape.push_back(3);
343      Data target(1.3,viewShape,FunctionSpace(),true);      Data target(1.3,viewShape,FunctionSpace(),true);
     DataArrayView::RegionType region;  
     region.push_back(DataArrayView::RegionType::value_type(0,0));  
     region.push_back(DataArrayView::RegionType::value_type(0,0));  
     target.setSlice(source,region);  
     assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)());  
   }  
344    
   {  
     DataArrayView::ShapeType viewShape;  
     Data source(10.0,viewShape,FunctionSpace(),false);  
     source.tag();  
     //  
     // weak tests for slicing DataTagged  
     cout << "\tTest slicing DataTagged" << endl;  
     viewShape.push_back(2);  
     viewShape.push_back(3);  
     Data target(1.3,viewShape,FunctionSpace(),false);  
     //  
     // convert the data to tagged  
     target.tag();  
345      DataArrayView::RegionType region;      DataArrayView::RegionType region;
346      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataArrayView::RegionType::value_type(0,0));
347      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataArrayView::RegionType::value_type(0,0));
348    
349      target.setSlice(source,region);      target.setSlice(source,region);
350    
351      assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)());      assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)());
352    
353    }    }
354    
355  }  }
356    
357  void DataTestCase::testMore() {  void DataTestCase::testAll() {
358    
359    cout << endl;    cout << endl;
360    
361    cout << "\tCreate a Data object from a DataArrayView" << endl;    cout << "\tCreate a Data object from a DataArrayView" << endl;
362    
   DataArrayView::ValueType viewData;  
363    DataArrayView::ShapeType viewShape;    DataArrayView::ShapeType viewShape;
364    viewShape.push_back(3);    viewShape.push_back(3);
365      DataArrayView::ValueType viewData(3);
366    for (int i=0;i<viewShape[0];++i) {    for (int i=0;i<viewShape[0];++i) {
367      viewData.push_back(i);      viewData[i]=i;
368    }    }
369    DataArrayView myView(viewData,viewShape);    DataArrayView myView(viewData,viewShape);
370    
# Line 210  void DataTestCase::testMore() { Line 381  void DataTestCase::testMore() {
381    result=exData*cData;    result=exData*cData;
382    assert(result.isExpanded());    assert(result.isExpanded());
383    
   assert(result.Lsup()==4);  
   assert(result.sup()==4);  
   assert(result.inf()==0);  
   
   result=exData+cData;  
   result=exData-cData;  
   result=exData/cData;  
   
   cout << "\tExercise wherePositive method" << endl;  
   assert(!exData.wherePositive().isEmpty());  
   //assert(exData.wherePositive()==exData.wherePositive());  
   
   cout << "\tExercise copyWithMask method" << endl;  
   exData.copyWithMask(result, exData.wherePositive());  
   assert(!exData.wherePositive().isEmpty());  
   
384  }  }
385    
386  void DataTestCase::testAll() {  void DataTestCase::testMore() {
387    
388    cout << endl;    cout << endl;
389    
390    cout << "\tCreate a Data object from a DataArrayView" << endl;    cout << "\tCreate a Data object from a DataArrayView" << endl;
391    
   DataArrayView::ValueType viewData;  
392    DataArrayView::ShapeType viewShape;    DataArrayView::ShapeType viewShape;
393    viewShape.push_back(3);    viewShape.push_back(3);
394      DataArrayView::ValueType viewData(3);
395    for (int i=0;i<viewShape[0];++i) {    for (int i=0;i<viewShape[0];++i) {
396      viewData.push_back(i);      viewData[i]=i;
397    }    }
398    DataArrayView myView(viewData,viewShape);    DataArrayView myView(viewData,viewShape);
399    
400    bool expanded=true;    bool expanded=true;
   
401    Data exData(myView,FunctionSpace(),expanded);    Data exData(myView,FunctionSpace(),expanded);
402    Data cData(myView);    Data cData(myView);
403    Data result;    Data result;
# Line 256  void DataTestCase::testAll() { Line 410  void DataTestCase::testAll() {
410    result=exData*cData;    result=exData*cData;
411    assert(result.isExpanded());    assert(result.isExpanded());
412    
413      assert(result.Lsup()==4);
414      assert(result.sup()==4);
415      assert(result.inf()==0);
416    
417      result=exData+cData;
418      result=exData-cData;
419      result=exData/cData;
420    
421      cout << "\tExercise wherePositive method" << endl;
422      assert(!exData.wherePositive().isEmpty());
423    
424      cout << "\tExercise copyWithMask method" << endl;
425      exData.copyWithMask(result, exData.wherePositive());
426      assert(!exData.wherePositive().isEmpty());
427    
428  }  }
429    
430  void DataTestCase::testDataConstant() {  void DataTestCase::testDataConstant() {
# Line 264  void DataTestCase::testDataConstant() { Line 433  void DataTestCase::testDataConstant() {
433    
434    cout << "\tCreate a DataConstant object from a DataArrayView" << endl;    cout << "\tCreate a DataConstant object from a DataArrayView" << endl;
435    
   DataArrayView::ValueType viewData;  
436    DataArrayView::ShapeType viewShape;    DataArrayView::ShapeType viewShape;
437    viewShape.push_back(2);    viewShape.push_back(2);
438    viewShape.push_back(3);    viewShape.push_back(3);
439    viewShape.push_back(4);    viewShape.push_back(4);
440      DataArrayView::ValueType viewData(2*3*4);
441    for (int i=0;i<DataArrayView::noValues(viewShape);++i) {    for (int i=0;i<DataArrayView::noValues(viewShape);++i) {
442      viewData.push_back(i);      viewData[i]=i;
443    }    }
444    DataArrayView myView(viewData,viewShape);    DataArrayView myView(viewData,viewShape);
445    
# Line 297  void DataTestCase::testDataConstant() { Line 466  void DataTestCase::testDataConstant() {
466    
467  }  }
468    
469    void DataTestCase::testDataTagged() {
470    
471      cout << endl;
472    
473      cout << "\tCreate a DataTagged object with a default value only." << endl;
474    
475      DataTagged::TagListType keys;
476    
477      DataTagged::ValueListType values;
478    
479      DataArrayView::ShapeType viewShape;
480      viewShape.push_back(3);
481    
482      DataArrayView::ValueType viewData(3);
483      for (int i=0;i<viewShape[0];i++) {
484        viewData[i]=i;
485      }
486      DataArrayView defaultValue(viewData,viewShape);
487    
488      bool expanded=false;
489    
490      Data myData(keys,values,defaultValue,FunctionSpace(),expanded);
491    
492      // cout << myData.toString() << endl;
493    
494      assert(!myData.isEmpty());
495      assert(myData.isTagged());
496      assert(myData.getTagNumber(0)==1);
497      assert(myData.getDataPointRank()==1);
498      assert(myData.getLength()==3);
499    
500      DataArrayView myDataView = myData.getPointDataView();
501      assert(!myDataView.isEmpty());
502      assert(myDataView.getOffset()==0);
503      assert(myDataView.getRank()==1);
504      assert(myDataView.noValues()==3);
505      assert(myDataView.getShape().size()==1);
506      assert(myDataView(0)==0.0);
507      assert(myDataView(1)==1.0);
508      assert(myDataView(2)==2.0);
509    
510      myDataView = myData.getDataPoint(0,0);
511      assert(!myDataView.isEmpty());
512      assert(myDataView.getOffset()==0);
513      assert(myDataView.getRank()==1);
514      assert(myDataView.noValues()==3);
515      assert(myDataView.getShape().size()==1);
516      assert(myDataView(0)==0.0);
517      assert(myDataView(1)==1.0);
518      assert(myDataView(2)==2.0);
519    
520      double* sampleData=myData.getSampleData(0);
521      for (int i=0; i<myDataView.noValues(); i++) {
522        assert(sampleData[i]==i);
523      }
524      // use a non-existent tag so we get a pointer to
525      // the first element of the data array
526      sampleData=myData.getSampleDataByTag(9);
527      for (int i=0; i<myData.getLength(); i++) {
528        assert(sampleData[i]==i);
529      }
530    
531      cout << "\tTest setting of a tag and associated value." << endl;
532    
533      // value for tag "1"
534      DataArray eTwo(defaultValue);
535      for (int i=0;i<eTwo.getView().getShape()[0];i++) {
536        eTwo.getView()(i)=i+2.0;
537      }
538    
539      myData.setTaggedValueFromCPP(1,eTwo.getView());
540    
541      assert(myData.getLength()==6);
542    
543      myDataView = myData.getDataPoint(0,0);
544      assert(myDataView==eTwo.getView());
545      assert(!myDataView.isEmpty());
546      assert(myDataView.getOffset()==3);
547      assert(myDataView.getRank()==1);
548      assert(myDataView.noValues()==3);
549      assert(myDataView.getShape().size()==1);
550      assert(myDataView(0)==2);
551      assert(myDataView(1)==3);
552      assert(myDataView(2)==4);
553    
554      sampleData=myData.getSampleDataByTag(1);
555      for (int i=0; i<myDataView.noValues(); i++) {
556        assert(sampleData[i]==i+2);
557      }
558    
559    }
560    
561  void DataTestCase::testDataTaggedExceptions() {  void DataTestCase::testDataTaggedExceptions() {
562    
563    cout << endl;    cout << endl;
564    
565    cout << "\tTest DataTagged operations exceptions." << endl;    cout << "\tTest DataTagged exceptions." << endl;
566    
567    Data myData;    Data myData;
568    DataArrayView myView;    DataArrayView myView;
569    
570    try {    try {
571        myData.getSampleDataByTag(0);;        myData.getSampleDataByTag(0);;
572        assert(false);        assert(false);
# Line 312  void DataTestCase::testDataTaggedExcepti Line 575  void DataTestCase::testDataTaggedExcepti
575        //cout << e.what() << endl;        //cout << e.what() << endl;
576        assert(true);        assert(true);
577    }    }
578    /*  
579    try {    try {
580        myData.setTaggedValue(0,myView);;        myData.setTaggedValueFromCPP(0,myView);;
581        assert(false);        assert(false);
582    }    }
583    catch (EsysException& e) {    catch (EsysException& e) {
584        //cout << e.what() << endl;        //cout << e.what() << endl;
585        assert(true);        assert(true);
586    }    }
   */  
   
 }  
   
 void DataTestCase::testDataTagged() {  
   
   cout << endl;  
   
   cout << "\tCreate a DataTagged object from a DataArrayView" << endl;  
   
   DataTagged::TagListType keys;  
   DataTagged::ValueListType values;  
   DataArrayView::ValueType viewData;  
   DataArrayView::ShapeType viewShape;  
   viewShape.push_back(3);  
   for (int i=0;i<viewShape[0];++i) {  
     viewData.push_back(i);  
   }  
   DataArrayView myView(viewData,viewShape);  
   
   // create tagged data with no tag values just a default  
   bool expanded=false;  
   
   Data myData(keys,values,myView,FunctionSpace(),expanded);  
   assert(myData.isTagged());  
   
   cout << "\tTest some basic operations" << endl;  
   
   Data myDataCopy(myData);  
   myDataCopy.expand();  
   assert(myDataCopy.isExpanded());  
587    
588  }  }
589    
# Line 369  void DataTestCase::testConstructors() { Line 601  void DataTestCase::testConstructors() {
601      viewShape.push_back(2);      viewShape.push_back(2);
602      viewShape.push_back(3);      viewShape.push_back(3);
603      Data temp(1.3,viewShape,FunctionSpace(),false);      Data temp(1.3,viewShape,FunctionSpace(),false);
     cout << "\tDump it toString:" << endl;  
     cout << temp.toString() << endl;  
604    }    }
605  }  }
606    
607  void DataTestCase::testOperations() {  void DataTestCase::testOperations() {
608    
609    cout << endl;    cout << endl;
610    
611    cout << "\tCreate a rank 2 Data object" << endl;    // define the shape for the DataArrayView test data
612    DataArrayView::ShapeType viewShape;    DataArrayView::ShapeType shape;
613    viewShape.push_back(2);    shape.push_back(2);
614    viewShape.push_back(3);    shape.push_back(3);
615    
616      // allocate the data for the DataArrayView
617      DataArrayView::ValueType data(DataArrayView::noValues(shape),0);
618    
619      // construct DataArrayView
620      DataArrayView dataView(data,shape);
621    
622      // assign values to the data
623      for (int i=0;i<shape[0];i++) {
624        for (int j=0;j<shape[1];j++) {
625          dataView(i,j)=dataView.index(i,j);
626        }
627      }
628    
629    Data base(2.0,viewShape,FunctionSpace(),false);    Data base(dataView);
   Data power(3.0,viewShape,FunctionSpace(),false);  
630    
631    cout << "\tPerform basic exercises of unary operations" << endl;    // test unary operations
632    
633      cout << "\tTest Data::pow." << endl;
634      Data power(3.0,shape,FunctionSpace(),true);
635    Data result(base.powD(power));    Data result(base.powD(power));
636    assert(result.getDataPoint(0,0)(0,0) == 8);    for (int i=0;i<shape[0];i++) {
637        for (int j=0;j<shape[1];j++) {
638          assert(result.getPointDataView()(i,j) == pow(dataView.index(i,j),3.0));
639        }
640      }
641    
642      cout << "\tTest Data::sin." << endl;
643    result.copy(base.sin());    result.copy(base.sin());
644    assert(true);    assert(true);
645    
646      cout << "\tTest Data::cos." << endl;
647    result.copy(base.cos());    result.copy(base.cos());
648    assert(true);    assert(true);
649    
650      cout << "\tTest Data::tan." << endl;
651    result.copy(base.tan());    result.copy(base.tan());
652    assert(true);    assert(true);
653    
654    result.copy(base.log());    cout << "\tTest Data::asin." << endl;
655      result.copy(base.asin());
656    assert(true);    assert(true);
657    
658    result.copy(base.ln());    cout << "\tTest Data::acos." << endl;
659      result.copy(base.acos());
660    assert(true);    assert(true);
661    
662    result.copy(base.abs());    cout << "\tTest Data::atan." << endl;
663      result.copy(base.atan());
664    assert(true);    assert(true);
665    
666    result.copy(base.maxval());    cout << "\tTest Data::sinh." << endl;
667      result.copy(base.sinh());
668    assert(true);    assert(true);
669    
670    result.copy(base.minval());    cout << "\tTest Data::cosh." << endl;
671      result.copy(base.cosh());
672    assert(true);    assert(true);
673    
674    result.copy(base.length());    cout << "\tTest Data::tanh." << endl;
675      result.copy(base.tanh());
676    assert(true);    assert(true);
677    
678    result.copy(base.sign());    cout << "\tTest Data::asinh." << endl;
679      result.copy(base.asinh());
680    assert(true);    assert(true);
681    
682    result.copy(base.transpose(0));    cout << "\tTest Data::acosh." << endl;
683      result.copy(base.acosh());
684    assert(true);    assert(true);
685    
686    result.copy(base.trace());    cout << "\tTest Data::atanh." << endl;
687      result.copy(base.atanh());
688      assert(true);
689    
690      cout << "\tTest Data::log." << endl;
691      result.copy(base.log());
692    assert(true);    assert(true);
693    
694      //cout << "\tTest Data::ln." << endl;
695      //result.copy(base.ln());
696      //assert(true);
697    
698      cout << "\tTest Data::abs." << endl;
699      result.copy(base.abs());
700      assert(true);
701    
702      cout << "\tTest Data::sign." << endl;
703      result.copy(base.sign());
704      assert(true);
705    
706      cout << "\tTest Data::exp." << endl;
707    result.copy(base.exp());    result.copy(base.exp());
708    assert(true);    assert(true);
709    
710      cout << "\tTest Data::sqrt." << endl;
711    result.copy(base.sqrt());    result.copy(base.sqrt());
712    assert(true);    assert(true);
713    
714      cout << "\tTest Data::neg." << endl;
715    result.copy(base.neg());    result.copy(base.neg());
716    assert(true);    assert(true);
717    
718      cout << "\tTest Data::pos." << endl;
719    result.copy(base.pos());    result.copy(base.pos());
720    assert(true);    for (int i=0;i<shape[0];i++) {
721        for (int j=0;j<shape[1];j++) {
722          assert(result.getPointDataView()(i,j) == dataView.index(i,j));
723        }
724      }
725    
726      // test reduction operations
727    
728      cout << "\tTest Data::Lsup." << endl;
729      assert(base.Lsup() == 5);
730    
731      cout << "\tTest Data::sup." << endl;
732      assert(base.sup() == 5);
733    
734      cout << "\tTest Data::inf." << endl;
735      assert(base.inf() == 0);
736    
737      // test data-point reduction operations
738    
739      cout << "\tTest Data::minval." << endl;
740      result.copy(base.minval());
741      assert(result.getPointDataView()() == 0);
742    
743      cout << "\tTest Data::maxval." << endl;
744      result.copy(base.maxval());
745      assert(result.getPointDataView()() == 5);
746    
747      //cout << "\tTest Data::length." << endl;
748      //result.copy(base.length());
749      //assert(pow(result.getPointDataView()(),2.0) == 55);
750    
751      cout << "\tTest Data::trace." << endl;
752      result.copy(base.trace());
753      assert(result.getPointDataView()() == 15);
754    
755      //result.copy(base.transpose(0));
756      //assert(true);
757    
758    }
759    
760    void DataTestCase::testRefValue() {
761    
762      //
763      // Note - this test can't be run as boost::python::numeric::array
764      // objects can only be created and used from within a python thread!
765      //
766    
767      cout << endl;
768    
769      cout << "\tTest Data object RefValue methods." << endl;
770    
771      // Create three Data object - DataExpanded, DataConstant and DataEmpty
772      DataArrayView::ShapeType viewShape;
773      viewShape.push_back(3);
774      DataArrayView::ValueType viewData(3);
775      for (int i=0;i<viewShape[0];++i) {
776        viewData[i]=i;
777      }
778      DataArrayView myView(viewData,viewShape);
779    
780      bool expanded=true;
781    
782      Data expandedData(myView,FunctionSpace(),expanded);
783      Data constantData(myView);
784      Data emptyData;
785    
786      assert(expandedData.isExpanded());
787      assert(constantData.isConstant());
788      assert(emptyData.isEmpty());
789    
790      // Check assertions are thrown for RefValue methods on DataEmpty
791    
792      int ref = 0;
793      boost::python::numeric::array num_array(1.0);
794    
795      try {
796          emptyData.getRefValue(ref,num_array);
797          assert(false);
798      }
799      catch (EsysException& e) {
800          assert(true);
801      }
802      try {
803          emptyData.setRefValue(ref,num_array);
804          assert(false);
805      }
806      catch (EsysException& e) {
807          assert(true);
808      }
809    
810      // Check assertions are thrown for RefValue methods on DataConstant
811      try {
812          constantData.getRefValue(ref,num_array);
813          assert(false);
814      }
815      catch (EsysException& e) {
816          assert(true);
817      }
818      try {
819          constantData.setRefValue(ref,num_array);
820          assert(false);
821      }
822      catch (EsysException& e) {
823          assert(true);
824      }
825    
826      // Check calls to RefValue methods on DataExpanded
827      expandedData.getRefValue(ref,num_array);
828      expandedData.setRefValue(ref,num_array);
829    
830    }
831    
832    void DataTestCase::testMemAlloc() {
833    
834      //
835      // Simple little sanity check for the memory allocator
836    
837      cout << endl;
838    
839      Data *testData;
840      for (int i=0; i<1000; i++) {
841        testData = new Data(0.0, DataArrayView::ShapeType(), FunctionSpace(), true);
842        delete testData;
843      }
844    
845      DataArrayView::ShapeType viewShape;
846      viewShape.push_back(10);
847      viewShape.push_back(10);
848      viewShape.push_back(10);
849    
850      Data *testData2;
851      Data *testData3 = new Data(0.0, viewShape, FunctionSpace(), true);
852      for (int i=0; i<1000; i++) {
853        testData2 = new Data(0.0, viewShape, FunctionSpace(), true);
854        delete testData2;
855      }
856      delete testData3;
857    
858  }  }
859    
860  TestSuite* DataTestCase::suite ()  TestSuite* DataTestCase::suite ()
# Line 453  TestSuite* DataTestCase::suite () Line 871  TestSuite* DataTestCase::suite ()
871    testSuite->addTest (new TestCaller< DataTestCase>("testConstructors",&DataTestCase::testConstructors));    testSuite->addTest (new TestCaller< DataTestCase>("testConstructors",&DataTestCase::testConstructors));
872    testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));    testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));
873    testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));    testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));
874      //testSuite->addTest (new TestCaller< DataTestCase>("testRefValue",&DataTestCase::testRefValue));
875      testSuite->addTest (new TestCaller< DataTestCase>("testMemAlloc",&DataTestCase::testMemAlloc));
876    
877    return testSuite;    return testSuite;
878  }  }

Legend:
Removed from v.97  
changed lines
  Added in v.538

  ViewVC Help
Powered by ViewVC 1.1.26