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

revision 110 by jgs, Mon Feb 14 04:14:42 2005 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 374  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      // allocate the data for the DataArrayView
387      DataArrayView::ValueType data(DataArrayView::noValues(shape),0);
388    
389    Data base(2.0,viewShape,FunctionSpace(),true);    // construct DataArrayView
390    Data power(3.0,viewShape,FunctionSpace(),true);    DataArrayView dataView(data,shape);
391    
392    cout << "\tPerform basic exercises of unary operations" << endl;    // 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      cout << "\tTest Data::sign." << endl;
437    result.copy(base.sign());    result.copy(base.sign());
438    assert(true);    assert(true);
439    
440      cout << "\tTest Data::exp." << endl;
441    result.copy(base.exp());    result.copy(base.exp());
442    assert(true);    assert(true);
443    
444      cout << "\tTest Data::sqrt." << endl;
445    result.copy(base.sqrt());    result.copy(base.sqrt());
446    assert(true);    assert(true);
447    
448      cout << "\tTest Data::neg." << endl;
449    result.copy(base.neg());    result.copy(base.neg());
450    assert(true);    assert(true);
451    
452      cout << "\tTest Data::pos." << endl;
453    result.copy(base.pos());    result.copy(base.pos());
454    assert(true);    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());    result.copy(base.minval());
475    assert(true);    assert(result.getPointDataView()() == 0);
476    
477      cout << "\tTest Data::maxval." << endl;
478    result.copy(base.maxval());    result.copy(base.maxval());
479    assert(true);    assert(result.getPointDataView()() == 5);
480    
481      cout << "\tTest Data::length." << endl;
482    result.copy(base.length());    result.copy(base.length());
483    assert(true);    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.transpose(0));    //result.copy(base.transpose(0));
490    //assert(true);    //assert(true);
# Line 443  void DataTestCase::testRefValue() { Line 495  void DataTestCase::testRefValue() {
495    
496    //    //
497    // Note - this test can't be run as boost::python::numeric::array    // Note - this test can't be run as boost::python::numeric::array
498    // objects can only be created and used form within a pythin thread!    // objects can only be created and used from within a python thread!
499    //    //
500    
501    cout << endl;    cout << endl;

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

  ViewVC Help
Powered by ViewVC 1.1.26