/[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 474 by jgs, Mon Jan 30 04:23:44 2006 UTC revision 497 by jgs, Tue Feb 7 01:28:01 2006 UTC
# Line 12  Line 12 
12   *                                                                           *   *                                                                           *
13   *****************************************************************************   *****************************************************************************
14  */  */
15    
16    #include "EsysException.h"
17    
18  #include "DataTagged.h"  #include "DataTagged.h"
19    
20    #include "DataTaggedTestCase.h"
21    
22  #include "BinaryOp.h"  #include "BinaryOp.h"
23  #include "UnaryOp.h"  #include "UnaryOp.h"
 #include "EsysException.h"  
   
24  #include "FunctionSpaceFactory.h"  #include "FunctionSpaceFactory.h"
25  #include "DataFactory.h"  #include "DataFactory.h"
26    
 #include "DataTaggedTestCase.h"  
   
27  #include <iostream>  #include <iostream>
28  #include <functional>  #include <functional>
29  #include <algorithm>  #include <algorithm>
# Line 186  void DataTaggedTestCase::testAll() { Line 188  void DataTaggedTestCase::testAll() {
188    cout << endl;    cout << endl;
189    
190    {    {
191      cout << "\tTest default construction." << endl;  
192        cout << "\tTest default DataTagged." << endl;
193      DataTagged myData;      DataTagged myData;
194      assert(myData.getPointDataView()()==0);  
     assert(myData.getNumDPPSample()==1);  
195      assert(myData.getNumSamples()==1);      assert(myData.getNumSamples()==1);
196      cout << "\tTest adding two keys with empty value list." << endl;      assert(myData.getNumDPPSample()==1);
197      DataTagged::TagListType keys;  
198      DataTagged::ValueListType values;      assert(myData.validSamplePointNo(0));
199      keys.push_back(1);      assert(myData.validSampleNo(0));
200      keys.push_back(2);      assert(!myData.validSamplePointNo(1));
201      myData.addTaggedValues(keys,values);      assert(!myData.validSampleNo(1));
202      for (int i=0;i<keys.size();++i) {  
203        assert(myData.getPointDataView()()==0);      assert(myData.getTagNumber(0)==1);
204      }  
205        assert(!myData.isCurrentTag(1));
206    
207        assert(myData.getTagLookup().size()==0);
208    
209        assert(myData.getLength()==1);
210    
211        assert(myData.getPointOffset(0,0)==0);
212    
213        // cout << myData.toString() << endl;
214    
215        DataArrayView myDataView = myData.getDataPoint(0,0);
216        assert(!myDataView.isEmpty());
217        assert(myDataView.getOffset()==0);
218        assert(myDataView.getRank()==0);
219        assert(myDataView.noValues()==1);
220        assert(myDataView.getShape().size()==0);
221        assert(myDataView()==0.0);
222    
223        myDataView = myData.getDataPointByTag(1);
224        assert(!myDataView.isEmpty());
225        assert(myDataView.getOffset()==0);
226        assert(myDataView.getRank()==0);
227        assert(myDataView.noValues()==1);
228        assert(myDataView.getShape().size()==0);
229        assert(myDataView()==0.0);
230    
231        myDataView = myData.getDefaultValue();
232        assert(!myDataView.isEmpty());
233        assert(myDataView.getOffset()==0);
234        assert(myDataView.getRank()==0);
235        assert(myDataView.noValues()==1);
236        assert(myDataView.getShape().size()==0);
237        assert(myDataView()==0.0);
238    
239        //assert(myData.getSampleDataByTag(0)[0]==0.0);
240        //assert(myData.getSampleDataByTag(3)[0]==0.0);
241        //assert(myData.getSampleDataByTag(472)[0]==0.0);
242    
243        //cout << "\tTest adding two keys with empty value list." << endl;
244        //DataTagged::TagListType keys;
245        //DataTagged::ValueListType values;
246        //keys.push_back(1);
247        //keys.push_back(2);
248        //myData.addTaggedValues(keys,values);
249        //for (int i=0;i<keys.size();++i) {
250        //  assert(myData.getPointDataView()()==0);
251        //}
252    }    }
253    
254    {    {
255      DataArrayView::ShapeType viewShape;  //    cout << "\tCreate tagged data with no tag values just a default." << endl;
256      viewShape.push_back(3);   //   DataArrayView::ShapeType viewShape;
257      DataArrayView::ValueType viewData(3);  //    viewShape.push_back(3);
258      DataTagged::TagListType keys;  //    DataArrayView::ValueType viewData(3);
259      DataTagged::ValueListType values;  //    DataTagged::TagListType keys;
260      for (int i=0;i<viewShape[0];++i) {  //    DataTagged::ValueListType values;
261        viewData[i]=0.0;  //    for (int i=0;i<viewShape[0];i++) {
262      }  //      viewData[i]=0.0;
263      DataArrayView myView(viewData,viewShape);  //    }
264      cout << "\tCreate tagged data with no tag values just a default." << endl;  //    DataArrayView myView(viewData,viewShape);
265      DataTagged myData(keys,values,myView,FunctionSpace());  //    DataTagged myData(keys,values,myView,FunctionSpace());
266      assert(myData.getNumDPPSample()==1);  //    assert(myData.getNumDPPSample()==1);
267      assert(myData.getNumSamples()==1);  //    assert(myData.getNumSamples()==1);
268      cout << "\tTest non existent tag returns the default value." << endl;  //    // Test non existent tag returns the default value.
269      assert(myData.getDataPointByTag(1)==myView);  //    assert(myData.getDataPointByTag(1)==myView);
270      cout << "\tTest adding a single tag value." << endl;  
271      for (int i=0;i<myView.getShape()[0];++i) {      //cout << "\tTest adding a single tag value." << endl;
272        myView(i)=i;      //for (int i=0;i<myView.getShape()[0];++i) {
273      }      //  myView(i)=i;
274      values.push_back(myView);      //}
275      keys.push_back(1);      //values.push_back(myView);
276      myData.addTaggedValues(keys,values);      //keys.push_back(1);
277      assert(myData.getDataPointByTag(1)==myView);      //myData.addTaggedValues(keys,values);
278      cout << "\tTest addition of further tags." << endl;      //assert(myData.getDataPointByTag(1)==myView);
279      keys.resize(0);      //cout << "\tTest addition of further tags." << endl;
280      keys.push_back(3);      //keys.resize(0);
281      for (int i=0;i<myView.getShape()[0];++i) {      //keys.push_back(3);
282        myView(i)=i+1.5;      //for (int i=0;i<myView.getShape()[0];++i) {
283      }      //  myView(i)=i+1.5;
284      myData.addTaggedValues(keys,values);      //}
285      assert(myData.getDataPointByTag(3)==myView);      //myData.addTaggedValues(keys,values);
286      assert(myData.getDataPointByTag(1)!=myView);      //assert(myData.getDataPointByTag(3)==myView);
287      cout << "\tTrigger the size mismatch exception." << endl;      //assert(myData.getDataPointByTag(1)!=myView);
288      try {      //cout << "\tTrigger the size mismatch exception." << endl;
289        values.push_back(myView);      //try {
290        myData.addTaggedValues(keys,values);      //  values.push_back(myView);
291        assert(false);      //  myData.addTaggedValues(keys,values);
292      }      //  assert(false);
293      catch (EsysException& e) {      //}
294        assert(true);      //catch (EsysException& e) {
295      }      // assert(true);
296        //}
297    }    }
298    
299    {    {
300      cout << "\tTest creation of tagged data with multiple tags." << endl;  //    cout << "\tTest creation of tagged data with multiple tags." << endl;
301      DataArrayView::ShapeType viewShape;  //    DataArrayView::ShapeType viewShape;
302      viewShape.push_back(3);  //    viewShape.push_back(3);
303      DataArrayView::ValueType viewData(3);  //    DataArrayView::ValueType viewData(3);
304      DataTagged::TagListType keys;   //   DataTagged::TagListType keys;
305      DataTagged::ValueListType values;   //   DataTagged::ValueListType values;
306      for (int i=0;i<viewShape[0];++i) {  //    for (int i=0;i<viewShape[0];++i) {
307        viewData[i]=0.0;  //      viewData[i]=0.0;
308      }  //    }
309      DataArrayView myView(viewData,viewShape);  //    DataArrayView myView(viewData,viewShape);
310      DataArray eOne(myView);  //    DataArray eOne(myView);
311      DataArray eTwo(myView);  //    DataArray eTwo(myView);
312      DataArray eThree(myView);  //    DataArray eThree(myView);
313      for (int i=0;i<eOne.getView().getShape()[0];++i) {  //    for (int i=0;i<eOne.getView().getShape()[0];++i) {
314        eOne.getView()(i)=i+1.0;  //      eOne.getView()(i)=i+1.0;
315      }  //    }
316      for (int i=0;i<eTwo.getView().getShape()[0];++i) {  //    for (int i=0;i<eTwo.getView().getShape()[0];++i) {
317        eTwo.getView()(i)=i+2.0;  //      eTwo.getView()(i)=i+2.0;
318      }  //    }
319      for (int i=0;i<eThree.getView().getShape()[0];++i) {  //    for (int i=0;i<eThree.getView().getShape()[0];++i) {
320        eThree.getView()(i)=i+3.0;  //      eThree.getView()(i)=i+3.0;
321      }  //    }
322      values.push_back(eOne.getView());  //    values.push_back(eOne.getView());
323      values.push_back(eTwo.getView());  //    values.push_back(eTwo.getView());
324      values.push_back(eThree.getView());  //    values.push_back(eThree.getView());
325      keys.push_back(1);  //    keys.push_back(1);
326      keys.push_back(2);  //    keys.push_back(2);
327      keys.push_back(3);  //    keys.push_back(3);
328      DataTagged myData(keys,values,myView,FunctionSpace());  //    DataTagged myData(keys,values,myView,FunctionSpace());
329      assert(myData.getDataPointByTag(1)==eOne.getView());  //    assert(myData.getDataPointByTag(1)==eOne.getView());
330      assert(myData.getDataPointByTag(2)==eTwo.getView());  //    assert(myData.getDataPointByTag(2)==eTwo.getView());
331      assert(myData.getDataPointByTag(3)==eThree.getView());  //    assert(myData.getDataPointByTag(3)==eThree.getView());
332      cout << "\tTest isCurrentTag function." << endl;  
333      for (int i=0;i<keys.size();++i) {      //cout << "\tTest isCurrentTag function." << endl;
334        assert(myData.isCurrentTag(keys[i]));      //for (int i=0;i<keys.size();++i) {
335      }      //  assert(myData.isCurrentTag(keys[i]));
336      cout << "\tCheck correct operation for key that doesn't exist." << endl;      //}
337      assert(!myData.isCurrentTag(123));      //cout << "\tCheck correct operation for key that doesn't exist." << endl;
338      cout << "\tTrigger bad shape in input values exception." << endl;      //assert(!myData.isCurrentTag(123));
339      viewShape.clear();      //cout << "\tTrigger bad shape in input values exception." << endl;
340      viewShape.push_back(1);      //viewShape.clear();
341      keys.clear();      //viewShape.push_back(1);
342      values.clear();      //keys.clear();
343      viewData.resize(1,0.0);      //values.clear();
344      DataArrayView myView2(viewData,viewShape);      //viewData.resize(1,0.0);
345      try {      //DataArrayView myView2(viewData,viewShape);
346        myData.addTaggedValue(5,myView2);      //try {
347        assert(false);      //  myData.addTaggedValue(5,myView2);
348      }      //  assert(false);
349      catch (EsysException& e) {      //}
350        assert(true);      //catch (EsysException& e) {
351      }      //  assert(true);
352      cout << "\tTest addTaggedValues." << endl;      //}
353      DataTagged myData2;      //cout << "\tTest addTaggedValues." << endl;
354      myData2.reshapeDataPoint(myView.getShape());      //DataTagged myData2;
355      keys.clear();      //myData2.reshapeDataPoint(myView.getShape());
356      values.clear();      //keys.clear();
357      keys.push_back(1);      //values.clear();
358      keys.push_back(2);      //keys.push_back(1);
359      keys.push_back(3);      //keys.push_back(2);
360      values.push_back(eOne.getView());      //keys.push_back(3);
361      values.push_back(eTwo.getView());      //values.push_back(eOne.getView());
362      values.push_back(eThree.getView());      //values.push_back(eTwo.getView());
363      myData2.addTaggedValues(keys,values);      //values.push_back(eThree.getView());
364      assert(myData2.getDataPointByTag(1)==eOne.getView());      //myData2.addTaggedValues(keys,values);
365      assert(myData2.getDataPointByTag(2)==eTwo.getView());      //assert(myData2.getDataPointByTag(1)==eOne.getView());
366      assert(myData2.getDataPointByTag(3)==eThree.getView());      //assert(myData2.getDataPointByTag(2)==eTwo.getView());
367      cout << "\tTest setTaggedValue." << endl;      //assert(myData2.getDataPointByTag(3)==eThree.getView());
368      DataTagged myData3;      //cout << "\tTest setTaggedValue." << endl;
369      myData3.reshapeDataPoint(myView.getShape());      //DataTagged myData3;
370      myData3.addTaggedValue(1,eThree.getView());      //myData3.reshapeDataPoint(myView.getShape());
371      myData3.addTaggedValue(2,eOne.getView());      //myData3.addTaggedValue(1,eThree.getView());
372      myData3.addTaggedValue(3,eTwo.getView());      //myData3.addTaggedValue(2,eOne.getView());
373      myData3.setTaggedValue(1,eOne.getView());      //myData3.addTaggedValue(3,eTwo.getView());
374      myData3.setTaggedValue(2,eTwo.getView());      //myData3.setTaggedValue(1,eOne.getView());
375      myData3.setTaggedValue(3,eThree.getView());      //myData3.setTaggedValue(2,eTwo.getView());
376      assert(myData3.getDataPointByTag(1)==eOne.getView());      //myData3.setTaggedValue(3,eThree.getView());
377      assert(myData3.getDataPointByTag(2)==eTwo.getView());      //assert(myData3.getDataPointByTag(1)==eOne.getView());
378      assert(myData3.getDataPointByTag(3)==eThree.getView());      //assert(myData3.getDataPointByTag(2)==eTwo.getView());
379        //assert(myData3.getDataPointByTag(3)==eThree.getView());
380    }    }
381    
382  }  }
# Line 334  TestSuite* DataTaggedTestCase::suite () Line 387  TestSuite* DataTaggedTestCase::suite ()
387    // create the suite of tests to perform.    // create the suite of tests to perform.
388    TestSuite *testSuite = new TestSuite ("DataTaggedTestCase");    TestSuite *testSuite = new TestSuite ("DataTaggedTestCase");
389    testSuite->addTest (new TestCaller< DataTaggedTestCase>("testAll",&DataTaggedTestCase::testAll));    testSuite->addTest (new TestCaller< DataTaggedTestCase>("testAll",&DataTaggedTestCase::testAll));
390    testSuite->addTest (new TestCaller< DataTaggedTestCase>("testOperations",&DataTaggedTestCase::testOperations));  //  testSuite->addTest (new TestCaller< DataTaggedTestCase>("testOperations",&DataTaggedTestCase::testOperations));
391    testSuite->addTest (new TestCaller< DataTaggedTestCase>("testReshape",&DataTaggedTestCase::testReshape));  //  testSuite->addTest (new TestCaller< DataTaggedTestCase>("testReshape",&DataTaggedTestCase::testReshape));
392    return testSuite;    return testSuite;
393  }  }

Legend:
Removed from v.474  
changed lines
  Added in v.497

  ViewVC Help
Powered by ViewVC 1.1.26