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

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

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

trunk/esys2/escript/test/Data/DataTestCase.cpp revision 123 by jgs, Fri Jul 8 04:08:13 2005 UTC trunk/escript/test/Data/DataTestCase.cpp revision 511 by jgs, Fri Feb 10 05:39:18 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 "Data.h"
19    #include "FunctionSpace.h"
20    #include "EsysException.h"
21    
22  #include <iostream>  #include <iostream>
23  #include <math.h>  #include <math.h>
24    
# Line 301  void DataTestCase::testDataTaggedExcepti Line 302  void DataTestCase::testDataTaggedExcepti
302    
303    cout << endl;    cout << endl;
304    
305    cout << "\tTest DataTagged operations exceptions." << endl;    cout << "\tTest DataTagged exceptions." << endl;
306    
307    Data myData;    Data myData;
308    DataArrayView myView;    DataArrayView myView;
# Line 315  void DataTestCase::testDataTaggedExcepti Line 316  void DataTestCase::testDataTaggedExcepti
316        assert(true);        assert(true);
317    }    }
318    
   /*  
319    try {    try {
320        myData.setTaggedValue(0,myView);;        myData.setTaggedValueFromCPP(0,myView);;
321        assert(false);        assert(false);
322    }    }
323    catch (EsysException& e) {    catch (EsysException& e) {
324        //cout << e.what() << endl;        //cout << e.what() << endl;
325        assert(true);        assert(true);
326    }    }
   */  
327    
328  }  }
329    
# Line 332  void DataTestCase::testDataTagged() { Line 331  void DataTestCase::testDataTagged() {
331    
332    cout << endl;    cout << endl;
333    
334    cout << "\tCreate a DataTagged object from a DataArrayView" << endl;    cout << "\tCreate a DataTagged object with a default value only." << endl;
335    
336      // create tagged data with no tag values just a default
337    
338    DataTagged::TagListType keys;    DataTagged::TagListType keys;
339    
340    DataTagged::ValueListType values;    DataTagged::ValueListType values;
341    
342    DataArrayView::ShapeType viewShape;    DataArrayView::ShapeType viewShape;
343    viewShape.push_back(3);    viewShape.push_back(3);
344    
345    DataArrayView::ValueType viewData(3);    DataArrayView::ValueType viewData(3);
346    for (int i=0;i<viewShape[0];++i) {    for (int i=0;i<viewShape[0];++i) {
347      viewData[i]=i;      viewData[i]=i;
348    }    }
349    DataArrayView myView(viewData,viewShape);    DataArrayView myView(viewData,viewShape);
350    
   // create tagged data with no tag values just a default  
351    bool expanded=false;    bool expanded=false;
352    
353    Data myData(keys,values,myView,FunctionSpace(),expanded);    Data myData(keys,values,myView,FunctionSpace(),expanded);
   assert(myData.isTagged());  
