/[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 2720 by jfenwick, Mon Jul 20 06:20:06 2009 UTC revision 2721 by jfenwick, Fri Oct 16 05:40:12 2009 UTC
# Line 750  void DataTestCase::testConstructors() { Line 750  void DataTestCase::testConstructors() {
750    }    }
751  }  }
752    
753    void DataTestCase::testMoreOperations()
754    {
755       cout << endl;
756       DataTypes::ShapeType shape;
757       shape.push_back(3);
758       shape.push_back(3);
759    
760      // allocate the data
761      DataTypes::ValueType data(DataTypes::noValues(shape),0);
762    
763      // assign values to the data
764      for (int i=0;i<shape[0];i++) {
765        for (int j=0;j<shape[1];j++) {
766          data[getRelIndex(shape,i,j)]=getRelIndex(shape,i,j);
767        }
768      }
769    
770    
771    
772      Data dats[]={Data(data,shape,FunctionSpace(),false),
773            Data(data,shape,FunctionSpace(),false),
774            Data(data,shape,FunctionSpace(),true),
775            Data(data,shape,FunctionSpace(),false),
776            Data(data,shape,FunctionSpace(),false),
777            Data(data,shape,FunctionSpace(),true)};
778      const int NUMDATS=6;
779    //  const int LAZY=3;       // where do the lazy objects start?
780    
781    //   Data baseEx(data,shape,FunctionSpace(),true);
782    //   Data baseCon(data,shape,FunctionSpace(),false);
783    //   Data baseTag(data,shape,FunctionSpace(),false);
784      Data& baseCon=dats[0];
785      Data& baseTag=dats[1];
786      Data& baseEx=dats[2];
787      baseTag.tag();
788      dats[4].tag();
789      dats[3].delaySelf();
790      dats[4].delaySelf();
791      dats[5].delaySelf();
792    
793      assert(baseEx.isExpanded());
794      assert(baseCon.isConstant());
795      assert(baseTag.isTagged());
796    
797      Data results[NUMDATS];
798      double tmp;
799      cout << "\tTest Data::trace(0)." << endl;
800      for (int z=0;z<NUMDATS;++z)
801      {
802        results[z].copy(dats[z].trace(0));
803      }
804      for (int z=0;z<NUMDATS;++z)
805      {
806        tmp=0;
807        for (int i=0;i<shape[0];++i)
808        {
809           tmp+=getRef(dats[z],i,i);
810        }
811        assert(std::abs(results[z].getDataAtOffsetRO(0) - tmp) <= REL_TOL*std::abs(tmp));
812      }
813    
814    
815    }
816    
817  void DataTestCase::testOperations()  void DataTestCase::testOperations()
818  {  {
# Line 1320  void DataTestCase::testOperations() Line 1383  void DataTestCase::testOperations()
1383      assert(std::abs(results[z].getDataAtOffsetRO(0) - 5) <= REL_TOL*5);      assert(std::abs(results[z].getDataAtOffsetRO(0) - 5) <= REL_TOL*5);
1384    }    }
1385    
1386      cout << "\tTest Data::whereZero." << endl;
1387      for (int z=0;z<NUMDATS;++z)
1388      {
1389        results[z].copy(dats[z].whereZero(2));
1390      }
1391      for (int i=0;i<shape[0];i++) {
1392        for (int j=0;j<shape[1];j++) {
1393          tmp=(getRelIndex(shape,i,j)<=2);
1394          for (int z=0;z<NUMDATS;++z)
1395          {
1396        assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1397          }
1398        }
1399      }
1400    
1401      cout << "\tTest Data::whereNonZero." << endl;
1402      for (int z=0;z<NUMDATS;++z)
1403      {
1404        results[z].copy(dats[z].whereNonZero(2));
1405      }
1406      for (int i=0;i<shape[0];i++) {
1407        for (int j=0;j<shape[1];j++) {
1408          tmp=!(getRelIndex(shape,i,j)<=2);
1409          for (int z=0;z<NUMDATS;++z)
1410          {
1411        assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1412          }
1413        }
1414      }
1415    
1416      cout << "\tTest Data::transpose(1)." << endl;
1417      for (int z=0;z<NUMDATS;++z)
1418      {
1419        results[z].copy(dats[z].transpose(1));
1420      }
1421      for (int i=0;i<shape[0];i++) {
1422        for (int j=0;j<shape[1];j++) {
1423         for (int z=0;z<NUMDATS;++z)
1424         {
1425            tmp=getRef(dats[z],i,j);
1426        assert(std::abs(getRef(results[z],j,i) - tmp) <= REL_TOL*std::abs(tmp));
1427         }
1428        }
1429      }
1430    
1431      cout << "\tTest Data::swapaxes(0,1)." << endl;
1432      for (int z=0;z<NUMDATS;++z)
1433      {
1434        results[z].copy(dats[z].swapaxes(0,1));
1435      }
1436      for (int i=0;i<shape[0];i++) {
1437        for (int j=0;j<shape[1];j++) {
1438         for (int z=0;z<NUMDATS;++z)
1439         {
1440            tmp=getRef(dats[z],i,j);
1441        assert(std::abs(getRef(results[z],j,i) - tmp) <= REL_TOL*std::abs(tmp));
1442         }
1443        }
1444      }
1445  }  }
1446    
1447    
# Line 1423  TestSuite* DataTestCase::suite () Line 1545  TestSuite* DataTestCase::suite ()
1545    testSuite->addTest (new TestCaller< DataTestCase>("testConstructors",&DataTestCase::testConstructors));    testSuite->addTest (new TestCaller< DataTestCase>("testConstructors",&DataTestCase::testConstructors));
1546    testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));    testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));
1547    testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));    testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));
1548      testSuite->addTest (new TestCaller< DataTestCase>("testMoreOperations",&DataTestCase::testMoreOperations));
1549    testSuite->addTest (new TestCaller< DataTestCase>("testMemAlloc",&DataTestCase::testMemAlloc));    testSuite->addTest (new TestCaller< DataTestCase>("testMemAlloc",&DataTestCase::testMemAlloc));
1550    testSuite->addTest (new TestCaller< DataTestCase>("Resolving",&DataTestCase::testResolveType));    testSuite->addTest (new TestCaller< DataTestCase>("Resolving",&DataTestCase::testResolveType));
1551      
1552    return testSuite;    return testSuite;
1553  }  }

Legend:
Removed from v.2720  
changed lines
  Added in v.2721

  ViewVC Help
Powered by ViewVC 1.1.26