/[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 113 by jgs, Mon Feb 28 07:06:33 2005 UTC trunk/escript/test/Data/DataTestCase.cpp revision 468 by jgs, Wed Jan 25 06:50:39 2006 UTC
# Line 12  Line 12 
12   *                                                                           *   *                                                                           *
13   *****************************************************************************   *****************************************************************************
14  */  */
15  #include "esysUtils/EsysException.h"  #include "EsysException.h"
16  #include "escript/Data/Data.h"  #include "escript/Data/Data.h"
17  #include "escript/Data/FunctionSpace.h"  #include "escript/Data/FunctionSpace.h"
18    
# Line 151  void DataTestCase::testSlicing() { Line 151  void DataTestCase::testSlicing() {
151      DataArrayView::ShapeType viewShape;      DataArrayView::ShapeType viewShape;
152      Data source(10.0,viewShape,FunctionSpace(),true);      Data source(10.0,viewShape,FunctionSpace(),true);
153      //      //
154      // weak tests for setting a slice of DataConstant      // weak tests for setting a slice of DataExpanded
155      viewShape.push_back(2);      viewShape.push_back(2);
156      viewShape.push_back(3);      viewShape.push_back(3);
157      Data target(1.3,viewShape,FunctionSpace(),true);      Data target(1.3,viewShape,FunctionSpace(),true);
# Line 190  void DataTestCase::testMore() { Line 190  void DataTestCase::testMore() {
190    
191    cout << "\tCreate a Data object from a DataArrayView" << endl;    cout << "\tCreate a Data object from a DataArrayView" << endl;
192    
   DataArrayView::ValueType viewData;  
193    DataArrayView::ShapeType viewShape;    DataArrayView::ShapeType viewShape;
194    viewShape.push_back(3);    viewShape.push_back(3);
195      DataArrayView::ValueType viewData(3);
196    for (int i=0;i<viewShape[0];++i) {    for (int i=0;i<viewShape[0];++i) {
197      viewData.push_back(i);      viewData[i]=i;
198    }    }
199    DataArrayView myView(viewData,viewShape);    DataArrayView myView(viewData,viewShape);
200    
# Line 221  void DataTestCase::testMore() { Line 221  void DataTestCase::testMore() {
221    
222    cout << "\tExercise wherePositive method" << endl;    cout << "\tExercise wherePositive method" << endl;
223    assert(!exData.wherePositive().isEmpty());    assert(!exData.wherePositive().isEmpty());
   //assert(exData.wherePositive()==exData.wherePositive());  
224    
225    cout << "\tExercise copyWithMask method" << endl;    cout << "\tExercise copyWithMask method" << endl;
226    exData.copyWithMask(result, exData.wherePositive());    exData.copyWithMask(result, exData.wherePositive());
# Line 235  void DataTestCase::testAll() { Line 234  void DataTestCase::testAll() {
234    
235    cout << "\tCreate a Data object from a DataArrayView" << endl;    cout << "\tCreate a Data object from a DataArrayView" << endl;
236    
   DataArrayView::ValueType viewData;  
237    DataArrayView::ShapeType viewShape;    DataArrayView::ShapeType viewShape;
238    viewShape.push_back(3);    viewShape.push_back(3);
239      DataArrayView::ValueType viewData(3);
240    for (int i=0;i<viewShape[0];++i) {    for (int i=0;i<viewShape[0];++i) {
241      viewData.push_back(i);      viewData[i]=i;
242    }    }
243    DataArrayView myView(viewData,viewShape);    DataArrayView myView(viewData,viewShape);
244    
# Line 248  void DataTestCase::testAll() { Line 247  void DataTestCase::testAll() {
247    Data exData(myView,FunctionSpace(),expanded);    Data exData(myView,FunctionSpace(),expanded);
248    Data cData(myView);    Data cData(myView);
249    Data result;    Data result;
250    
251    assert(exData.isExpanded());    assert(exData.isExpanded());
252    assert(cData.isConstant());    assert(cData.isConstant());
253    assert(result.isEmpty());    assert(result.isEmpty());
# Line 264  void DataTestCase::testDataConstant() { Line 264  void DataTestCase::testDataConstant() {
264    
265    cout << "\tCreate a DataConstant object from a DataArrayView" << endl;    cout << "\tCreate a DataConstant object from a DataArrayView" << endl;
266    
   DataArrayView::ValueType viewData;  
267    DataArrayView::ShapeType viewShape;    DataArrayView::ShapeType viewShape;
268    viewShape.push_back(2);    viewShape.push_back(2);
269    viewShape.push_back(3);    viewShape.push_back(3);
270    viewShape.push_back(4);    viewShape.push_back(4);
271      DataArrayView::ValueType viewData(2*3*4);
272    for (int i=0;i<DataArrayView::noValues(viewShape);++i) {    for (int i=0;i<DataArrayView::noValues(viewShape);++i) {
273      viewData.push_back(i);      viewData[i]=i;
274    }    }
275    DataArrayView myView(viewData,viewShape);    DataArrayView myView(viewData,viewShape);
276    
# Line 302  void DataTestCase::testDataTaggedExcepti Line 302  void DataTestCase::testDataTaggedExcepti
302    cout << endl;    cout << endl;
303    
304    cout << "\tTest DataTagged operations exceptions." << endl;    cout << "\tTest DataTagged operations exceptions." << endl;
305    
306    Data myData;    Data myData;
307    DataArrayView myView;    DataArrayView myView;
308    
309    try {    try {
310        myData.getSampleDataByTag(0);;        myData.getSampleDataByTag(0);;
311        assert(false);        assert(false);
# Line 312  void DataTestCase::testDataTaggedExcepti Line 314  void DataTestCase::testDataTaggedExcepti
314        //cout << e.what() << endl;        //cout << e.what() << endl;
315        assert(true);        assert(true);
316    }    }
317    
318    /*    /*
319    try {    try {
320        myData.setTaggedValue(0,myView);;        myData.setTaggedValue(0,myView);;
# Line 333  void DataTestCase::testDataTagged() { Line 336  void DataTestCase::testDataTagged() {
336    
337    DataTagged::TagListType keys;    DataTagged::TagListType keys;
338    DataTagged::ValueListType values;    DataTagged::ValueListType values;
   DataArrayView::ValueType viewData;  
339    DataArrayView::ShapeType viewShape;    DataArrayView::ShapeType viewShape;
340    viewShape.push_back(3);    viewShape.push_back(3);
341      DataArrayView::ValueType viewData(3);
342    for (int i=0;i<viewShape[0];++i) {    for (int i=0;i<viewShape[0];++i) {
343      viewData.push_back(i);      viewData[i]=i;
344    }    }
345    DataArrayView myView(viewData,viewShape);    DataArrayView myView(viewData,viewShape);
346    
# Line 369  void DataTestCase::testConstructors() { Line 372  void DataTestCase::testConstructors() {
372      viewShape.push_back(2);      viewShape.push_back(2);
373      viewShape.push_back(3);      viewShape.push_back(3);
374      Data temp(1.3,viewShape,FunctionSpace(),false);      Data temp(1.3,viewShape,FunctionSpace(),false);
     cout << "\tDump it toString:" << endl;  
     cout << temp.toString() << endl;  
375    }    }
376  }  }
377    
# Line 421  void DataTestCase::testOperations() { Line 422  void DataTestCase::testOperations() {
422    result.copy(base.tan());    result.copy(base.tan());
423    assert(true);    assert(true);
424    
425      cout << "\tTest Data::asin." << endl;
426      result.copy(base.asin());
427      assert(true);
428    
429      cout << "\tTest Data::acos." << endl;
430      result.copy(base.acos());
431      assert(true);
432    
433      cout << "\tTest Data::atan." << endl;
434      result.copy(base.atan());
435      assert(true);
436    
437      cout << "\tTest Data::sinh." << endl;
438      result.copy(base.sinh());
439      assert(true);
440    
441      cout << "\tTest Data::cosh." << endl;
442      result.copy(base.cosh());
443      assert(true);
444    
445      cout << "\tTest Data::tanh." << endl;
446      result.copy(base.tanh());
447      assert(true);
448    
449      cout << "\tTest Data::asinh." << endl;
450      result.copy(base.asinh());
451      assert(true);
452    
453      cout << "\tTest Data::acosh." << endl;
454      result.copy(base.acosh());
455      assert(true);
456    
457      cout << "\tTest Data::atanh." << endl;
458      result.copy(base.atanh());
459      assert(true);
460    
461    cout << "\tTest Data::log." << endl;    cout << "\tTest Data::log." << endl;
462    result.copy(base.log());    result.copy(base.log());
463    assert(true);    assert(true);
464    
465    cout << "\tTest Data::ln." << endl;    //cout << "\tTest Data::ln." << endl;
466    result.copy(base.ln());    //result.copy(base.ln());
467    assert(true);    //assert(true);
468    
469    cout << "\tTest Data::abs." << endl;    cout << "\tTest Data::abs." << endl;
470    result.copy(base.abs());    result.copy(base.abs());
# Line 478  void DataTestCase::testOperations() { Line 515  void DataTestCase::testOperations() {
515    result.copy(base.maxval());    result.copy(base.maxval());
516    assert(result.getPointDataView()() == 5);    assert(result.getPointDataView()() == 5);
517    
518    cout << "\tTest Data::length." << endl;    //cout << "\tTest Data::length." << endl;
519    result.copy(base.length());    //result.copy(base.length());
520    assert(pow(result.getPointDataView()(),2.0) == 55);    //assert(pow(result.getPointDataView()(),2.0) == 55);
521    
522    cout << "\tTest Data::trace." << endl;    cout << "\tTest Data::trace." << endl;
523    result.copy(base.trace());    result.copy(base.trace());
# Line 503  void DataTestCase::testRefValue() { Line 540  void DataTestCase::testRefValue() {
540    cout << "\tTest Data object RefValue methods." << endl;    cout << "\tTest Data object RefValue methods." << endl;
541    
542    // Create three Data object - DataExpanded, DataConstant and DataEmpty    // Create three Data object - DataExpanded, DataConstant and DataEmpty
   DataArrayView::ValueType viewData;  
543    DataArrayView::ShapeType viewShape;    DataArrayView::ShapeType viewShape;
544    viewShape.push_back(3);    viewShape.push_back(3);
545      DataArrayView::ValueType viewData(3);
546    for (int i=0;i<viewShape[0];++i) {    for (int i=0;i<viewShape[0];++i) {
547      viewData.push_back(i);      viewData[i]=i;
548    }    }
549    DataArrayView myView(viewData,viewShape);    DataArrayView myView(viewData,viewShape);
550    
# Line 563  void DataTestCase::testRefValue() { Line 600  void DataTestCase::testRefValue() {
600    
601  }  }
602    
603    void DataTestCase::testMemAlloc() {
604    
605      //
606      // Simple little sanity check for the memory allocator
607    
608      cout << endl;
609    
610      Data *testData;
611      for (int i=0; i<1000; i++) {
612        testData = new Data(0.0, DataArrayView::ShapeType(), FunctionSpace(), true);
613        delete testData;
614      }
615    
616      DataArrayView::ShapeType viewShape;
617      viewShape.push_back(10);
618      viewShape.push_back(10);
619      viewShape.push_back(10);
620    
621      Data *testData2;
622      Data *testData3 = new Data(0.0, viewShape, FunctionSpace(), true);
623      for (int i=0; i<1000; i++) {
624        testData2 = new Data(0.0, viewShape, FunctionSpace(), true);
625        delete testData2;
626      }
627      delete testData3;
628    
629    }
630    
631  TestSuite* DataTestCase::suite ()  TestSuite* DataTestCase::suite ()
632  {  {
633    //    //
# Line 578  TestSuite* DataTestCase::suite () Line 643  TestSuite* DataTestCase::suite ()
643    testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));    testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));
644    testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));    testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));
645    //testSuite->addTest (new TestCaller< DataTestCase>("testRefValue",&DataTestCase::testRefValue));    //testSuite->addTest (new TestCaller< DataTestCase>("testRefValue",&DataTestCase::testRefValue));
646      testSuite->addTest (new TestCaller< DataTestCase>("testMemAlloc",&DataTestCase::testMemAlloc));
647    
648    return testSuite;    return testSuite;
649  }  }

Legend:
Removed from v.113  
changed lines
  Added in v.468

  ViewVC Help
Powered by ViewVC 1.1.26