/[escript]/branches/arrayview_from_1695_trunk/escript/test/DataConstantTestCase.cpp
ViewVC logotype

Contents of /branches/arrayview_from_1695_trunk/escript/test/DataConstantTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1747 - (show annotations)
Wed Sep 3 04:56:50 2008 UTC (11 years, 3 months ago) by jfenwick
File size: 7632 byte(s)
Branch commit.

Current status, this version compiles as passes run_tests (haven't tried 
all_tests), provided that the following files are moved out of the way:

DataAlgorithmAdapterTestCase.h 
DataTaggedTestCase.cpp 
DataTestCase.cpp 
DataTaggedTestCase.h

(They are not run by the unit tests at the moment).

I will fix those next.



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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26