/[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 503 by jgs, Wed Feb 8 04:25:40 2006 UTC revision 504 by jgs, Wed Feb 8 05:51:27 2006 UTC
# Line 88  void DataTaggedTestCase::testOperations( Line 88  void DataTaggedTestCase::testOperations(
88    cout << endl;    cout << endl;
89    
90    {    {
91      DataTagged left;      DataTagged myData;
92      DataTagged right;      DataTagged right;
93    
94      cout << "\tTest default DataTagged contains only a default value." << endl;      cout << "\tTest addition of two default DataTagged objects." << endl;
95      binaryOp(left,right,plus<double>());  
96      assert(left.getPointDataView()()==0);      binaryOp(myData,right,plus<double>());
97      assert(right.getPointDataView()()==0);  
98        //cout << myData.toString() << endl;
99    
100        assert(myData.getNumSamples()==1);
101        assert(myData.getNumDPPSample()==1);
102    
103        assert(myData.validSamplePointNo(0));
104        assert(myData.validSampleNo(0));
105        assert(!myData.validSamplePointNo(1));
106        assert(!myData.validSampleNo(1));
107    
108        // data-point 0 has tag number 1 by default
109        assert(myData.getTagNumber(0)==1);
110    
111        assert(!myData.isCurrentTag(1));
112    
113        assert(myData.getTagLookup().size()==0);
114    
115        assert(myData.getLength()==1);
116    
117        assert(myData.getPointOffset(0,0)==0);
118    
119        DataArrayView myDataView = myData.getDataPoint(0,0);
120        assert(!myDataView.isEmpty());
121        assert(myDataView.getOffset()==0);
122        assert(myDataView.getRank()==0);
123        assert(myDataView.noValues()==1);
124        assert(myDataView.getShape().size()==0);
125        assert(myDataView()==0.0);
126    
127        // Test non-existent tag returns the default value.
128        myDataView = myData.getDataPointByTag(1);
129        assert(!myDataView.isEmpty());
130        assert(myDataView.getOffset()==0);
131        assert(myDataView.getRank()==0);
132        assert(myDataView.noValues()==1);
133        assert(myDataView.getShape().size()==0);
134        assert(myDataView()==0.0);
135    
136        myDataView = myData.getDefaultValue();
137        assert(!myDataView.isEmpty());
138        assert(myDataView.getOffset()==0);
139        assert(myDataView.getRank()==0);
140        assert(myDataView.noValues()==1);
141        assert(myDataView.getShape().size()==0);
142        assert(myDataView()==0.0);
143      }
144    
145      {
146        DataTagged myData;
147        DataTagged right;
148    
149        cout << "\tTest addition of two DataTagged objects with one identical tag each." << endl;
150    
     cout << "\tTest binaryOp(plus)." << endl;  
151      DataArray vOne(1.0);      DataArray vOne(1.0);
152      DataArray vTwo(2.0);      myData.addTaggedValue(1,vOne.getView());
153      right.addTaggedValue(1,vOne.getView());      right.addTaggedValue(1,vOne.getView());
154      right.addTaggedValue(2,vTwo.getView());  
155      binaryOp(left,right,plus<double>());      binaryOp(myData,right,plus<double>());
156      assert(left.getPointDataView()()==0);  
157      assert(left.getDataPointByTag(1)==vOne.getView());      // check result value for tag "1"
158      assert(left.getDataPointByTag(2)==vTwo.getView());      DataArrayView myDataView = myData.getDataPointByTag(1);
159        assert(!myDataView.isEmpty());
160      cout << "\tTest binaryOp(multiplies)." << endl;      assert(myDataView.getOffset()==1);
161      DataArray vZero(0.0);      assert(myDataView.getRank()==0);
162      right.setTaggedValue(1,vZero.getView());      assert(myDataView.noValues()==1);
163      right.setTaggedValue(2,vZero.getView());      assert(myDataView.getShape().size()==0);
164      binaryOp(left,right,multiplies<double>());      assert(myDataView()==2.0);
165      assert(left.getPointDataView()()==0);  
166      assert(left.getDataPointByTag(1)==vZero.getView());      // check result for default value
167      assert(left.getDataPointByTag(2)==vZero.getView());      myDataView = myData.getDefaultValue();
168        assert(!myDataView.isEmpty());
169        assert(myDataView.getOffset()==0);
170        assert(myDataView.getRank()==0);
171        assert(myDataView.noValues()==1);
172        assert(myDataView.getShape().size()==0);
173        assert(myDataView()==0.0);
174    }    }
175    
176    {    {
177      DataArrayView::ShapeType viewShape;      DataTagged myData;
178      viewShape.push_back(3);      DataTagged right;
179      DataArrayView::ValueType viewData(3);  
180      DataTagged::TagListType keys;      cout << "\tTest addition of two DataTagged objects with one different tag each." << endl;
181      DataTagged::ValueListType values;  
182      for (int i=0;i<viewShape[0];++i) {      DataArray vOne(1.0);
183        viewData[i]=i;      myData.addTaggedValue(1,vOne.getView());
184      }      right.addTaggedValue(2,vOne.getView());
185      DataArrayView myView(viewData,viewShape);  
186      cout << "\tCreate tagged data with no tag values just a default." << endl;      binaryOp(myData,right,plus<double>());
187      DataTagged left(keys,values,myView,FunctionSpace());  
188      DataTagged right(keys,values,myView,FunctionSpace());      // check result value for tag "1"
189      binaryOp(left,right,minus<double>());      DataArrayView myDataView = myData.getDataPointByTag(1);
190      for (int i=0;i<viewShape[0];++i) {      assert(!myDataView.isEmpty());
191        assert(left.getDefaultValue()(i)==0);      assert(myDataView.getOffset()==1);
192      }      assert(myDataView.getRank()==0);
193      double mVal=10.0;      assert(myDataView.noValues()==1);
194      for (int i=0;i<viewShape[0];++i) {      assert(myDataView.getShape().size()==0);
195        viewData[i]=i*mVal;      assert(myDataView()==1.0);
196      }  
197      cout << "\tTest binaryOp(minus) with the right hand side as a view." << endl;      // check result value for tag "2"
198      binaryOp(left,myView,minus<double>());      myDataView = myData.getDataPointByTag(2);
199      for (int i=0;i<viewShape[0];++i) {      assert(!myDataView.isEmpty());
200        assert(left.getDefaultValue()(i)==-(i*mVal));      assert(myDataView.getOffset()==2);
201      }      assert(myDataView.getRank()==0);
202        assert(myDataView.noValues()==1);
203        assert(myDataView.getShape().size()==0);
204        assert(myDataView()==1.0);
205    
206        // check result for default value
207        myDataView = myData.getDefaultValue();
208        assert(!myDataView.isEmpty());
209        assert(myDataView.getOffset()==0);
210        assert(myDataView.getRank()==0);
211        assert(myDataView.noValues()==1);
212        assert(myDataView.getShape().size()==0);
213        assert(myDataView()==0.0);
214    }    }
215    
216    {    {
217      cout << "\tTest unaryOp(negate) on default DataTagged." << endl;      DataTagged myData;
218      DataTagged data;      DataTagged right;
219      unaryOp(data,negate<double>());  
220      assert(data.getDefaultValue()()==0);      cout << "\tTest addition of two DataTagged objects with overlapping tag sets." << endl;
221      DataArray vOne(1);  
222      binaryOp(data,vOne.getView(),plus<double>());      DataArray vOne(1.0);
223      assert(data.getDefaultValue()()==1);      myData.addTaggedValue(1,vOne.getView());
224      unaryOp(data,negate<double>());      myData.addTaggedValue(2,vOne.getView());
225      assert(data.getDefaultValue()()==-1);      right.addTaggedValue(2,vOne.getView());
226        right.addTaggedValue(3,vOne.getView());
227    
228        binaryOp(myData,right,plus<double>());
229    
230        // check result value for tag "1"
231        DataArrayView myDataView = myData.getDataPointByTag(1);
232        assert(!myDataView.isEmpty());
233        assert(myDataView.getOffset()==1);
234        assert(myDataView.getRank()==0);
235        assert(myDataView.noValues()==1);
236        assert(myDataView.getShape().size()==0);
237        assert(myDataView()==1.0);
238    
239        // check result value for tag "2"
240        myDataView = myData.getDataPointByTag(2);
241        assert(!myDataView.isEmpty());
242        assert(myDataView.getOffset()==2);
243        assert(myDataView.getRank()==0);
244        assert(myDataView.noValues()==1);
245        assert(myDataView.getShape().size()==0);
246        assert(myDataView()==2.0);
247    
248        // check result value for tag "3"
249        myDataView = myData.getDataPointByTag(3);
250        assert(!myDataView.isEmpty());
251        assert(myDataView.getOffset()==3);
252        assert(myDataView.getRank()==0);
253        assert(myDataView.noValues()==1);
254        assert(myDataView.getShape().size()==0);
255        assert(myDataView()==1.0);
256    
257        // check result for default value
258        myDataView = myData.getDefaultValue();
259        assert(!myDataView.isEmpty());
260        assert(myDataView.getOffset()==0);
261        assert(myDataView.getRank()==0);
262        assert(myDataView.noValues()==1);
263        assert(myDataView.getShape().size()==0);
264        assert(myDataView()==0.0);
265    }    }
266    
267    {    {
268      cout << "\tTest unaryOp(negate) on DataTagged with 3 tags." << endl;      //cout << "\tTest binaryOp(multiplies)." << endl;
269      DataArrayView::ShapeType vShape;      //DataArray vZero(0.0);
270      vShape.push_back(3);      //right.setTaggedValue(1,vZero.getView());
271      vShape.push_back(2);      //right.setTaggedValue(2,vZero.getView());
272      vShape.push_back(1);      //binaryOp(left,right,multiplies<double>());
273      DataArray defData(vShape,0.0);  
274      DataArrayView& defView=defData.getView();      //assert(left.getPointDataView()()==0);
275      DataArray tOneData(vShape,1.0);      //assert(left.getDataPointByTag(1)==vZero.getView());
276      DataArrayView& tOneView=tOneData.getView();      //assert(left.getDataPointByTag(2)==vZero.getView());
277      DataArray tTwoData(vShape,2.0);    }
278      DataArrayView& tTwoView=tTwoData.getView();  
279      DataArray tThreeData(vShape,3.0);    {
280      DataArrayView& tThreeView=tThreeData.getView();      //DataArrayView::ShapeType viewShape;
281      DataTagged::TagListType keys;      //viewShape.push_back(3);
282      DataTagged::ValueListType values;      //DataArrayView::ValueType viewData(3);
283      keys.push_back(1);      //DataTagged::TagListType keys;
284      keys.push_back(2);      //DataTagged::ValueListType values;
285      keys.push_back(3);      //for (int i=0;i<viewShape[0];++i) {
286      values.push_back(tOneView);      //  viewData[i]=i;
287      values.push_back(tTwoView);      //}
288      values.push_back(tThreeView);      //DataArrayView myView(viewData,viewShape);
289      DataTagged tData(keys,values,defView,FunctionSpace());      //cout << "\tCreate tagged data with no tag values just a default." << endl;
290      unaryOp(tData,negate<double>());      //DataTagged left(keys,values,myView,FunctionSpace());
291      unaryOp(tData,negate<double>());      //DataTagged right(keys,values,myView,FunctionSpace());
292      assert(tData.getDataPointByTag(1)==tOneView);      //binaryOp(left,right,minus<double>());
293      assert(tData.getDataPointByTag(2)==tTwoView);      //for (int i=0;i<viewShape[0];++i) {
294      assert(tData.getDataPointByTag(3)==tThreeView);      //  assert(left.getDefaultValue()(i)==0);
295        //}
296        //double mVal=10.0;
297        //for (int i=0;i<viewShape[0];++i) {
298        //  viewData[i]=i*mVal;
299        //}
300        //cout << "\tTest binaryOp(minus) with the right hand side as a view." << endl;
301        //binaryOp(left,myView,minus<double>());
302        //for (int i=0;i<viewShape[0];++i) {
303        //  assert(left.getDefaultValue()(i)==-(i*mVal));
304        //}
305      }
306    
307      {
308        //cout << "\tTest unaryOp(negate) on default DataTagged." << endl;
309        //DataTagged data;
310        //unaryOp(data,negate<double>());
311        //assert(data.getDefaultValue()()==0);
312        //DataArray vOne(1);
313        //binaryOp(data,vOne.getView(),plus<double>());
314        //assert(data.getDefaultValue()()==1);
315        //unaryOp(data,negate<double>());
316        //assert(data.getDefaultValue()()==-1);
317      }
318    
319      {
320        //cout << "\tTest unaryOp(negate) on DataTagged with 3 tags." << endl;
321        //DataArrayView::ShapeType vShape;
322        //vShape.push_back(3);
323        //vShape.push_back(2);
324        //vShape.push_back(1);
325        //DataArray defData(vShape,0.0);
326        //DataArrayView& defView=defData.getView();
327        //DataArray tOneData(vShape,1.0);
328        //DataArrayView& tOneView=tOneData.getView();
329        //DataArray tTwoData(vShape,2.0);
330        //DataArrayView& tTwoView=tTwoData.getView();
331        //DataArray tThreeData(vShape,3.0);
332        //DataArrayView& tThreeView=tThreeData.getView();
333        //DataTagged::TagListType keys;
334        //DataTagged::ValueListType values;
335        //keys.push_back(1);
336        //keys.push_back(2);
337        //keys.push_back(3);
338        //values.push_back(tOneView);
339        //values.push_back(tTwoView);
340        //values.push_back(tThreeView);
341        //DataTagged tData(keys,values,defView,FunctionSpace());
342        //unaryOp(tData,negate<double>());
343        //unaryOp(tData,negate<double>());
344        //assert(tData.getDataPointByTag(1)==tOneView);
345        //assert(tData.getDataPointByTag(2)==tTwoView);
346        //assert(tData.getDataPointByTag(3)==tThreeView);
347    }    }
348    
349  }  }
# Line 1853  TestSuite* DataTaggedTestCase::suite () Line 2013  TestSuite* DataTaggedTestCase::suite ()
2013    testSuite->addTest (new TestCaller< DataTaggedTestCase>("testAddTaggedValues",&DataTaggedTestCase::testAddTaggedValues));    testSuite->addTest (new TestCaller< DataTaggedTestCase>("testAddTaggedValues",&DataTaggedTestCase::testAddTaggedValues));
2014    testSuite->addTest (new TestCaller< DataTaggedTestCase>("testSetTaggedValue",&DataTaggedTestCase::testSetTaggedValue));    testSuite->addTest (new TestCaller< DataTaggedTestCase>("testSetTaggedValue",&DataTaggedTestCase::testSetTaggedValue));
2015    testSuite->addTest (new TestCaller< DataTaggedTestCase>("testCopyConstructors",&DataTaggedTestCase::testCopyConstructors));    testSuite->addTest (new TestCaller< DataTaggedTestCase>("testCopyConstructors",&DataTaggedTestCase::testCopyConstructors));
2016  //  testSuite->addTest (new TestCaller< DataTaggedTestCase>("testOperations",&DataTaggedTestCase::testOperations));    testSuite->addTest (new TestCaller< DataTaggedTestCase>("testOperations",&DataTaggedTestCase::testOperations));
2017  //  testSuite->addTest (new TestCaller< DataTaggedTestCase>("testReshape",&DataTaggedTestCase::testReshape));  //  testSuite->addTest (new TestCaller< DataTaggedTestCase>("testReshape",&DataTaggedTestCase::testReshape));
2018    return testSuite;    return testSuite;
2019  }  }

Legend:
Removed from v.503  
changed lines
  Added in v.504

  ViewVC Help
Powered by ViewVC 1.1.26