354    
355    cout << "\tTest some basic operations" << endl;    // cout << myData.toString() << endl;
356    
357    Data myDataCopy(myData);    assert(!myData.isEmpty());
358    myDataCopy.expand();    assert(myData.isTagged());
359    assert(myDataCopy.isExpanded());    assert(myData.getTagNumber(0)==1);
360      assert(myData.getDataPointRank()==1);
361      assert(myData.getLength()==3);
362    
363      DataArrayView myDataView = myData.getPointDataView();
364      assert(!myDataView.isEmpty());
365      assert(myDataView.getOffset()==0);
366      assert(myDataView.getRank()==1);
367      assert(myDataView.noValues()==3);
368      assert(myDataView.getShape().size()==1);
369      assert(myDataView(0)==0.0);
370      assert(myDataView(1)==1.0);
371      assert(myDataView(2)==2.0);
372    
373      myDataView = myData.getDataPoint(0,0);
374      assert(!myDataView.isEmpty());
375      assert(myDataView.getOffset()==0);
376      assert(myDataView.getRank()==1);
377      assert(myDataView.noValues()==3);
378      assert(myDataView.getShape().size()==1);
379      assert(myDataView(0)==0.0);
380      assert(myDataView(1)==1.0);
381      assert(myDataView(2)==2.0);
382    
383      double* sampleData=myData.getSampleData(0);
384      for (int i=0; i<myDataView.noValues(); i++) {
385        assert(sampleData[i]==i);
386      }
387      // use a non-existent tag so we get a pointer to
388      // the first element of the data array
389      sampleData=myData.getSampleDataByTag(9);
390      for (int i=0; i<myData.getLength(); i++) {
391        assert(sampleData[i]==i);
392      }
393    
394      cout << "\tTest setting of a tag and associated value." << endl;
395    
396      // value for tag "1"
397      DataArray eTwo(myView);
398      for (int i=0;i<eTwo.getView().getShape()[0];i++) {
399        eTwo.getView()(i)=i+2.0;
400      }
401    
402      myData.setTaggedValueFromCPP(1,eTwo.getView());
403    
404      assert(myData.getLength()==6);
405    
406      myDataView = myData.getDataPoint(0,0);
407      assert(myDataView==eTwo.getView());
408      assert(!myDataView.isEmpty());
409      assert(myDataView.getOffset()==3);
410      assert(myDataView.getRank()==1);
411      assert(myDataView.noValues()==3);
412      assert(myDataView.getShape().size()==1);
413      assert(myDataView(0)==2);
414      assert(myDataView(1)==3);
415      assert(myDataView(2)==4);
416    
417      sampleData=myData.getSampleDataByTag(1);
418      for (int i=0; i<myDataView.noValues(); i++) {
419        assert(sampleData[i]==i+2);
420      }
421    
422  }  }
423    
# Line 422  void DataTestCase::testOperations() { Line 485  void DataTestCase::testOperations() {
485    result.copy(base.tan());    result.copy(base.tan());
486    assert(true);    assert(true);
487    
488      cout << "\tTest Data::asin." << endl;
489      result.copy(base.asin());
490      assert(true);
491    
492      cout << "\tTest Data::acos." << endl;
493      result.copy(base.acos());
494      assert(true);
495    
496      cout << "\tTest Data::atan." << endl;
497      result.copy(base.atan());
498      assert(true);
499    
500      cout << "\tTest Data::sinh." << endl;
501      result.copy(base.sinh());
502      assert(true);
503    
504      cout << "\tTest Data::cosh." << endl;
505      result.copy(base.cosh());
506      assert(true);
507    
508      cout << "\tTest Data::tanh." << endl;
509      result.copy(base.tanh());
510      assert(true);
511    
512      cout << "\tTest Data::asinh." << endl;
513      result.copy(base.asinh());
514      assert(true);
515    
516      cout << "\tTest Data::acosh." << endl;
517      result.copy(base.acosh());
518      assert(true);
519    
520      cout << "\tTest Data::atanh." << endl;
521      result.copy(base.atanh());
522      assert(true);
523    
524    cout << "\tTest Data::log." << endl;    cout << "\tTest Data::log." << endl;
525    result.copy(base.log());    result.copy(base.log());
526    assert(true);    assert(true);
527    
528    cout << "\tTest Data::ln." << endl;    //cout << "\tTest Data::ln." << endl;
529    result.copy(base.ln());    //result.copy(base.ln());
530    assert(true);    //assert(true);
531    
532    cout << "\tTest Data::abs." << endl;    cout << "\tTest Data::abs." << endl;
533    result.copy(base.abs());    result.copy(base.abs());
# Line 479  void DataTestCase::testOperations() { Line 578  void DataTestCase::testOperations() {
578    result.copy(base.maxval());    result.copy(base.maxval());
579    assert(result.getPointDataView()() == 5);    assert(result.getPointDataView()() == 5);
580    
581    cout << "\tTest Data::length." << endl;    //cout << "\tTest Data::length." << endl;
582    result.copy(base.length());    //result.copy(base.length());
583    assert(pow(result.getPointDataView()(),2.0) == 55);    //assert(pow(result.getPointDataView()(),2.0) == 55);
584    
585    cout << "\tTest Data::trace." << endl;    cout << "\tTest Data::trace." << endl;
586    result.copy(base.trace());    result.copy(base.trace());
# Line 564  void DataTestCase::testRefValue() { Line 663  void DataTestCase::testRefValue() {
663    
664  }  }
665    
666    void DataTestCase::testMemAlloc() {
667    
668      //
669      // Simple little sanity check for the memory allocator
670    
671      cout << endl;
672    
673      Data *testData;
674      for (int i=0; i<1000; i++) {
675        testData = new Data(0.0, DataArrayView::ShapeType(), FunctionSpace(), true);
676        delete testData;
677      }
678    
679      DataArrayView::ShapeType viewShape;
680      viewShape.push_back(10);
681      viewShape.push_back(10);
682      viewShape.push_back(10);
683    
684      Data *testData2;
685      Data *testData3 = new Data(0.0, viewShape, FunctionSpace(), true);
686      for (int i=0; i<1000; i++) {
687        testData2 = new Data(0.0, viewShape, FunctionSpace(), true);
688        delete testData2;
689      }
690      delete testData3;
691    
692    }
693    
694  TestSuite* DataTestCase::suite ()  TestSuite* DataTestCase::suite ()
695  {  {
696    //    //
# Line 579  TestSuite* DataTestCase::suite () Line 706  TestSuite* DataTestCase::suite ()
706    testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));    testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));
707    testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));    testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));
708    //testSuite->addTest (new TestCaller< DataTestCase>("testRefValue",&DataTestCase::testRefValue));    //testSuite->addTest (new TestCaller< DataTestCase>("testRefValue",&DataTestCase::testRefValue));
709      testSuite->addTest (new TestCaller< DataTestCase>("testMemAlloc",&DataTestCase::testMemAlloc));
710    
711    return testSuite;    return testSuite;
712  }  }

Legend:
Removed from v.123  
changed lines
  Added in v.511

  ViewVC Help
Powered by ViewVC 1.1.26