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

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

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

revision 120 by jgs, Fri Apr 1 05:48:57 2005 UTC revision 121 by jgs, Fri May 6 04:26:16 2005 UTC
# Line 17  Line 17 
17  #include "escript/Data/UnaryOp.h"  #include "escript/Data/UnaryOp.h"
18  #include "esysUtils/EsysException.h"  #include "esysUtils/EsysException.h"
19    
 /*  
 #include "finley/CPPAdapter/MeshAdapter.h"  
 #include "finley/CPPAdapter/MeshAdapterFactory.h"  
 #include "escript/Data/AbstractContinuousDomain.h"  
 */  
   
20  #include "escript/Data/FunctionSpaceFactory.h"  #include "escript/Data/FunctionSpaceFactory.h"
21  #include "escript/Data/DataFactory.h"  #include "escript/Data/DataFactory.h"
22    
# Line 37  using namespace escript; Line 31  using namespace escript;
31  using namespace esysUtils;  using namespace esysUtils;
32  using namespace std;  using namespace std;
33    
 //using namespace finley;  
   
34  void DataTaggedTestCase::setUp() {  void DataTaggedTestCase::setUp() {
35    //    //
36    // This is called before each test is run    // This is called before each test is run
# Line 93  void DataTaggedTestCase::testOperations( Line 85  void DataTaggedTestCase::testOperations(
85    cout << endl;    cout << endl;
86    
87    {    {
     cout << "\tTest default DataTagged contains only a default value." << endl;  
88      DataTagged left;      DataTagged left;
89      DataTagged right;      DataTagged right;
90    
91        cout << "\tTest default DataTagged contains only a default value." << endl;
92      binaryOp(left,right,plus<double>());      binaryOp(left,right,plus<double>());
93      assert(left.getPointDataView()()==0);      assert(left.getPointDataView()()==0);
94      assert(right.getPointDataView()()==0);      assert(right.getPointDataView()()==0);
95      cout << "\tTest addTaggedValue and binaryOp(plus)." << endl;  
96        cout << "\tTest binaryOp(plus)." << endl;
97      DataArray vOne(1.0);      DataArray vOne(1.0);
98      DataArray vTwo(2.0);      DataArray vTwo(2.0);
99      right.addTaggedValue(1,vOne.getView());      right.addTaggedValue(1,vOne.getView());
# Line 108  void DataTaggedTestCase::testOperations( Line 102  void DataTaggedTestCase::testOperations(
102      assert(left.getPointDataView()()==0);      assert(left.getPointDataView()()==0);
103      assert(left.getDataPointByTag(1)==vOne.getView());      assert(left.getDataPointByTag(1)==vOne.getView());
104      assert(left.getDataPointByTag(2)==vTwo.getView());      assert(left.getDataPointByTag(2)==vTwo.getView());
105      cout << "\tTest setTaggedValue and binaryOp(multiplies)." << endl;  
106        cout << "\tTest binaryOp(multiplies)." << endl;
107      DataArray vZero(0.0);      DataArray vZero(0.0);
108      right.setTaggedValue(1,vZero.getView());      right.setTaggedValue(1,vZero.getView());
109      right.setTaggedValue(2,vZero.getView());      right.setTaggedValue(2,vZero.getView());
# Line 118  void DataTaggedTestCase::testOperations( Line 113  void DataTaggedTestCase::testOperations(
113      assert(left.getDataPointByTag(2)==vZero.getView());      assert(left.getDataPointByTag(2)==vZero.getView());
114    }    }
115    {    {
     DataArrayView::ValueType viewData;  
116      DataArrayView::ShapeType viewShape;      DataArrayView::ShapeType viewShape;
117      viewShape.push_back(3);      viewShape.push_back(3);
118        DataArrayView::ValueType viewData(3);
119      DataTagged::TagListType keys;      DataTagged::TagListType keys;
120      DataTagged::ValueListType values;      DataTagged::ValueListType values;
121      for (int i=0;i<viewShape[0];++i) {      for (int i=0;i<viewShape[0];++i) {
122        viewData.push_back(i);        viewData[i]=i;
123      }      }
124      DataArrayView myView(viewData,viewShape);      DataArrayView myView(viewData,viewShape);
125      cout << "\tCreate tagged data with no tag values just a default." << endl;      cout << "\tCreate tagged data with no tag values just a default." << endl;
# Line 184  void DataTaggedTestCase::testOperations( Line 179  void DataTaggedTestCase::testOperations(
179      assert(tData.getDataPointByTag(2)==tTwoView);      assert(tData.getDataPointByTag(2)==tTwoView);
180      assert(tData.getDataPointByTag(3)==tThreeView);      assert(tData.getDataPointByTag(3)==tThreeView);
181    }    }
   
182  }  }
183    
184  void DataTaggedTestCase::testAll() {  void DataTaggedTestCase::testAll() {
185    
186    cout << endl;    cout << endl;
187    
188    {    {
189      cout << "\tTest default construction." << endl;      cout << "\tTest default construction." << endl;
190      DataTagged myData;      DataTagged myData;
# Line 206  void DataTaggedTestCase::testAll() { Line 202  void DataTaggedTestCase::testAll() {
202      }      }
203    }    }
204    {    {
     DataArrayView::ValueType viewData;  
205      DataArrayView::ShapeType viewShape;      DataArrayView::ShapeType viewShape;
206      viewShape.push_back(3);      viewShape.push_back(3);
207        DataArrayView::ValueType viewData(3);
208      DataTagged::TagListType keys;      DataTagged::TagListType keys;
209      DataTagged::ValueListType values;      DataTagged::ValueListType values;
210      for (int i=0;i<viewShape[0];++i) {      for (int i=0;i<viewShape[0];++i) {
211        viewData.push_back(0.0);        viewData[i]=0.0;
212      }      }
213      DataArrayView myView(viewData,viewShape);      DataArrayView myView(viewData,viewShape);
214      cout << "\tCreate tagged data with no tag values just a default." << endl;      cout << "\tCreate tagged data with no tag values just a default." << endl;
# Line 245  void DataTaggedTestCase::testAll() { Line 241  void DataTaggedTestCase::testAll() {
241        assert(false);        assert(false);
242      }      }
243      catch (EsysException& e) {      catch (EsysException& e) {
       //cout << e.what() << endl;  
244        assert(true);        assert(true);
245      }      }
246    }    }
247    {    {
248      cout << "\tTest creation of tagged data with multiple tags." << endl;      cout << "\tTest creation of tagged data with multiple tags." << endl;
     DataArrayView::ValueType viewData;  
249      DataArrayView::ShapeType viewShape;      DataArrayView::ShapeType viewShape;
250      viewShape.push_back(3);      viewShape.push_back(3);
251        DataArrayView::ValueType viewData(3);
252      DataTagged::TagListType keys;      DataTagged::TagListType keys;
253      DataTagged::ValueListType values;      DataTagged::ValueListType values;
254      for (int i=0;i<viewShape[0];++i) {      for (int i=0;i<viewShape[0];++i) {
255        viewData.push_back(0.0);        viewData[i]=0.0;
256      }      }
257      DataArrayView myView(viewData,viewShape);      DataArrayView myView(viewData,viewShape);
258      DataArray eOne(myView);      DataArray eOne(myView);
# Line 293  void DataTaggedTestCase::testAll() { Line 288  void DataTaggedTestCase::testAll() {
288      viewShape.push_back(1);      viewShape.push_back(1);
289      keys.clear();      keys.clear();
290      values.clear();      values.clear();
291      viewData.resize(0);      viewData.resize(1,0.0);
     for (int i=0;i<viewShape[0];++i) {  
       viewData.push_back(0.0);  
     }  
292      DataArrayView myView2(viewData,viewShape);      DataArrayView myView2(viewData,viewShape);
293      try {      try {
294        myData.addTaggedValue(5,myView2);        myData.addTaggedValue(5,myView2);
295        assert(false);        assert(false);
296      }      }
297      catch (EsysException& e) {      catch (EsysException& e) {
       //cout << e.what() << endl;  
298        assert(true);        assert(true);
299      }      }
300      cout << "\tTest setTaggedValues." << endl;      cout << "\tTest addTaggedValues." << endl;
301      DataTagged myData2;      DataTagged myData2;
302      myData2.reshapeDataPoint(myView.getShape());      myData2.reshapeDataPoint(myView.getShape());
303      keys.clear();      keys.clear();
# Line 317  void DataTaggedTestCase::testAll() { Line 308  void DataTaggedTestCase::testAll() {
308      values.push_back(eOne.getView());      values.push_back(eOne.getView());
309      values.push_back(eTwo.getView());      values.push_back(eTwo.getView());
310      values.push_back(eThree.getView());      values.push_back(eThree.getView());
311      myData2.setTaggedValues(keys,values);      myData2.addTaggedValues(keys,values);
312      assert(myData2.getDataPointByTag(1)==eOne.getView());      assert(myData2.getDataPointByTag(1)==eOne.getView());
313      assert(myData2.getDataPointByTag(2)==eTwo.getView());      assert(myData2.getDataPointByTag(2)==eTwo.getView());
314      assert(myData2.getDataPointByTag(3)==eThree.getView());      assert(myData2.getDataPointByTag(3)==eThree.getView());
315      cout << "\tTest setTaggedValue." << endl;      cout << "\tTest setTaggedValue." << endl;
316      DataTagged myData3;      DataTagged myData3;
317      myData3.reshapeDataPoint(myView.getShape());      myData3.reshapeDataPoint(myView.getShape());
318        myData3.addTaggedValue(1,eThree.getView());
319        myData3.addTaggedValue(2,eOne.getView());
320        myData3.addTaggedValue(3,eTwo.getView());
321      myData3.setTaggedValue(1,eOne.getView());      myData3.setTaggedValue(1,eOne.getView());
322      myData3.setTaggedValue(2,eTwo.getView());      myData3.setTaggedValue(2,eTwo.getView());
323      myData3.setTaggedValue(3,eThree.getView());      myData3.setTaggedValue(3,eThree.getView());
# Line 334  void DataTaggedTestCase::testAll() { Line 328  void DataTaggedTestCase::testAll() {
328    
329  }  }
330    
 void DataTaggedTestCase::testSubtraction() {  
   
   // An error with FinleyMesh::getTagList used to cause binary operations  
   // between DataExpanded and DataTagged objects to seg-fault. This test  
   // case will provoke this error if it arises again.  
   
   // This test requires the version of setTaggedData which takes a Data  
   // object as an argument. This version is not currently available, so  
   // this test is disabled for now  
   
   /*  
   
   cout << endl;  
   
   cout << "\tCreate domain and function-space." << endl;  
   AbstractContinuousDomain* myDomain = rectangle(10,10);  
   FunctionSpace f = functionOnBoundary(*myDomain);  
   
   cout << "\tCreate two vectors, one being DataExpanded." << endl;  
   Data A = Vector(0,f);  
   Data B = Vector(0,f,true);  
   
   cout << "\tCreate some tags and values to add to the other." << endl;  
   DataArrayView::ValueType viewData;  
   DataArrayView::ShapeType viewShape;  
   viewShape.push_back(2);  
   for (int i=0;i<viewShape[0];++i) {  
     viewData.push_back(0.0);  
   }  
   DataArrayView myView(viewData,viewShape);  
   DataArray eOne(myView);  
   for (int i=0;i<eOne.getView().getShape()[0];++i) {  
     eOne.getView()(i)=i+1.0;  
   }  
   
   A.setTaggedValue(2,eOne.getView());  
   
   //cout << A.toString() << endl;  
   
   cout << "\tCalculate difference." << endl;  
   Data difference = B - A;  
   
   cout << "\tCalculate other binaryOps just to be sure." << endl;  
   Data sum = B + A;  
   Data product = B * A;  
   Data dividend = B / A;  
   
   // If we get here, subtraction operation did not seg-fault.  
   assert(true);  
   
   */  
   
 }  
   
