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

Diff of /trunk/escript/test/DataConstantTestCase.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 "DataConstantTestCase.h"
16    
17  #include "escript/DataConstant.h"  #include "escript/DataConstant.h"
18  #include "escript/FunctionSpace.h"  #include "escript/FunctionSpace.h"
19  #include "esysUtils/EsysException.h"  #include "esysUtils/EsysException.h"
20    
21  #include "DataConstantTestCase.h"  #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 DataConstantTestCase::setUp() {  
   //  
   // This is called before each test is run  
 }  
   
 void DataConstantTestCase::tearDown() {  
   //  
   // This is called after each test has been run  
 }  
   
   
30  namespace  namespace
31  {  {
32    
# Line 61  resolveAndDelete(DataAbstract* p) Line 51  resolveAndDelete(DataAbstract* p)
51  }  }
52    
53    
54  void DataConstantTestCase::testAll() {  void DataConstantTestCase::testAll()
55    {
56    cout << endl;    cout << endl;
57    
58    //    //
# Line 81  void DataConstantTestCase::testAll() { Line 71  void DataConstantTestCase::testAll() {
71    DataConstant testData(FunctionSpace(),shape,data);    DataConstant testData(FunctionSpace(),shape,data);
72    
73    cout << "\tTest getLength." << endl;    cout << "\tTest getLength." << endl;
74    assert(testData.getLength()==1);    CPPUNIT_ASSERT(testData.getLength()==1);
75    
76    shape.push_back(2);    shape.push_back(2);
77    shape.push_back(3);    shape.push_back(3);
# Line 98  void DataConstantTestCase::testAll() { Line 88  void DataConstantTestCase::testAll() {
88    for (int k=0;k<shape[2];k++) {    for (int k=0;k<shape[2];k++) {
89      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
90        for (int i=0;i<shape[0];i++) {        for (int i=0;i<shape[0];i++) {
91      assert(getRefRO(testData1,i,j,k)==1.0);          CPPUNIT_ASSERT(getRefRO(testData1,i,j,k)==1.0);
92        }        }
93      }      }
94    }    }
95    
96    cout << "\tTest getLength." << endl;    cout << "\tTest getLength." << endl;
97    assert(testData1.getLength()==126);    CPPUNIT_ASSERT(testData1.getLength()==126);
98    
99    cout << "\tTesting copy constructor." << endl;    cout << "\tTesting copy constructor." << endl;
100    DataConstant testData2(testData1);    DataConstant testData2(testData1);
# Line 112  void DataConstantTestCase::testAll() { Line 102  void DataConstantTestCase::testAll() {
102    for (int k=0;k<shape[2];k++) {    for (int k=0;k<shape[2];k++) {
103      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
104        for (int i=0;i<shape[0];i++) {        for (int i=0;i<shape[0];i++) {
105      assert(getRefRO(testData2,i,j,k)==data[0]);          CPPUNIT_ASSERT(getRefRO(testData2,i,j,k)==data[0]);
106        }        }
107      }      }
108    }    }
109    
110    cout << "\tTest getLength." << endl;    cout << "\tTest getLength." << endl;
111    assert(testData2.getLength()==126);    CPPUNIT_ASSERT(testData2.getLength()==126);
112    
113    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
114    assert(testData2.getRank()==3);    CPPUNIT_ASSERT(testData2.getRank()==3);
115    assert(testData2.getNoValues()==126);    CPPUNIT_ASSERT(testData2.getNoValues()==126);
116    assert(testData2.getShape()[0]==2);    CPPUNIT_ASSERT(testData2.getShape()[0]==2);
117    assert(testData2.getShape()[1]==3);    CPPUNIT_ASSERT(testData2.getShape()[1]==3);
118    assert(testData2.getShape()[2]==21);    CPPUNIT_ASSERT(testData2.getShape()[2]==21);
119    
120    cout << "\tTest slicing (whole object)." << endl;    cout << "\tTest slicing (whole object)." << endl;
121    
# Line 139  void DataConstantTestCase::testAll() { Line 129  void DataConstantTestCase::testAll() {
129    for (int k=0;k<shape[2];k++) {    for (int k=0;k<shape[2];k++) {
130      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
131        for (int i=0;i<shape[0];i++) {        for (int i=0;i<shape[0];i++) {
132      assert(getRefRO(*testData3,i,j,k)==data[0]);          CPPUNIT_ASSERT(getRefRO(*testData3,i,j,k)==data[0]);
133        }        }
134      }      }
135    }    }
136    
137    assert(testData3->getLength()==126);    CPPUNIT_ASSERT(testData3->getLength()==126);
138    
139    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
140    assert(testData3->getRank()==3);    CPPUNIT_ASSERT(testData3->getRank()==3);
141    assert(testData3->getNoValues()==126);    CPPUNIT_ASSERT(testData3->getNoValues()==126);
142    assert(testData3->getShape()[0]==2);    CPPUNIT_ASSERT(testData3->getShape()[0]==2);
143    assert(testData3->getShape()[1]==3);    CPPUNIT_ASSERT(testData3->getShape()[1]==3);
144    assert(testData3->getShape()[2]==21);    CPPUNIT_ASSERT(testData3->getShape()[2]==21);
145    
146    cout << "\tTest slicing (part object)." << endl;    cout << "\tTest slicing (part object)." << endl;
147    
# Line 165  void DataConstantTestCase::testAll() { Line 155  void DataConstantTestCase::testAll() {
155    for (int k=0;k<2;k++) {    for (int k=0;k<2;k++) {
156      for (int j=0;j<2;j++) {      for (int j=0;j<2;j++) {
157        for (int i=0;i<2;i++) {        for (int i=0;i<2;i++) {
158      assert(getRefRO(*testData4,i,j,k)==data[0]);          CPPUNIT_ASSERT(getRefRO(*testData4,i,j,k)==data[0]);
159        }        }
160      }      }
161    }    }
162    
163    assert(testData4->getLength()==8);    CPPUNIT_ASSERT(testData4->getLength()==8);
164    
165    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
166    assert(testData4->getRank()==3);    CPPUNIT_ASSERT(testData4->getRank()==3);
167    assert(testData4->getNoValues()==8);    CPPUNIT_ASSERT(testData4->getNoValues()==8);
168    assert(testData4->getShape()[0]==2);    CPPUNIT_ASSERT(testData4->getShape()[0]==2);
169    assert(testData4->getShape()[1]==2);    CPPUNIT_ASSERT(testData4->getShape()[1]==2);
170    assert(testData4->getShape()[2]==2);    CPPUNIT_ASSERT(testData4->getShape()[2]==2);
171    
172    cout << "\tTest slicing (part object)." << endl;    cout << "\tTest slicing (part object)." << endl;
173    
# Line 191  void DataConstantTestCase::testAll() { Line 181  void DataConstantTestCase::testAll() {
181    for (int k=0;k<4;k++) {    for (int k=0;k<4;k++) {
182      for (int j=0;j<2;j++) {      for (int j=0;j<2;j++) {
183        for (int i=0;i<1;i++) {        for (int i=0;i<1;i++) {
184      assert(getRefRO(*testData5,i,j,k)==data[0]);          CPPUNIT_ASSERT(getRefRO(*testData5,i,j,k)==data[0]);
185        }        }
186      }      }
187    }    }
188    
189    assert(testData5->getLength()==8);    CPPUNIT_ASSERT(testData5->getLength()==8);
190    
191    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
192  //   dataView=testData5->getPointDataView();  //   dataView=testData5->getPointDataView();
193    assert(testData5->getRank()==3);    CPPUNIT_ASSERT(testData5->getRank()==3);
194    assert(testData5->getNoValues()==8);    CPPUNIT_ASSERT(testData5->getNoValues()==8);
195    assert(testData5->getShape()[0]==1);    CPPUNIT_ASSERT(testData5->getShape()[0]==1);
196    assert(testData5->getShape()[1]==2);    CPPUNIT_ASSERT(testData5->getShape()[1]==2);
197    assert(testData5->getShape()[2]==4);    CPPUNIT_ASSERT(testData5->getShape()[2]==4);
198    
199    cout << "\tTest slice setting (1)." << endl;    cout << "\tTest slice setting (1)." << endl;
200    
# Line 220  void DataConstantTestCase::testAll() { Line 210  void DataConstantTestCase::testAll() {
210    for (int k=0;k<4;k++) {    for (int k=0;k<4;k++) {
211      for (int j=0;j<2;j++) {      for (int j=0;j<2;j++) {
212        for (int i=0;i<1;i++) {        for (int i=0;i<1;i++) {
213      assert(getRefRO(*testData5,i,j,k)==data[0]);          CPPUNIT_ASSERT(getRefRO(*testData5,i,j,k)==data[0]);
214        }        }
215      }      }
216    }    }
217    
218    assert(testData5->getLength()==8);    CPPUNIT_ASSERT(testData5->getLength()==8);
219    
220    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
221  //   dataView=testData5->getPointDataView();  //   dataView=testData5->getPointDataView();
222    assert(testData5->getRank()==3);    CPPUNIT_ASSERT(testData5->getRank()==3);
223    assert(testData5->getNoValues()==8);    CPPUNIT_ASSERT(testData5->getNoValues()==8);
224    assert(testData5->getShape()[0]==1);    CPPUNIT_ASSERT(testData5->getShape()[0]==1);
225    assert(testData5->getShape()[1]==2);    CPPUNIT_ASSERT(testData5->getShape()[1]==2);
226    assert(testData5->getShape()[2]==4);    CPPUNIT_ASSERT(testData5->getShape()[2]==4);
227    
228  //   delete testData3;  //   delete testData3;
229  //   delete testData4;  //   delete testData4;
# Line 241  void DataConstantTestCase::testAll() { Line 231  void DataConstantTestCase::testAll() {
231    delete testData6;    delete testData6;
232  }  }
233    
234  TestSuite* DataConstantTestCase::suite ()  TestSuite* DataConstantTestCase::suite()
235  {  {
236    //    TestSuite *testSuite = new TestSuite("DataConstantTestCase");
   // create the suite of tests to perform.  
   TestSuite *testSuite = new TestSuite ("DataConstantTestCase");  
237    
238    testSuite->addTest (new TestCaller< DataConstantTestCase>("testAll",&DataConstantTestCase::testAll));    testSuite->addTest(new TestCaller<DataConstantTestCase>(
239                  "testAll",&DataConstantTestCase::testAll));
240    return testSuite;    return testSuite;
241  }  }
242    

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

  ViewVC Help
Powered by ViewVC 1.1.26