/[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

revision 97 by jgs, Tue Dec 14 05:39:33 2004 UTC revision 113 by jgs, Mon Feb 28 07:06:33 2005 UTC
# Line 19  Line 19 
19  #include "DataTestCase.h"  #include "DataTestCase.h"
20    
21  #include <iostream>  #include <iostream>
22    #include <math.h>
23    
24  using namespace std;  using namespace std;
25  using namespace CppUnitTest;  using namespace CppUnitTest;
# Line 247  void DataTestCase::testAll() { Line 248  void DataTestCase::testAll() {
248    Data exData(myView,FunctionSpace(),expanded);    Data exData(myView,FunctionSpace(),expanded);
249    Data cData(myView);    Data cData(myView);
250    Data result;    Data result;
   
251    assert(exData.isExpanded());    assert(exData.isExpanded());
252    assert(cData.isConstant());    assert(cData.isConstant());
253    assert(result.isEmpty());    assert(result.isEmpty());
# Line 375  void DataTestCase::testConstructors() { Line 375  void DataTestCase::testConstructors() {
375  }  }
376    
377  void DataTestCase::testOperations() {  void DataTestCase::testOperations() {
378    
379    cout << endl;    cout << endl;
380    
381    cout << "\tCreate a rank 2 Data object" << endl;    // define the shape for the DataArrayView test data
382    DataArrayView::ShapeType viewShape;    DataArrayView::ShapeType shape;
383    viewShape.push_back(2);    shape.push_back(2);
384    viewShape.push_back(3);    shape.push_back(3);
385    
386    Data base(2.0,viewShape,FunctionSpace(),false);    // allocate the data for the DataArrayView
387    Data power(3.0,viewShape,FunctionSpace(),false);    DataArrayView::ValueType data(DataArrayView::noValues(shape),0);
388    
389    cout << "\tPerform basic exercises of unary operations" << endl;    // construct DataArrayView
390      DataArrayView dataView(data,shape);
391    
392      // assign values to the data
393      for (int i=0;i<shape[0];i++) {
394        for (int j=0;j<shape[1];j++) {
395          dataView(i,j)=dataView.index(i,j);
396        }
397      }
398    
399      Data base(dataView);
400    
401      // test unary operations
402    
403      cout << "\tTest Data::pow." << endl;
404      Data power(3.0,shape,FunctionSpace(),true);
405    Data result(base.powD(power));    Data result(base.powD(power));
406    assert(result.getDataPoint(0,0)(0,0) == 8);    for (int i=0;i<shape[0];i++) {
407        for (int j=0;j<shape[1];j++) {
408          assert(result.getPointDataView()(i,j) == pow(dataView.index(i,j),3.0));
409        }
410      }
411    
412      cout << "\tTest Data::sin." << endl;
413    result.copy(base.sin());    result.copy(base.sin());
414    assert(true);    assert(true);
415    
416      cout << "\tTest Data::cos." << endl;
417    result.copy(base.cos());    result.copy(base.cos());
418    assert(true);    assert(true);
419    
420      cout << "\tTest Data::tan." << endl;
421    result.copy(base.tan());    result.copy(base.tan());
422    assert(true);    assert(true);
423    
424      cout << "\tTest Data::log." << endl;
425    result.copy(base.log());    result.copy(base.log());
426    assert(true);    assert(true);
427    
428      cout << "\tTest Data::ln." << endl;
429    result.copy(base.ln());    result.copy(base.ln());
430    assert(true);    assert(true);
431    
432      cout << "\tTest Data::abs." << endl;
433    result.copy(base.abs());    result.copy(base.abs());
434    assert(true);    assert(true);
435    
436    result.copy(base.maxval());    cout << "\tTest Data::sign." << endl;
437      result.copy(base.sign());
438    assert(true);    assert(true);
439    
440    result.copy(base.minval());    cout << "\tTest Data::exp." << endl;
441      result.copy(base.exp());
442    assert(true);    assert(true);
443    
444    result.copy(base.length());    cout << "\tTest Data::sqrt." << endl;
445      result.copy(base.sqrt());
446    assert(true);    assert(true);
447    
448    result.copy(base.sign());    cout << "\tTest Data::neg." << endl;
449      result.copy(base.neg());
450    assert(true);    assert(true);
451    
452    result.copy(base.transpose(0));    cout << "\tTest Data::pos." << endl;
453    assert(true);    result.copy(base.pos());
454      for (int i=0;i<shape[0];i++) {
455        for (int j=0;j<shape[1];j++) {
456          assert(result.getPointDataView()(i,j) == dataView.index(i,j));
457        }
458      }
459    
460      // test reduction operations
461    
462      cout << "\tTest Data::Lsup." << endl;
463      assert(base.Lsup() == 5);
464    
465      cout << "\tTest Data::sup." << endl;
466      assert(base.sup() == 5);
467    
468      cout << "\tTest Data::inf." << endl;
469      assert(base.inf() == 0);
470    
471      // test data-point reduction operations
472    
473      cout << "\tTest Data::minval." << endl;
474      result.copy(base.minval());
475      assert(result.getPointDataView()() == 0);
476    
477      cout << "\tTest Data::maxval." << endl;
478      result.copy(base.maxval());
479      assert(result.getPointDataView()() == 5);
480    
481      cout << "\tTest Data::length." << endl;
482      result.copy(base.length());
483      assert(pow(result.getPointDataView()(),2.0) == 55);
484    
485      cout << "\tTest Data::trace." << endl;
486    result.copy(base.trace());    result.copy(base.trace());
487    assert(true);    assert(result.getPointDataView()() == 15);
488    
489    result.copy(base.exp());    //result.copy(base.transpose(0));
490    assert(true);    //assert(true);
491    
492    result.copy(base.sqrt());  }
   assert(true);  
493    
494    result.copy(base.neg());  void DataTestCase::testRefValue() {
495    assert(true);  
496      //
497      // Note - this test can't be run as boost::python::numeric::array
498      // objects can only be created and used from within a python thread!
499      //
500    
501      cout << endl;
502    
503      cout << "\tTest Data object RefValue methods." << endl;
504    
505      // Create three Data object - DataExpanded, DataConstant and DataEmpty
506      DataArrayView::ValueType viewData;
507      DataArrayView::ShapeType viewShape;
508      viewShape.push_back(3);
509      for (int i=0;i<viewShape[0];++i) {
510        viewData.push_back(i);
511      }
512      DataArrayView myView(viewData,viewShape);
513    
514      bool expanded=true;
515    
516      Data expandedData(myView,FunctionSpace(),expanded);
517      Data constantData(myView);
518      Data emptyData;
519    
520      assert(expandedData.isExpanded());
521      assert(constantData.isConstant());
522      assert(emptyData.isEmpty());
523    
524      // Check assertions are thrown for RefValue methods on DataEmpty
525    
526      int ref = 0;
527      boost::python::numeric::array num_array(1.0);
528    
529      try {
530          emptyData.getRefValue(ref,num_array);
531          assert(false);
532      }
533      catch (EsysException& e) {
534          assert(true);
535      }
536      try {
537          emptyData.setRefValue(ref,num_array);
538          assert(false);
539      }
540      catch (EsysException& e) {
541          assert(true);
542      }
543    
544      // Check assertions are thrown for RefValue methods on DataConstant
545      try {
546          constantData.getRefValue(ref,num_array);
547          assert(false);
548      }
549      catch (EsysException& e) {
550          assert(true);
551      }
552      try {
553          constantData.setRefValue(ref,num_array);
554          assert(false);
555      }
556      catch (EsysException& e) {
557          assert(true);
558      }
559    
560      // Check calls to RefValue methods on DataExpanded
561      expandedData.getRefValue(ref,num_array);
562      expandedData.setRefValue(ref,num_array);
563    
   result.copy(base.pos());  
   assert(true);  
564  }  }
565    
566  TestSuite* DataTestCase::suite ()  TestSuite* DataTestCase::suite ()
# Line 453  TestSuite* DataTestCase::suite () Line 577  TestSuite* DataTestCase::suite ()
577    testSuite->addTest (new TestCaller< DataTestCase>("testConstructors",&DataTestCase::testConstructors));    testSuite->addTest (new TestCaller< DataTestCase>("testConstructors",&DataTestCase::testConstructors));
578    testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));    testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));
579    testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));    testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));
580      //testSuite->addTest (new TestCaller< DataTestCase>("testRefValue",&DataTestCase::testRefValue));
581    
582    return testSuite;    return testSuite;
583  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26