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

Annotation of /trunk/esys2/escript/test/DataConstant/DataConstantTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 149 - (hide annotations)
Thu Sep 1 03:31:39 2005 UTC (17 years, 6 months ago) by jgs
File size: 7822 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-09-01

1 jgs 82 // $Id$
2     /*
3     *****************************************************************************
4     * *
5     * COPYRIGHT ACcESS - All Rights Reserved *
6     * *
7     * This software is the property of ACcESS. No part of this code *
8     * may be copied in any form or by any means without the expressed written *
9     * consent of ACcESS. Copying, use or modification of this software *
10     * by any unauthorised person is illegal unless that person has a software *
11     * license agreement with ACcESS. *
12     * *
13     *****************************************************************************
14     */
15     #include "escript/Data/DataConstant.h"
16     #include "escript/Data/FunctionSpace.h"
17     #include "esysUtils/EsysException.h"
18    
19     #include "DataConstantTestCase.h"
20    
21     #include <iostream>
22    
23     using namespace CppUnitTest;
24     using namespace escript;
25     using namespace std;
26     using namespace esysUtils;
27    
28     void DataConstantTestCase::setUp() {
29     //
30     // This is called before each test is run
31     }
32    
33     void DataConstantTestCase::tearDown() {
34     //
35     // This is called after each test has been run
36     }
37    
38     void DataConstantTestCase::testAll() {
39    
40     cout << endl;
41    
42     //
43     // Create a scalar pointData
44     DataArrayView::ShapeType shape;
45     DataArrayView::ValueType data(DataArrayView::noValues(shape),0);
46     DataArrayView pointData(data,shape);
47    
48     //
49     // assign an arbitrary value
50     pointData()=1.0;
51    
52     //
53     // Test construction
54     cout << "\tTesting default constructor." << endl;
55     DataConstant testData(pointData, FunctionSpace());
56    
57 jgs 102 cout << "\tTest getLength." << endl;
58     assert(testData.getLength()==1);
59    
60 jgs 82 cout << "\tTest reshape." << endl;
61     shape.push_back(2);
62     shape.push_back(3);
63     shape.push_back(21);
64     testData.reshapeDataPoint(shape);
65     assert(testData.getPointDataView().getRank()==shape.size());
66    
67     cout << "\tTest getPointDataView." << endl;
68 jgs 102 for (int k=0;k<shape[2];k++) {
69     for (int j=0;j<shape[1];j++) {
70     for (int i=0;i<shape[0];i++) {
71 jgs 82 assert(testData.getPointDataView()(i,j,k)==pointData());
72     }
73     }
74     }
75    
76     try {
77     cout << "\tTest illegal reshape." << endl;
78     testData.reshapeDataPoint(shape);
79     assert(false);
80     }
81     catch (EsysException& e) {
82     //cout << e.toString() << endl;
83     assert(true);
84     }
85    
86 jgs 102 cout << "\tVerify data point attributes." << endl;
87     DataArrayView dataView=testData.getPointDataView();
88     assert(dataView.getRank()==3);
89     assert(dataView.noValues()==126);
90     assert(dataView.getShape()[0]==2);
91     assert(dataView.getShape()[1]==3);
92     assert(dataView.getShape()[2]==21);
93    
94 jgs 119 cout << "\tTesting alternative constructor." << endl;
95     DataArrayView::ValueType data1(DataArrayView::noValues(shape),1.0);
96     DataConstant testData1(FunctionSpace(), shape, data1);
97    
98     for (int k=0;k<shape[2];k++) {
99     for (int j=0;j<shape[1];j++) {
100     for (int i=0;i<shape[0];i++) {
101     assert(testData1.getPointDataView()(i,j,k)==1.0);
102     }
103     }
104     }
105    
106     cout << "\tTest getLength." << endl;
107     assert(testData1.getLength()==126);
108    
109     cout << "\tVerify data point attributes." << endl;
110     dataView=testData1.getPointDataView();
111     assert(dataView.getRank()==3);
112     assert(dataView.noValues()==126);
113     assert(dataView.getShape()[0]==2);
114     assert(dataView.getShape()[1]==3);
115     assert(dataView.getShape()[2]==21);
116    
117 jgs 82 cout << "\tTesting copy constructor." << endl;
118     DataConstant testData2(testData);
119    
120 jgs 102 for (int k=0;k<shape[2];k++) {
121     for (int j=0;j<shape[1];j++) {
122     for (int i=0;i<shape[0];i++) {
123     assert(testData2.getPointDataView()(i,j,k)==pointData());
124     }
125     }
126     }
127    
128 jgs 82 cout << "\tTest getLength." << endl;
129 jgs 102 assert(testData2.getLength()==126);
130 jgs 82
131 jgs 102 cout << "\tVerify data point attributes." << endl;
132     dataView=testData2.getPointDataView();
133     assert(dataView.getRank()==3);
134     assert(dataView.noValues()==126);
135     assert(dataView.getShape()[0]==2);
136     assert(dataView.getShape()[1]==3);
137     assert(dataView.getShape()[2]==21);
138    
139     cout << "\tTest slicing (whole object)." << endl;
140    
141     DataArrayView::RegionType region;
142     region.push_back(DataArrayView::RegionType::value_type(0,shape[0]));
143     region.push_back(DataArrayView::RegionType::value_type(0,shape[1]));
144     region.push_back(DataArrayView::RegionType::value_type(0,shape[2]));
145    
146     DataAbstract* testData3=testData2.getSlice(region);
147    
148     for (int k=0;k<shape[2];k++) {
149     for (int j=0;j<shape[1];j++) {
150     for (int i=0;i<shape[0];i++) {
151     assert(testData3->getPointDataView()(i,j,k)==pointData());
152     }
153     }
154     }
155    
156     assert(testData3->getLength()==126);
157    
158     cout << "\tVerify data point attributes." << endl;
159     dataView=testData3->getPointDataView();
160     assert(dataView.getRank()==3);
161     assert(dataView.noValues()==126);
162     assert(dataView.getShape()[0]==2);
163     assert(dataView.getShape()[1]==3);
164     assert(dataView.getShape()[2]==21);
165    
166     cout << "\tTest slicing (part object)." << endl;
167    
168     DataArrayView::RegionType region2;
169     region2.push_back(DataArrayView::RegionType::value_type(0,2));
170     region2.push_back(DataArrayView::RegionType::value_type(0,2));
171     region2.push_back(DataArrayView::RegionType::value_type(0,2));
172    
173     DataAbstract* testData4=testData3->getSlice(region2);
174    
175     for (int k=0;k<2;k++) {
176     for (int j=0;j<2;j++) {
177     for (int i=0;i<2;i++) {
178     assert(testData4->getPointDataView()(i,j,k)==pointData());
179     }
180     }
181     }
182    
183     assert(testData4->getLength()==8);
184    
185     cout << "\tVerify data point attributes." << endl;
186     dataView=testData4->getPointDataView();
187     assert(dataView.getRank()==3);
188     assert(dataView.noValues()==8);
189     assert(dataView.getShape()[0]==2);
190     assert(dataView.getShape()[1]==2);
191     assert(dataView.getShape()[2]==2);
192    
193     cout << "\tTest slicing (part object)." << endl;
194    
195     DataArrayView::RegionType region3;
196     region3.push_back(DataArrayView::RegionType::value_type(1,2));
197     region3.push_back(DataArrayView::RegionType::value_type(1,3));
198     region3.push_back(DataArrayView::RegionType::value_type(5,9));
199    
200     DataAbstract* testData5=testData3->getSlice(region3);
201    
202     for (int k=0;k<4;k++) {
203     for (int j=0;j<2;j++) {
204     for (int i=0;i<1;i++) {
205     assert(testData5->getPointDataView()(i,j,k)==pointData());
206     }
207     }
208     }
209    
210     assert(testData5->getLength()==8);
211    
212     cout << "\tVerify data point attributes." << endl;
213     dataView=testData5->getPointDataView();
214     assert(dataView.getRank()==3);
215     assert(dataView.noValues()==8);
216     assert(dataView.getShape()[0]==1);
217     assert(dataView.getShape()[1]==2);
218     assert(dataView.getShape()[2]==4);
219    
220     cout << "\tTest slice setting (1)." << endl;
221    
222     DataArrayView::RegionType region4;
223     region4.push_back(DataArrayView::RegionType::value_type(0,1));
224     region4.push_back(DataArrayView::RegionType::value_type(0,2));
225     region4.push_back(DataArrayView::RegionType::value_type(0,4));
226    
227     DataAbstract* testData6=testData3->getSlice(region3);
228    
229     testData5->setSlice(testData6,region4);
230    
231     for (int k=0;k<4;k++) {
232     for (int j=0;j<2;j++) {
233     for (int i=0;i<1;i++) {
234     assert(testData5->getPointDataView()(i,j,k)==pointData());
235     }
236     }
237     }
238    
239     assert(testData5->getLength()==8);
240    
241     cout << "\tVerify data point attributes." << endl;
242     dataView=testData5->getPointDataView();
243     assert(dataView.getRank()==3);
244     assert(dataView.noValues()==8);
245     assert(dataView.getShape()[0]==1);
246     assert(dataView.getShape()[1]==2);
247     assert(dataView.getShape()[2]==4);
248    
249 jgs 149 delete testData3;
250     delete testData4;
251     delete testData5;
252     delete testData6;
253 jgs 82 }
254    
255     TestSuite* DataConstantTestCase::suite ()
256     {
257     //
258     // create the suite of tests to perform.
259     TestSuite *testSuite = new TestSuite ("DataConstantTestCase");
260    
261     testSuite->addTest (new TestCaller< DataConstantTestCase>("testAll",&DataConstantTestCase::testAll));
262     return testSuite;
263     }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26