/[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 2147 by jfenwick, Wed Dec 10 04:41:26 2008 UTC revision 2271 by jfenwick, Mon Feb 16 05:08:29 2009 UTC
# Line 58  namespace Line 58  namespace
58  {  {
59    
60  inline  inline
61  DataTypes::ValueType::reference  DataTypes::ValueType::const_reference
62  getRef(Data& d,int s1, int p1, int x, int y)  getRef(Data& d,int s1, int p1, int x, int y)
63  {  {
64      return d.getDataAtOffset(d.getDataOffset(s1,p1)+getRelIndex(d.getDataPointShape(),x,y));      return d.getDataAtOffsetRO(d.getDataOffset(s1,p1)+getRelIndex(d.getDataPointShape(),x,y));
65  }  }
66    
67  inline  inline
68  DataTypes::ValueType::reference  DataTypes::ValueType::const_reference
69  getRef(Data& d, int x, int y)  getRef(Data& d, int x, int y)
70  {  {
71      return d.getDataAtOffset(getRelIndex(d.getDataPointShape(),x,y));      return d.getDataAtOffsetRO(getRelIndex(d.getDataPointShape(),x,y));
72  }  }
73    
74  }  }
# Line 108  void DataTestCase::testCopyingWorker(boo Line 108  void DataTestCase::testCopyingWorker(boo
108      }      }
109      for (int i=0;i<DataTypes::noValues(shape);++i)      for (int i=0;i<DataTypes::noValues(shape);++i)
110      {      {
111      if (d->getDataAtOffset(i)!=deep.getDataAtOffset(i))      if (d->getDataAtOffsetRO(i)!=deep.getDataAtOffsetRO(i))
112          assert(false);          assert(false);
113      }      }
114      if (delayed)      if (delayed)
# Line 122  void DataTestCase::testCopyingWorker(boo Line 122  void DataTestCase::testCopyingWorker(boo
122      }      }
123      for (int i=0;i<DataTypes::noValues(shape);++i)      for (int i=0;i<DataTypes::noValues(shape);++i)
124      {      {
125      if (d->getDataAtOffset(i)==deep.getDataAtOffset(i))      if (d->getDataAtOffsetRO(i)==deep.getDataAtOffsetRO(i))
126          assert(false);          assert(false);
127      }      }
128          if (delayed)          if (delayed)
# Line 137  void DataTestCase::testCopyingWorker(boo Line 137  void DataTestCase::testCopyingWorker(boo
137      }      }
138      for (int i=0;i<DataTypes::noValues(shape);++i)      for (int i=0;i<DataTypes::noValues(shape);++i)
139      {      {
140      if (d->getDataAtOffset(i)!=deep.getDataAtOffset(i))      if (d->getDataAtOffsetRO(i)!=deep.getDataAtOffsetRO(i))
141          assert(false);          assert(false);
142      }      }
143      d->setToZero();      d->setToZero();
144      for (int i=0;i<DataTypes::noValues(shape);++i)      for (int i=0;i<DataTypes::noValues(shape);++i)
145      {      {
146      if (d->getDataAtOffset(i)==deep.getDataAtOffset(i))      if (d->getDataAtOffsetRO(i)==deep.getDataAtOffsetRO(i))
147          assert(false);          assert(false);
148      }      }
149      delete dats[k];      delete dats[k];
# Line 186  void DataTestCase::testSlicingWorker(boo Line 186  void DataTestCase::testSlicingWorker(boo
186     for (int k=0;k<NUMDATS;++k)     for (int k=0;k<NUMDATS;++k)
187     {     {
188      cout << "\t\tTest get-slicing " << strs[k] << endl;      cout << "\t\tTest get-slicing " << strs[k] << endl;
189          dats[k]->getDataAtOffset(dats[k]->getDataOffset(0,0)+getRelIndex(viewShape,0,0))=1.0;      dats[k]->requireWrite();
190          dats[k]->getDataAtOffset(dats[k]->getDataOffset(0,0)+getRelIndex(viewShape,1,1))=2.0;          dats[k]->getDataAtOffsetRW(dats[k]->getDataOffset(0,0)+getRelIndex(viewShape,0,0))=1.0;
191            dats[k]->getDataAtOffsetRW(dats[k]->getDataOffset(0,0)+getRelIndex(viewShape,1,1))=2.0;
192    
193          DataTypes::RegionType region;          DataTypes::RegionType region;
194          region.push_back(DataTypes::RegionType::value_type(0,0));          region.push_back(DataTypes::RegionType::value_type(0,0));
# Line 197  void DataTestCase::testSlicingWorker(boo Line 198  void DataTestCase::testSlicingWorker(boo
198    
199          if (tags[k]) {assert(slice1.isTagged());}          if (tags[k]) {assert(slice1.isTagged());}
200          assert(slice1.getDataPointRank()==0);          assert(slice1.getDataPointRank()==0);
201          assert(slice1.getDataPoint(0,0)==1.0);          assert(slice1.getDataPointRO(0,0)==1.0);
202    
203      //      //
204      // create a rank 2 slice with one value      // create a rank 2 slice with one value
# Line 213  void DataTestCase::testSlicingWorker(boo Line 214  void DataTestCase::testSlicingWorker(boo
214      if (tags[k]) {assert(slice2.isTagged());}      if (tags[k]) {assert(slice2.isTagged());}
215      assert(slice2.getDataPointRank()==2);      assert(slice2.getDataPointRank()==2);
216            
217      assert(slice2.getDataAtOffset(slice2.getDataOffset(0,0)+getRelIndex(slice2.getDataPointShape(),0,0))==1.0);      assert(slice2.getDataAtOffsetRO(slice2.getDataOffset(0,0)+getRelIndex(slice2.getDataPointShape(),0,0))==1.0);
218    
219      //      //
220      // create a rank 2 slice with four values      // create a rank 2 slice with four values
# Line 311  void DataTestCase::testSlicingWorker(boo Line 312  void DataTestCase::testSlicingWorker(boo
312      region.push_back(DataTypes::RegionType::value_type(1,1));      region.push_back(DataTypes::RegionType::value_type(1,1));
313      region.push_back(DataTypes::RegionType::value_type(1,1));      region.push_back(DataTypes::RegionType::value_type(1,1));
314      target.setSlice(*(src[k]),region);      target.setSlice(*(src[k]),region);
315      assert(getRef(target,0,0,1,1)==src[k]->getDataPoint(0,0));      assert(getRef(target,0,0,1,1)==src[k]->getDataPointRO(0,0));
316    }    }
317        
318    // some extra tests on tagged data    // some extra tests on tagged data
# Line 342  void DataTestCase::testSlicingWorker(boo Line 343  void DataTestCase::testSlicingWorker(boo
343    assert(target.isTagged());    assert(target.isTagged());
344    assert(target.getDataPointRank()==2);    assert(target.getDataPointRank()==2);
345    assert(getRef(target,0,0,0,0)==0);    assert(getRef(target,0,0,0,0)==0);
346    assert(getRef(target,0,0,0,1)==src[1]->getDataPoint(0,0));    assert(getRef(target,0,0,0,1)==src[1]->getDataPointRO(0,0));
347    assert(getRef(target,0,0,0,2)==4);    assert(getRef(target,0,0,0,2)==4);
348    assert(getRef(target,0,0,1,0)==1);    assert(getRef(target,0,0,1,0)==1);
349    assert(getRef(target,0,0,1,1)==3);    assert(getRef(target,0,0,1,1)==3);
# Line 614  void DataTestCase::testDataTagged() { Line 615  void DataTestCase::testDataTagged() {
615      assert(myData.getLength()==3);      assert(myData.getLength()==3);
616            
617      assert(myData.getNoValues()==3);      assert(myData.getNoValues()==3);
618      assert(myData.getDataAtOffset(0)==0.0);      assert(myData.getDataAtOffsetRO(0)==0.0);
619      assert(myData.getDataAtOffset(1)==1.0);      assert(myData.getDataAtOffsetRO(1)==1.0);
620      assert(myData.getDataAtOffset(2)==2.0);      assert(myData.getDataAtOffsetRO(2)==2.0);
621    
622      double* sampleData=myData.getSampleData(0);      double* sampleData=myData.getSampleDataRW(0);
623      for (int i=0; i<myData.getNoValues(); i++) {      for (int i=0; i<myData.getNoValues(); i++) {
624        assert(sampleData[i]==i);        assert(sampleData[i]==i);
625      }      }
# Line 647  void DataTestCase::testDataTagged() { Line 648  void DataTestCase::testDataTagged() {
648      assert(myData.getDataPointRank()==1);      assert(myData.getDataPointRank()==1);
649      assert(myData.getNoValues()==3);      assert(myData.getNoValues()==3);
650    
651      assert(myData.getDataAtOffset(offset+0)==2);      assert(myData.getDataAtOffsetRO(offset+0)==2);
652      assert(myData.getDataAtOffset(offset+1)==3);      assert(myData.getDataAtOffsetRO(offset+1)==3);
653      assert(myData.getDataAtOffset(offset+2)==4);      assert(myData.getDataAtOffsetRO(offset+2)==4);
654    
655      sampleData=myData.getSampleDataByTag(1);      sampleData=myData.getSampleDataByTag(1);
656      for (int i=0; i<myData.getNoValues(); i++) {      for (int i=0; i<myData.getNoValues(); i++) {
# Line 820  void DataTestCase::testOperations() Line 821  void DataTestCase::testOperations()
821          Data(smalldata,shape,FunctionSpace(),true)};          Data(smalldata,shape,FunctionSpace(),true)};
822    sdats[1].tag();    sdats[1].tag();
823    sdats[4].tag();    sdats[4].tag();
824    sdats[3].delaySelf();    sdats[3].delaySelf();     // 3 is a lazy constant
825    sdats[4].delaySelf();    sdats[4].delaySelf();     // 4 is a lazy tagged
826    sdats[5].delaySelf();    sdats[5].delaySelf();     // 5 is a lazy expanded
827    
828    
829    
# Line 1305  void DataTestCase::testOperations() Line 1306  void DataTestCase::testOperations()
1306    }    }
1307    for (int z=0;z<NUMDATS;++z)    for (int z=0;z<NUMDATS;++z)
1308    {    {
1309      assert(std::abs(results[z].getDataAtOffset(0) - 0) <= REL_TOL*0);      assert(std::abs(results[z].getDataAtOffsetRO(0) - 0) <= REL_TOL*0);
1310    }    }
1311        
1312    
# Line 1316  void DataTestCase::testOperations() Line 1317  void DataTestCase::testOperations()
1317    }    }
1318    for (int z=0;z<NUMDATS;++z)    for (int z=0;z<NUMDATS;++z)
1319    {    {
1320      assert(std::abs(results[z].getDataAtOffset(0) - 5) <= REL_TOL*5);      assert(std::abs(results[z].getDataAtOffsetRO(0) - 5) <= REL_TOL*5);
1321    }    }
1322    
1323  }  }
# Line 1372  void DataTestCase::testBinary() Line 1373  void DataTestCase::testBinary()
1373      }      }
1374      for (int i=0;i<DataTypes::noValues(shape);++i)      for (int i=0;i<DataTypes::noValues(shape);++i)
1375      {      {
1376        assert(std::abs(r1.getDataAtOffset(i)-data[i]) <= REL_TOL*data[i]);        assert(std::abs(r1.getDataAtOffsetRO(i)-data[i]) <= REL_TOL*data[i]);
1377        assert(std::abs(r2.getDataAtOffset(i)-data[i]) <= REL_TOL*data[i]);        assert(std::abs(r2.getDataAtOffsetRO(i)-data[i]) <= REL_TOL*data[i]);
1378        assert(std::abs(r3.getDataAtOffset(i)-data[i]) <= REL_TOL*data[i]);        assert(std::abs(r3.getDataAtOffsetRO(i)-data[i]) <= REL_TOL*data[i]);
1379        assert(std::abs(r4.getDataAtOffset(i)-pow(data[i],i)) <=REL_TOL*pow(data[i],i));        assert(std::abs(r4.getDataAtOffsetRO(i)-pow(data[i],i)) <=REL_TOL*pow(data[i],i));
1380      }      }
1381    }    }
1382  }  }
# Line 1422  TestSuite* DataTestCase::suite () Line 1423  TestSuite* DataTestCase::suite ()
1423    testSuite->addTest (new TestCaller< DataTestCase>("testConstructors",&DataTestCase::testConstructors));    testSuite->addTest (new TestCaller< DataTestCase>("testConstructors",&DataTestCase::testConstructors));
1424    testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));    testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));
1425    testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));    testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));
   //testSuite->addTest (new TestCaller< DataTestCase>("testRefValue",&DataTestCase::testRefValue));  
1426    testSuite->addTest (new TestCaller< DataTestCase>("testMemAlloc",&DataTestCase::testMemAlloc));    testSuite->addTest (new TestCaller< DataTestCase>("testMemAlloc",&DataTestCase::testMemAlloc));
1427    testSuite->addTest (new TestCaller< DataTestCase>("Resolving",&DataTestCase::testResolveType));    testSuite->addTest (new TestCaller< DataTestCase>("Resolving",&DataTestCase::testResolveType));
1428    

Legend:
Removed from v.2147  
changed lines
  Added in v.2271

  ViewVC Help
Powered by ViewVC 1.1.26