/[escript]/trunk/escript/test/DataExpandedTestCase.cpp
ViewVC logotype

Diff of /trunk/escript/test/DataExpandedTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3596 by jfenwick, Thu Jan 28 02:03:15 2010 UTC revision 3597 by caltinay, Thu Sep 15 06:03:17 2011 UTC
# Line 12  Line 12 
12  *******************************************************/  *******************************************************/
13    
14    
15    #include "DataExpandedTestCase.h"
16  #include "escript/FunctionSpace.h"  #include "escript/FunctionSpace.h"
17  #include "escript/DataExpanded.h"  #include "escript/DataExpanded.h"
18  #include "esysUtils/EsysException.h"  #include "esysUtils/EsysException.h"
 #include "DataExpandedTestCase.h"  
19  #include "escript/DataReady.h"  #include "escript/DataReady.h"
20    
21    #include <cppunit/TestCaller.h>
22  #include <iostream>  #include <iostream>
23    
24  using namespace CppUnitTest;  using namespace CppUnit;
25  using namespace escript;  using namespace escript;
26  using namespace std;  using namespace std;
27  using namespace esysUtils;  using namespace esysUtils;
28  using namespace escript::DataTypes;  using namespace escript::DataTypes;
29    
 void DataExpandedTestCase::setUp() {  
   //  
   // This is called before each test is run  
   
 }  
   
 void DataExpandedTestCase::tearDown() {  
   //  
   // This is called after each test has been run  
   
 }  
   
