/[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 1795 by trankine, Fri Jan 11 07:45:58 2008 UTC revision 1796 by jfenwick, Wed Sep 17 01:45:46 2008 UTC
# Line 25  using namespace CppUnitTest; Line 25  using namespace CppUnitTest;
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;
29    
30  void DataConstantTestCase::setUp() {  void DataConstantTestCase::setUp() {
31    //    //
# Line 36  void DataConstantTestCase::tearDown() { Line 37  void DataConstantTestCase::tearDown() {
37    // This is called after each test has been run    // This is called after each test has been run
38  }  }
39    
40    
41    namespace
42    {
43    
44    ValueType::reference
45    getRef(DataAbstract& data,int i, int j, int k)
46    {
47       return data.getVector()[getRelIndex(data.getShape(),i,j,k)];
48    }
49    
50    
51    }
52    
53    
54  void DataConstantTestCase::testAll() {  void DataConstantTestCase::testAll() {
55    
56    cout << endl;    cout << endl;
57    
58    //    //
59    // Create a scalar pointData    // Create a scalar pointData
60    DataArrayView::ShapeType shape;    DataTypes::ShapeType shape;
61    DataArrayView::ValueType data(DataArrayView::noValues(shape),0);    DataTypes::ValueType data(DataTypes::noValues(shape),0);
62    DataArrayView pointData(data,shape);  //  DataArrayView pointData(data,shape);
63    
64    //    //
65    // assign an arbitrary value    // assign an arbitrary value
66    pointData()=1.0;    data[0]=1.0;
67    
68    //    //
69    // Test construction    // Test construction
70    cout << "\tTesting default constructor." << endl;    cout << "\tTesting default constructor." << endl;
71    DataConstant testData(pointData, FunctionSpace());    DataConstant testData(FunctionSpace(),shape,data);
72    
73    cout << "\tTest getLength." << endl;    cout << "\tTest getLength." << endl;
74    assert(testData.getLength()==1);    assert(testData.getLength()==1);
# Line 96  void DataConstantTestCase::testAll() { Line 111  void DataConstantTestCase::testAll() {
111  */  */
112    
113    cout << "\tTesting alternative constructor." << endl;    cout << "\tTesting alternative constructor." << endl;
114    DataArrayView::ValueType data1(DataArrayView::noValues(shape),1.0);    DataTypes::ValueType data1(DataTypes::noValues(shape),1.0);
115    // do not call the FunctionSpace constructor directly    // do not call the FunctionSpace constructor directly
116    // in the argument of DataConstant    // in the argument of DataConstant
117    // GCC chokes on it.    // GCC chokes on it.
# Line 106  void DataConstantTestCase::testAll() { Line 121  void DataConstantTestCase::testAll() {
121    for (int k=0;k<shape[2];k++) {    for (int k=0;k<shape[2];k++) {
122      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
123        for (int i=0;i<shape[0];i++) {        for (int i=0;i<shape[0];i++) {
124      assert(testData1.getPointDataView()(i,j,k)==1.0);      assert(getRef(testData1,i,j,k)==1.0);
125        }        }
126      }      }
127    }    }
# Line 114  void DataConstantTestCase::testAll() { Line 129  void DataConstantTestCase::testAll() {
129    cout << "\tTest getLength." << endl;    cout << "\tTest getLength." << endl;
130    assert(testData1.getLength()==126);    assert(testData1.getLength()==126);
131    
132    cout << "\tVerify data point attributes." << endl;  //   cout << "\tVerify data point attributes." << endl;
133    DataArrayView dataView=testData1.getPointDataView();  // //   DataArrayView dataView=testData1.getPointDataView();
134    assert(dataView.getRank()==3);  //   assert(data.getRank()==3);
135    assert(dataView.noValues()==126);  //   assert(data.getNoValues()==126);
136    assert(dataView.getShape()[0]==2);  //   assert(data.getShape()[0]==2);
137    assert(dataView.getShape()[1]==3);  //   assert(data.getShape()[1]==3);
138    assert(dataView.getShape()[2]==21);  //   assert(data.getShape()[2]==21);
139    
140    cout << "\tTesting copy constructor." << endl;    cout << "\tTesting copy constructor." << endl;
141    DataConstant testData2(testData1);    DataConstant testData2(testData1);
# Line 128  void DataConstantTestCase::testAll() { Line 143  void DataConstantTestCase::testAll() {
143    for (int k=0;k<shape[2];k++) {    for (int k=0;k<shape[2];k++) {
144      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
145        for (int i=0;i<shape[0];i++) {        for (int i=0;i<shape[0];i++) {
146      assert(testData2.getPointDataView()(i,j,k)==pointData());      assert(getRef(testData2,i,j,k)==data[0]);
147        }        }
148      }      }
149    }    }
# Line 137  void DataConstantTestCase::testAll() { Line 152  void DataConstantTestCase::testAll() {
152    assert(testData2.getLength()==126);    assert(testData2.getLength()==126);
153    
154    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
155    dataView=testData2.getPointDataView();  //  dataView=testData2.getPointDataView();
156    assert(dataView.getRank()==3);    assert(testData2.getRank()==3);
157    assert(dataView.noValues()==126);    assert(testData2.getNoValues()==126);
158    assert(dataView.getShape()[0]==2);    assert(testData2.getShape()[0]==2);
159    assert(dataView.getShape()[1]==3);    assert(testData2.getShape()[1]==3);
160    assert(dataView.getShape()[2]==21);    assert(testData2.getShape()[2]==21);
161    
162    cout << "\tTest slicing (whole object)." << endl;    cout << "\tTest slicing (whole object)." << endl;
163    
164    DataArrayView::RegionType region;    DataTypes::RegionType region;
165    region.push_back(DataArrayView::RegionType::value_type(0,shape[0]));    region.push_back(DataTypes::RegionType::value_type(0,shape[0]));
166    region.push_back(DataArrayView::RegionType::value_type(0,shape[1]));    region.push_back(DataTypes::RegionType::value_type(0,shape[1]));
167    region.push_back(DataArrayView::RegionType::value_type(0,shape[2]));    region.push_back(DataTypes::RegionType::value_type(0,shape[2]));
168    
169    DataAbstract* testData3=testData2.getSlice(region);    DataAbstract* testData3=testData2.getSlice(region);
170    
171    for (int k=0;k<shape[2];k++) {    for (int k=0;k<shape[2];k++) {
172      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
173        for (int i=0;i<shape[0];i++) {        for (int i=0;i<shape[0];i++) {
174      assert(testData3->getPointDataView()(i,j,k)==pointData());      assert(getRef(*testData3,i,j,k)==data[0]);
175        }        }
176      }      }
177    }    }
# Line 164  void DataConstantTestCase::testAll() { Line 179  void DataConstantTestCase::testAll() {
179    assert(testData3->getLength()==126);    assert(testData3->getLength()==126);
180    
181    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
182    dataView=testData3->getPointDataView();  //   dataView=testData3->getPointDataView();
183    assert(dataView.getRank()==3);    assert(testData3->getRank()==3);
184    assert(dataView.noValues()==126);    assert(testData3->getNoValues()==126);
185    assert(dataView.getShape()[0]==2);    assert(testData3->getShape()[0]==2);
186    assert(dataView.getShape()[1]==3);    assert(testData3->getShape()[1]==3);
187    assert(dataView.getShape()[2]==21);    assert(testData3->getShape()[2]==21);
188    
189    cout << "\tTest slicing (part object)." << endl;    cout << "\tTest slicing (part object)." << endl;
190    
191    DataArrayView::RegionType region2;    DataTypes::RegionType region2;
192    region2.push_back(DataArrayView::RegionType::value_type(0,2));    region2.push_back(DataTypes::RegionType::value_type(0,2));
193    region2.push_back(DataArrayView::RegionType::value_type(0,2));    region2.push_back(DataTypes::RegionType::value_type(0,2));
194    region2.push_back(DataArrayView::RegionType::value_type(0,2));    region2.push_back(DataTypes::RegionType::value_type(0,2));
195    
196    DataAbstract* testData4=testData3->getSlice(region2);    DataAbstract* testData4=testData3->getSlice(region2);
197    
198    for (int k=0;k<2;k++) {    for (int k=0;k<2;k++) {
199      for (int j=0;j<2;j++) {      for (int j=0;j<2;j++) {
200        for (int i=0;i<2;i++) {        for (int i=0;i<2;i++) {
201      assert(testData4->getPointDataView()(i,j,k)==pointData());      assert(getRef(*testData4,i,j,k)==data[0]);
202        }        }
203      }      }
204    }    }
# Line 191  void DataConstantTestCase::testAll() { Line 206  void DataConstantTestCase::testAll() {
206    assert(testData4->getLength()==8);    assert(testData4->getLength()==8);
207    
208    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
209    dataView=testData4->getPointDataView();  //   dataView=testData4->getPointDataView();
210    assert(dataView.getRank()==3);    assert(testData4->getRank()==3);
211    assert(dataView.noValues()==8);    assert(testData4->getNoValues()==8);
212    assert(dataView.getShape()[0]==2);    assert(testData4->getShape()[0]==2);
213    assert(dataView.getShape()[1]==2);    assert(testData4->getShape()[1]==2);
214    assert(dataView.getShape()[2]==2);    assert(testData4->getShape()[2]==2);
215    
216    cout << "\tTest slicing (part object)." << endl;    cout << "\tTest slicing (part object)." << endl;
217    
218    DataArrayView::RegionType region3;    DataTypes::RegionType region3;
219    region3.push_back(DataArrayView::RegionType::value_type(1,2));    region3.push_back(DataTypes::RegionType::value_type(1,2));
220    region3.push_back(DataArrayView::RegionType::value_type(1,3));    region3.push_back(DataTypes::RegionType::value_type(1,3));
221    region3.push_back(DataArrayView::RegionType::value_type(5,9));    region3.push_back(DataTypes::RegionType::value_type(5,9));
222    
223    DataAbstract* testData5=testData3->getSlice(region3);    DataAbstract* testData5=testData3->getSlice(region3);
224    
225    for (int k=0;k<4;k++) {    for (int k=0;k<4;k++) {
226      for (int j=0;j<2;j++) {      for (int j=0;j<2;j++) {
227        for (int i=0;i<1;i++) {        for (int i=0;i<1;i++) {
228      assert(testData5->getPointDataView()(i,j,k)==pointData());      assert(getRef(*testData5,i,j,k)==data[0]);
229        }        }
230      }      }
231    }    }
# Line 218  void DataConstantTestCase::testAll() { Line 233  void DataConstantTestCase::testAll() {
233    assert(testData5->getLength()==8);    assert(testData5->getLength()==8);
234    
235    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
236    dataView=testData5->getPointDataView();  //   dataView=testData5->getPointDataView();
237    assert(dataView.getRank()==3);    assert(testData5->getRank()==3);
238    assert(dataView.noValues()==8);    assert(testData5->getNoValues()==8);
239    assert(dataView.getShape()[0]==1);    assert(testData5->getShape()[0]==1);
240    assert(dataView.getShape()[1]==2);    assert(testData5->getShape()[1]==2);
241    assert(dataView.getShape()[2]==4);    assert(testData5->getShape()[2]==4);
242    
243    cout << "\tTest slice setting (1)." << endl;    cout << "\tTest slice setting (1)." << endl;
244    
245    DataArrayView::RegionType region4;    DataTypes::RegionType region4;
246    region4.push_back(DataArrayView::RegionType::value_type(0,1));    region4.push_back(DataTypes::RegionType::value_type(0,1));
247    region4.push_back(DataArrayView::RegionType::value_type(0,2));    region4.push_back(DataTypes::RegionType::value_type(0,2));
248    region4.push_back(DataArrayView::RegionType::value_type(0,4));    region4.push_back(DataTypes::RegionType::value_type(0,4));
249    
250    DataAbstract* testData6=testData3->getSlice(region3);    DataAbstract* testData6=testData3->getSlice(region3);
251    
# Line 239  void DataConstantTestCase::testAll() { Line 254  void DataConstantTestCase::testAll() {
254    for (int k=0;k<4;k++) {    for (int k=0;k<4;k++) {
255      for (int j=0;j<2;j++) {      for (int j=0;j<2;j++) {
256        for (int i=0;i<1;i++) {        for (int i=0;i<1;i++) {
257      assert(testData5->getPointDataView()(i,j,k)==pointData());      assert(getRef(*testData5,i,j,k)==data[0]);
258        }        }
259      }      }
260    }    }
# Line 247  void DataConstantTestCase::testAll() { Line 262  void DataConstantTestCase::testAll() {
262    assert(testData5->getLength()==8);    assert(testData5->getLength()==8);
263    
264    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
265    dataView=testData5->getPointDataView();  //   dataView=testData5->getPointDataView();
266    assert(dataView.getRank()==3);    assert(testData5->getRank()==3);
267    assert(dataView.noValues()==8);    assert(testData5->getNoValues()==8);
268    assert(dataView.getShape()[0]==1);    assert(testData5->getShape()[0]==1);
269    assert(dataView.getShape()[1]==2);    assert(testData5->getShape()[1]==2);
270    assert(dataView.getShape()[2]==4);    assert(testData5->getShape()[2]==4);
271    
272    delete testData3;    delete testData3;
273    delete testData4;    delete testData4;

Legend:
Removed from v.1795  
changed lines
  Added in v.1796

  ViewVC Help
Powered by ViewVC 1.1.26