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

Contents of /trunk/escript/test/DataConstantTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1811 - (show annotations)
Thu Sep 25 23:11:13 2008 UTC (11 years, 2 months ago) by ksteube
File size: 7597 byte(s)
Copyright updated in all files

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2008 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 #include "escript/DataConstant.h"
16 #include "escript/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 using namespace escript::DataTypes;
28
29 void DataConstantTestCase::setUp() {
30 //
31 // This is called before each test is run
32 }
33
34 void DataConstantTestCase::tearDown() {
35 //
36 // This is called after each test has been run
37 }
38
39
40 namespace
41 {
42
43 ValueType::reference
44 getRef(DataAbstract& data,int i, int j, int k)
45 {
46 return data.getVector()[getRelIndex(data.getShape(),i,j,k)];
47 }
48
49
50 }
51
52
53 void DataConstantTestCase::testAll() {
54
55 cout << endl;
56
57 //
58 // Create a scalar pointData
59 DataTypes::ShapeType shape;
60 DataTypes::ValueType data(DataTypes::noValues(shape),0);
61 // DataArrayView pointData(data,shape);
62
63 //
64 // assign an arbitrary value
65 data[0]=1.0;
66
67 //
68 // Test construction
69 cout << "\tTesting default constructor." << endl;
70 DataConstant testData(FunctionSpace(),shape,data);
71
72 cout << "\tTest getLength." << endl;
73 assert(testData.getLength()==1);
74
75 shape.push_back(2);
76 shape.push_back(3);
77 shape.push_back(21);
78
79 /*
80 cout << "\tTest reshape." << endl;
81 testData.reshapeDataPoint(shape);
82 assert((unsigned int)testData.getPointDataView().getRank()==shape.size());
83
84 cout << "\tTest getPointDataView." << endl;
85 for (int k=0;k<shape[2];k++) {
86 for (int j=0;j<shape[1];j++) {
87 for (int i=0;i<shape[0];i++) {
88 assert(testData.getPointDataView()(i,j,k)==pointData());
89 }
90 }
91 }
92
93 try {
94 cout << "\tTest illegal reshape." << endl;
95 testData.reshapeDataPoint(shape);
96 assert(false);
97 }
98 catch (EsysException& e) {
99 //cout << e.toString() << endl;
100 assert(true);
101 }
102
103 cout << "\tVerify data point attributes." << endl;
104 DataArrayView dataView=testData.getPointDataView();
105 assert(dataView.getRank()==3);
106 assert(dataView.noValues()==126);
107 assert(dataView.getShape()[0]==2);
108 assert(dataView.getShape()[1]==3);
109 assert(dataView.getShape()[2]==21);
110 */
111
112 cout << "\tTesting alternative constructor." << endl;
113 DataTypes::ValueType data1(DataTypes::noValues(shape),1.0);
114 // do not call the FunctionSpace constructor directly
115 // in the argument of DataConstant
116 // GCC chokes on it.
117 FunctionSpace tmp_fns;
118 DataConstant testData1(tmp_fns, shape, data1);
119
120 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(getRef(testData1,i,j,k)==1.0);
124 }
125 }
126 }
127
128 cout << "\tTest getLength." << endl;
129 assert(testData1.getLength()==126);
130
131 // cout << "\tVerify data point attributes." << endl;
132 // // DataArrayView dataView=testData1.getPointDataView();
133 // assert(data.getRank()==3);
134 // assert(data.getNoValues()==126);
135 // assert(data.getShape()[0]==2);
136 // assert(data.getShape()[1]==3);
137 // assert(data.getShape()[2]==21);
138
139 cout << "\tTesting copy constructor." << endl;
140 DataConstant testData2(testData1);
141
142 for (int k=0;k<shape[2];k++) {
143 for (int j=0;j<shape[1];j++) {
144 for (int i=0;i<shape[0];i++) {
145 assert(getRef(testData2,i,j,k)==data[0]);
146 }
147 }
148 }
149
150 cout << "\tTest getLength." << endl;
151 assert(testData2.getLength()==126);
152
153 cout << "\tVerify data point attributes." << endl;
154 // dataView=testData2.getPointDataView();
155 assert(testData2.getRank()==3);
156 assert(testData2.getNoValues()==126);
157 assert(testData2.getShape()[0]==2);
158 assert(testData2.getShape()[1]==3);
159 assert(testData2.getShape()[2]==21);
160
161 cout << "\tTest slicing (whole object)." << endl;
162
163 DataTypes::RegionType region;
164 region.push_back(DataTypes::RegionType::value_type(0,shape[0]));
165 region.push_back(DataTypes::RegionType::value_type(0,shape[1]));
166 region.push_back(DataTypes::RegionType::value_type(0,shape[2]));
167
168 DataAbstract* testData3=testData2.getSlice(region);
169
170 for (int k=0;k<shape[2];k++) {
171 for (int j=0;j<shape[1];j++) {
172 for (int i=0;i<shape[0];i++) {
173 assert(getRef(*testData3,i,j,k)==data[0]);
174 }
175 }
176 }
177
178 assert(testData3->getLength()==126);
179
180 cout << "\tVerify data point attributes." << endl;
181 // dataView=testData3->getPointDataView();
182 assert(testData3->getRank()==3);
183 assert(testData3->getNoValues()==126);
184 assert(testData3->getShape()[0]==2);
185 assert(testData3->getShape()[1]==3);
186 assert(testData3->getShape()[2]==21);
187
188 cout << "\tTest slicing (part object)." << endl;
189
190 DataTypes::RegionType region2;
191 region2.push_back(DataTypes::RegionType::value_type(0,2));
192 region2.push_back(DataTypes::RegionType::value_type(0,2));
193 region2.push_back(DataTypes::RegionType::value_type(0,2));
194
195 DataAbstract* testData4=testData3->getSlice(region2);
196
197 for (int k=0;k<2;k++) {
198 for (int j=0;j<2;j++) {
199 for (int i=0;i<2;i++) {
200 assert(getRef(*testData4,i,j,k)==data[0]);
201 }
202 }
203 }
204
205 assert(testData4->getLength()==8);
206
207 cout << "\tVerify data point attributes." << endl;
208 // dataView=testData4->getPointDataView();
209 assert(testData4->getRank()==3);
210 assert(testData4->getNoValues()==8);
211 assert(testData4->getShape()[0]==2);
212 assert(testData4->getShape()[1]==2);
213 assert(testData4->getShape()[2]==2);
214
215 cout << "\tTest slicing (part object)." << endl;
216
217 DataTypes::RegionType region3;
218 region3.push_back(DataTypes::RegionType::value_type(1,2));
219 region3.push_back(DataTypes::RegionType::value_type(1,3));
220 region3.push_back(DataTypes::RegionType::value_type(5,9));
221
222 DataAbstract* testData5=testData3->getSlice(region3);
223
224 for (int k=0;k<4;k++) {
225 for (int j=0;j<2;j++) {
226 for (int i=0;i<1;i++) {
227 assert(getRef(*testData5,i,j,k)==data[0]);
228 }
229 }
230 }
231
232 assert(testData5->getLength()==8);
233
234 cout << "\tVerify data point attributes." << endl;
235 // dataView=testData5->getPointDataView();
236 assert(testData5->getRank()==3);
237 assert(testData5->getNoValues()==8);
238 assert(testData5->getShape()[0]==1);
239 assert(testData5->getShape()[1]==2);
240 assert(testData5->getShape()[2]==4);
241
242 cout << "\tTest slice setting (1)." << endl;
243
244 DataTypes::RegionType region4;
245 region4.push_back(DataTypes::RegionType::value_type(0,1));
246 region4.push_back(DataTypes::RegionType::value_type(0,2));
247 region4.push_back(DataTypes::RegionType::value_type(0,4));
248
249 DataAbstract* testData6=testData3->getSlice(region3);
250
251 testData5->setSlice(testData6,region4);
252
253 for (int k=0;k<4;k++) {
254 for (int j=0;j<2;j++) {
255 for (int i=0;i<1;i++) {
256 assert(getRef(*testData5,i,j,k)==data[0]);
257 }
258 }
259 }
260
261 assert(testData5->getLength()==8);
262
263 cout << "\tVerify data point attributes." << endl;
264 // dataView=testData5->getPointDataView();
265 assert(testData5->getRank()==3);
266 assert(testData5->getNoValues()==8);
267 assert(testData5->getShape()[0]==1);
268 assert(testData5->getShape()[1]==2);
269 assert(testData5->getShape()[2]==4);
270
271 delete testData3;
272 delete testData4;
273 delete testData5;
274 delete testData6;
275 }
276
277 TestSuite* DataConstantTestCase::suite ()
278 {
279 //
280 // create the suite of tests to perform.
281 TestSuite *testSuite = new TestSuite ("DataConstantTestCase");
282
283 testSuite->addTest (new TestCaller< DataConstantTestCase>("testAll",&DataConstantTestCase::testAll));
284 return testSuite;
285 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26