30  namespace  namespace
31  {  {
32    
# Line 79  resolveAndDelete(DataAbstract* p) Line 68  resolveAndDelete(DataAbstract* p)
68  }  }
69    
70    
71  void DataExpandedTestCase::testAll() {  void DataExpandedTestCase::testAll()
72    {
73    cout << endl;    cout << endl;
74    
75    //    //
# Line 102  void DataExpandedTestCase::testAll() { Line 91  void DataExpandedTestCase::testAll() {
91    DataExpanded testData(FunctionSpace(), shape, data);    DataExpanded testData(FunctionSpace(), shape, data);
92    
93  //   cout << "\tTest getLength." << endl;  //   cout << "\tTest getLength." << endl;
94  //   assert(testData.getLength()==pointData.getNoValues());  //   CPPUNIT_ASSERT(testData.getLength()==pointData.getNoValues());
95    
96    cout << "\tTest getDataAtOffset." << endl;    cout << "\tTest getDataAtOffset." << endl;
97    for (int i=0;i<testData.getShape()[0];i++) {    for (int i=0;i<testData.getShape()[0];i++) {
98        assert(testData.getDataAtOffsetRO(i)==data[i]);        CPPUNIT_ASSERT(testData.getDataAtOffsetRO(i)==data[i]);
99    }    }
100    
101    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
102  //  DataArrayView dataView=testData.getPointDataView();  //  DataArrayView dataView=testData.getPointDataView();
103    assert(testData.getRank()==shape.size());    CPPUNIT_ASSERT(testData.getRank()==shape.size());
104    assert(testData.getNoValues()==shape[0]*1);    CPPUNIT_ASSERT(testData.getNoValues()==shape[0]*1);
105    assert(testData.getShape()[0]==shape[0]);    CPPUNIT_ASSERT(testData.getShape()[0]==shape[0]);
106    assert(testData.getNumDPPSample()==1);    CPPUNIT_ASSERT(testData.getNumDPPSample()==1);
107    assert(testData.getNumSamples()==1);    CPPUNIT_ASSERT(testData.getNumSamples()==1);
108    assert(testData.validSamplePointNo(testData.getNumDPPSample()-1));    CPPUNIT_ASSERT(testData.validSamplePointNo(testData.getNumDPPSample()-1));
109    assert(testData.validSampleNo(testData.getNumSamples()-1));    CPPUNIT_ASSERT(testData.validSampleNo(testData.getNumSamples()-1));
110    
111    //    //
112    // Test alternative constructor    // Test alternative constructor
# Line 129  void DataExpandedTestCase::testAll() { Line 118  void DataExpandedTestCase::testAll() {
118    DataExpanded testData1(tmp_fns,shape,data);    DataExpanded testData1(tmp_fns,shape,data);
119    
120  //   cout << "\tTest getLength." << endl;  //   cout << "\tTest getLength." << endl;
121  //   assert(testData1.getLength()==pointData.noValues());  //   CPPUNIT_ASSERT(testData1.getLength()==pointData.noValues());
122    
123  //   cout << "\tTest getPointDataView." << endl;  //   cout << "\tTest getPointDataView." << endl;
124  //   for (int i=0;i<testData1.getPointDataView().getShape()[0];i++) {  //   for (int i=0;i<testData1.getPointDataView().getShape()[0];i++) {
125  //       assert(testData1.getPointDataView()(i)==pointData(i));  //       CPPUNIT_ASSERT(testData1.getPointDataView()(i)==pointData(i));
126  //   }  //   }
127    
128    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
129  //  dataView=testData1.getPointDataView();  //  dataView=testData1.getPointDataView();
130    assert(testData1.getRank()==shape.size());    CPPUNIT_ASSERT(testData1.getRank()==shape.size());
131    assert(testData1.getNoValues()==shape[0]*1);    CPPUNIT_ASSERT(testData1.getNoValues()==shape[0]*1);
132    assert(testData1.getShape()[0]==shape[0]);    CPPUNIT_ASSERT(testData1.getShape()[0]==shape[0]);
133    assert(testData1.getNumDPPSample()==1);    CPPUNIT_ASSERT(testData1.getNumDPPSample()==1);
134    assert(testData1.getNumSamples()==1);    CPPUNIT_ASSERT(testData1.getNumSamples()==1);
135    assert(testData1.validSamplePointNo(testData1.getNumDPPSample()-1));    CPPUNIT_ASSERT(testData1.validSamplePointNo(testData1.getNumDPPSample()-1));
136    assert(testData1.validSampleNo(testData1.getNumSamples()-1));    CPPUNIT_ASSERT(testData1.validSampleNo(testData1.getNumSamples()-1));
137    
138    //    //
139    // Test copy constructor    // Test copy constructor
# Line 152  void DataExpandedTestCase::testAll() { Line 141  void DataExpandedTestCase::testAll() {
141    DataExpanded testData2(testData);    DataExpanded testData2(testData);
142    
143    cout << "\tTest getLength." << endl;    cout << "\tTest getLength." << endl;
144    assert(testData2.getLength()==data.size());    CPPUNIT_ASSERT(testData2.getLength()==data.size());
145    
146    cout << "\tTest getPointDataView." << endl;    cout << "\tTest getPointDataView." << endl;
147    for (int i=0;i<testData2.getShape()[0];i++) {    for (int i=0;i<testData2.getShape()[0];i++) {
148      assert(testData2.getDataAtOffsetRO(i)==data[i]);      CPPUNIT_ASSERT(testData2.getDataAtOffsetRO(i)==data[i]);
149    }    }
150    
151    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
152  //   dataView=testData2.getPointDataView();  //   dataView=testData2.getPointDataView();
153    assert(testData2.getRank()==shape.size());    CPPUNIT_ASSERT(testData2.getRank()==shape.size());
154    assert(testData2.getNoValues()==shape[0]*1);    CPPUNIT_ASSERT(testData2.getNoValues()==shape[0]*1);
155    assert(testData2.getShape()[0]==shape[0]);    CPPUNIT_ASSERT(testData2.getShape()[0]==shape[0]);
156    assert(testData2.getNumDPPSample()==1);    CPPUNIT_ASSERT(testData2.getNumDPPSample()==1);
157    assert(testData2.getNumSamples()==1);    CPPUNIT_ASSERT(testData2.getNumSamples()==1);
158    assert(testData2.validSamplePointNo(testData2.getNumDPPSample()-1));    CPPUNIT_ASSERT(testData2.validSamplePointNo(testData2.getNumDPPSample()-1));
159    assert(testData2.validSampleNo(testData2.getNumSamples()-1));    CPPUNIT_ASSERT(testData2.validSampleNo(testData2.getNumSamples()-1));
160    
161  }  }
162    
# Line 204  void DataExpandedTestCase::testSlicing() Line 193  void DataExpandedTestCase::testSlicing()
193    // Verify data values    // Verify data values
194    cout << "\tVerify data point values." << endl;    cout << "\tVerify data point values." << endl;
195    for (int i=0;i<testData2->getShape()[0];i++) {    for (int i=0;i<testData2->getShape()[0];i++) {
196      assert(testData2->getDataAtOffsetRO(i)==data[region[0].first+i]);      CPPUNIT_ASSERT(testData2->getDataAtOffsetRO(i)==data[region[0].first+i]);
197    }    }
198  }  }
199    
# Line 249  void DataExpandedTestCase::testSlicing2( Line 238  void DataExpandedTestCase::testSlicing2(
238    cout << "\tVerify data point values." << endl;    cout << "\tVerify data point values." << endl;
239    for (int j=0;j<testData2->getShape()[1];j++) {    for (int j=0;j<testData2->getShape()[1];j++) {
240      for (int i=0;i<testData2->getShape()[0];i++) {      for (int i=0;i<testData2->getShape()[0];i++) {
241        assert(getRefRO(*testData2,i,j)==data[getRelIndex(shape,region[0].first+i,region[1].first+j)]);        CPPUNIT_ASSERT(getRefRO(*testData2,i,j)==data[getRelIndex(shape,region[0].first+i,region[1].first+j)]);
242      }      }
243    }    }
244    
245    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
246  //   DataArrayView dataView=testData2->getPointDataView();  //   DataArrayView dataView=testData2->getPointDataView();
247    assert(testData2->getRank()==region.size());    CPPUNIT_ASSERT(testData2->getRank()==region.size());
248    assert(testData2->getNoValues()==(region[0].second-region[0].first)*(region[1].second-region[1].first));    CPPUNIT_ASSERT(testData2->getNoValues()==(region[0].second-region[0].first)*(region[1].second-region[1].first));
249    assert(testData2->getShape()[0]==(region[0].second-region[0].first));    CPPUNIT_ASSERT(testData2->getShape()[0]==(region[0].second-region[0].first));
250    assert(testData2->getShape()[1]==(region[1].second-region[1].first));    CPPUNIT_ASSERT(testData2->getShape()[1]==(region[1].second-region[1].first));
251    
252    cout << "\tTest slicing (part object)." << endl;    cout << "\tTest slicing (part object)." << endl;
253    DataTypes::RegionType region2;    DataTypes::RegionType region2;
# Line 270  void DataExpandedTestCase::testSlicing2( Line 259  void DataExpandedTestCase::testSlicing2(
259    cout << "\tVerify data point values." << endl;    cout << "\tVerify data point values." << endl;
260    for (int j=0;j<testData3->getShape()[1];j++) {    for (int j=0;j<testData3->getShape()[1];j++) {
261      for (int i=0;i<testData3->getShape()[0];i++) {      for (int i=0;i<testData3->getShape()[0];i++) {
262        assert(getRefRO(*testData3,i,j)==getDRef(data,shape,region2[0].first+i,region2[1].first+j));        CPPUNIT_ASSERT(getRefRO(*testData3,i,j)==getDRef(data,shape,region2[0].first+i,region2[1].first+j));
263      }      }
264    }    }
265    
266    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
267  //   dataView=testData3->getPointDataView();  //   dataView=testData3->getPointDataView();
268    assert(testData3->getRank()==region2.size());    CPPUNIT_ASSERT(testData3->getRank()==region2.size());
269    assert(testData3->getNoValues()==(region2[0].second-region2[0].first)*(region2[1].second-region2[1].first));    CPPUNIT_ASSERT(testData3->getNoValues()==(region2[0].second-region2[0].first)*(region2[1].second-region2[1].first));
270    assert(testData3->getShape()[0]==(region2[0].second-region2[0].first));    CPPUNIT_ASSERT(testData3->getShape()[0]==(region2[0].second-region2[0].first));
271    assert(testData3->getShape()[1]==(region2[1].second-region2[1].first));    CPPUNIT_ASSERT(testData3->getShape()[1]==(region2[1].second-region2[1].first));
272    
273  //   delete testData2;  //   delete testData2;
274  //   delete testData3;  //   delete testData3;
# Line 349  void DataExpandedTestCase::testSlicing3( Line 338  void DataExpandedTestCase::testSlicing3(
338    for (int k=0;k<testData2->getShape()[2];k++) {    for (int k=0;k<testData2->getShape()[2];k++) {
339      for (int j=0;j<testData2->getShape()[1];j++) {      for (int j=0;j<testData2->getShape()[1];j++) {
340        for (int i=0;i<testData2->getShape()[0];i++) {        for (int i=0;i<testData2->getShape()[0];i++) {
341          assert(getRefRO(*testData2,i,j,k)==getDRef(data,shape,region[0].first+i,          CPPUNIT_ASSERT(getRefRO(*testData2,i,j,k)==getDRef(data,shape,region[0].first+i,
342                                                                 region[1].first+j,                                                                 region[1].first+j,
343                                                                 region[2].first+k));                                                                 region[2].first+k));
344        }        }
# Line 358  void DataExpandedTestCase::testSlicing3( Line 347  void DataExpandedTestCase::testSlicing3(
347    
348    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
349  //   DataArrayView dataView=testData2->getPointDataView();  //   DataArrayView dataView=testData2->getPointDataView();
350    assert(testData2->getRank()==region.size());    CPPUNIT_ASSERT(testData2->getRank()==region.size());
351    assert(testData2->getNoValues()==(region[0].second-region[0].first)    CPPUNIT_ASSERT(testData2->getNoValues()==(region[0].second-region[0].first)
352                                 *(region[1].second-region[1].first)                                 *(region[1].second-region[1].first)
353                                 *(region[2].second-region[2].first));                                 *(region[2].second-region[2].first));
354    assert(testData2->getShape()[0]==(region[0].second-region[0].first));    CPPUNIT_ASSERT(testData2->getShape()[0]==(region[0].second-region[0].first));
355    assert(testData2->getShape()[1]==(region[1].second-region[1].first));    CPPUNIT_ASSERT(testData2->getShape()[1]==(region[1].second-region[1].first));
356    assert(testData2->getShape()[2]==(region[2].second-region[2].first));    CPPUNIT_ASSERT(testData2->getShape()[2]==(region[2].second-region[2].first));
357    
358    cout << "\tTest slicing (part object)." << endl;    cout << "\tTest slicing (part object)." << endl;
359    DataTypes::RegionType region2;    DataTypes::RegionType region2;
# Line 379  void DataExpandedTestCase::testSlicing3( Line 368  void DataExpandedTestCase::testSlicing3(
368    for (int k=0;k<testData3->getShape()[2];k++) {    for (int k=0;k<testData3->getShape()[2];k++) {
369      for (int j=0;j<testData3->getShape()[1];j++) {      for (int j=0;j<testData3->getShape()[1];j++) {
370        for (int i=0;i<testData3->getShape()[0];i++) {        for (int i=0;i<testData3->getShape()[0];i++) {
371          assert(getRefRO(*testData3,i,j,k)==getDRef(data,shape,region2[0].first+i,          CPPUNIT_ASSERT(getRefRO(*testData3,i,j,k)==getDRef(data,shape,region2[0].first+i,
372                                                                 region2[1].first+j,                                                                 region2[1].first+j,
373                                                                 region2[2].first+k));                                                                 region2[2].first+k));
374        }        }
# Line 388  void DataExpandedTestCase::testSlicing3( Line 377  void DataExpandedTestCase::testSlicing3(
377    
378    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
379  //   dataView=testData2->getPointDataView();  //   dataView=testData2->getPointDataView();
380    assert(testData2->getRank()==region.size());    CPPUNIT_ASSERT(testData2->getRank()==region.size());
381    assert(testData2->getNoValues()==(region[0].second-region[0].first)    CPPUNIT_ASSERT(testData2->getNoValues()==(region[0].second-region[0].first)
382                                 *(region[1].second-region[1].first)                                 *(region[1].second-region[1].first)
383                                 *(region[2].second-region[2].first));                                 *(region[2].second-region[2].first));
384    assert(testData2->getShape()[0]==(region[0].second-region[0].first));    CPPUNIT_ASSERT(testData2->getShape()[0]==(region[0].second-region[0].first));
385    assert(testData2->getShape()[1]==(region[1].second-region[1].first));    CPPUNIT_ASSERT(testData2->getShape()[1]==(region[1].second-region[1].first));
386    assert(testData2->getShape()[2]==(region[2].second-region[2].first));    CPPUNIT_ASSERT(testData2->getShape()[2]==(region[2].second-region[2].first));
387    
388  //   delete testData2;  //   delete testData2;
389  //  delete testData3;  //  delete testData3;
# Line 469  void DataExpandedTestCase::testSliceSett Line 458  void DataExpandedTestCase::testSliceSett
458    cout << "\tVerify data point values." << endl;    cout << "\tVerify data point values." << endl;
459    for (int j=region2[1].first;j<region2[1].second;j++) {    for (int j=region2[1].first;j<region2[1].second;j++) {
460      for (int i=region2[0].first;i<region2[0].second;i++) {      for (int i=region2[0].first;i<region2[0].second;i++) {
461        assert(getRefRO(testData2,i,j)==data[getRelIndex(shape,i-(region[0].second-1),j-(region[1].second-1))]);        CPPUNIT_ASSERT(getRefRO(testData2,i,j)==data[getRelIndex(shape,i-(region[0].second-1),j-(region[1].second-1))]);
462      }      }
463     }     }
464    
# Line 538  void DataExpandedTestCase::testSliceSett Line 527  void DataExpandedTestCase::testSliceSett
527    cout << "\tVerify data point values." << endl;    cout << "\tVerify data point values." << endl;
528    for (int j=region2[1].first;j<region2[1].second;j++) {    for (int j=region2[1].first;j<region2[1].second;j++) {
529      for (int i=region2[0].first;i<region2[0].second;i++) {      for (int i=region2[0].first;i<region2[0].second;i++) {
530        assert(getRefRO(testData2,i,j)==data[0]);        CPPUNIT_ASSERT(getRefRO(testData2,i,j)==data[0]);
531      }      }
532     }     }
533    
# Line 547  void DataExpandedTestCase::testSliceSett Line 536  void DataExpandedTestCase::testSliceSett
536  }  }
537    
538    
539    TestSuite* DataExpandedTestCase::suite()
   
   
 TestSuite* DataExpandedTestCase::suite ()  
540  {  {
   //  
541    // Create the suite of tests to perform.    // Create the suite of tests to perform.
542    TestSuite *testSuite = new TestSuite ("DataExpandedTestCase");    TestSuite *testSuite = new TestSuite("DataExpandedTestCase");
543    testSuite->addTest (new TestCaller< DataExpandedTestCase>("testAll",&DataExpandedTestCase::testAll));    testSuite->addTest(new TestCaller<DataExpandedTestCase>(
544    testSuite->addTest (new TestCaller< DataExpandedTestCase>("testSlicing",&DataExpandedTestCase::testSlicing));                "testAll",&DataExpandedTestCase::testAll));
545    testSuite->addTest (new TestCaller< DataExpandedTestCase>("testSlicing2",&DataExpandedTestCase::testSlicing2));    testSuite->addTest(new TestCaller<DataExpandedTestCase>(
546    testSuite->addTest (new TestCaller< DataExpandedTestCase>("testSlicing3",&DataExpandedTestCase::testSlicing3));                "testSlicing",&DataExpandedTestCase::testSlicing));
547    testSuite->addTest (new TestCaller< DataExpandedTestCase>("testSliceSetting",&DataExpandedTestCase::testSliceSetting));    testSuite->addTest(new TestCaller<DataExpandedTestCase>(
548    testSuite->addTest (new TestCaller< DataExpandedTestCase>("testSliceSetting2",&DataExpandedTestCase::testSliceSetting2));                "testSlicing2",&DataExpandedTestCase::testSlicing2));
549      testSuite->addTest(new TestCaller<DataExpandedTestCase>(
550                  "testSlicing3",&DataExpandedTestCase::testSlicing3));
551      testSuite->addTest(new TestCaller<DataExpandedTestCase>(
552                  "testSliceSetting",&DataExpandedTestCase::testSliceSetting));
553      testSuite->addTest(new TestCaller<DataExpandedTestCase>(
554                  "testSliceSetting2",&DataExpandedTestCase::testSliceSetting2));
555    return testSuite;    return testSuite;
556  }  }
557    

Legend:
Removed from v.3596  
changed lines
  Added in v.3597

  ViewVC Help
Powered by ViewVC 1.1.26