/[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 121 by jgs, Fri May 6 04:26:16 2005 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>  #include <math.h>
25    
# Line 41  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    
# Line 211  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    
# Line 244  void DataTestCase::testAll() { Line 398  void DataTestCase::testAll() {
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;
404    
405    assert(exData.isExpanded());    assert(exData.isExpanded());
406    assert(cData.isConstant());    assert(cData.isConstant());
407    assert(result.isEmpty());    assert(result.isEmpty());
# 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 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::ShapeType viewShape;  
   viewShape.push_back(3);  
   DataArrayView::ValueType viewData(3);  
   for (int i=0;i<viewShape[0];++i) {  
     viewData[i]=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    
# Line 421  void DataTestCase::testOperations() { Line 651  void DataTestCase::testOperations() {
651    result.copy(base.tan());    result.copy(base.tan());
652    assert(true);    assert(true);
653    
654      cout << "\tTest Data::asin." << endl;
655      result.copy(base.asin());
656      assert(true);
657    
658      cout << "\tTest Data::acos." << endl;
659      result.copy(base.acos());
660      assert(true);
661    
662      cout << "\tTest Data::atan." << endl;
663      result.copy(base.atan());
664      assert(true);
665    
666      cout << "\tTest Data::sinh." << endl;
667      result.copy(base.sinh());
668      assert(true);
669    
670      cout << "\tTest Data::cosh." << endl;
671      result.copy(base.cosh());
672      assert(true);
673    
674      cout << "\tTest Data::tanh." << endl;
675      result.copy(base.tanh());
676      assert(true);
677    
678      cout << "\tTest Data::asinh." << endl;
679      result.copy(base.asinh());
680      assert(true);
681    
682      cout << "\tTest Data::acosh." << endl;
683      result.copy(base.acosh());
684      assert(true);
685    
686      cout << "\tTest Data::atanh." << endl;
687      result.copy(base.atanh());
688      assert(true);
689    
690    cout << "\tTest Data::log." << endl;    cout << "\tTest Data::log." << endl;
691    result.copy(base.log());    result.copy(base.log());
692    assert(true);    assert(true);
693    
694    cout << "\tTest Data::ln." << endl;    //cout << "\tTest Data::ln." << endl;
695    result.copy(base.ln());    //result.copy(base.ln());
696    assert(true);    //assert(true);
697    
698    cout << "\tTest Data::abs." << endl;    cout << "\tTest Data::abs." << endl;
699    result.copy(base.abs());    result.copy(base.abs());
# Line 478  void DataTestCase::testOperations() { Line 744  void DataTestCase::testOperations() {
744    result.copy(base.maxval());    result.copy(base.maxval());
745    assert(result.getPointDataView()() == 5);    assert(result.getPointDataView()() == 5);
746    
747    cout << "\tTest Data::length." << endl;    //cout << "\tTest Data::length." << endl;
748    result.copy(base.length());    //result.copy(base.length());
749    assert(pow(result.getPointDataView()(),2.0) == 55);    //assert(pow(result.getPointDataView()(),2.0) == 55);
750    
751    cout << "\tTest Data::trace." << endl;    cout << "\tTest Data::trace." << endl;
752    result.copy(base.trace());    result.copy(base.trace());
# Line 563  void DataTestCase::testRefValue() { Line 829  void DataTestCase::testRefValue() {
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 ()
861  {  {
862    //    //
# Line 578  TestSuite* DataTestCase::suite () Line 872  TestSuite* DataTestCase::suite ()
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));    //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.121  
changed lines
  Added in v.538

  ViewVC Help
Powered by ViewVC 1.1.26