331  TestSuite* DataTaggedTestCase::suite ()  TestSuite* DataTaggedTestCase::suite ()
332  {  {
333    //    //
# Line 396  TestSuite* DataTaggedTestCase::suite () Line 336  TestSuite* DataTaggedTestCase::suite ()
336    testSuite->addTest (new TestCaller< DataTaggedTestCase>("testAll",&DataTaggedTestCase::testAll));    testSuite->addTest (new TestCaller< DataTaggedTestCase>("testAll",&DataTaggedTestCase::testAll));
337    testSuite->addTest (new TestCaller< DataTaggedTestCase>("testOperations",&DataTaggedTestCase::testOperations));    testSuite->addTest (new TestCaller< DataTaggedTestCase>("testOperations",&DataTaggedTestCase::testOperations));
338    testSuite->addTest (new TestCaller< DataTaggedTestCase>("testReshape",&DataTaggedTestCase::testReshape));    testSuite->addTest (new TestCaller< DataTaggedTestCase>("testReshape",&DataTaggedTestCase::testReshape));
   //testSuite->addTest (new TestCaller< DataTaggedTestCase>("testSubtraction",&DataTaggedTestCase::testSubtraction));  
339    return testSuite;    return testSuite;
340  }  }

Legend:
Removed from v.120  
changed lines
  Added in v.121

  ViewVC Help
Powered by ViewVC 1.1.26