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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 682 - (show annotations)
Mon Mar 27 02:43:09 2006 UTC (13 years, 4 months ago) by robwdcock
File size: 7959 byte(s)
+ NEW BUILD SYSTEM

This commit contains the new build system with cross-platform support.
Most things work are before though you can have more control.

ENVIRONMENT settings have changed:
+ You no longer require LD_LIBRARY_PATH or PYTHONPATH to point to the
esysroot for building and testing performed via scons
+ ACcESS altix users: It is recommended you change your modules to load
the latest intel compiler and other libraries required by boost to match
the setup in svn (you can override). The correct modules are as follows

module load intel_cc.9.0.026
export
MODULEPATH=${MODULEPATH}:/data/raid2/toolspp4/modulefiles/gcc-3.3.6
module load boost/1.33.0/python-2.4.1
module load python/2.4.1
module load numarray/1.3.3


1 // $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/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
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 cout << "\tTest getLength." << endl;
58 assert(testData.getLength()==1);
59
60 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((unsigned int)testData.getPointDataView().getRank()==shape.size());
66
67 cout << "\tTest getPointDataView." << endl;
68 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 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 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 cout << "\tTesting alternative constructor." << endl;
95 DataArrayView::ValueType data1(DataArrayView::noValues(shape),1.0);
96 // do not call the FunctionSpace constructor directly
97 // in the argument of DataConstant
98 // GCC chokes on it.
99 FunctionSpace tmp_fns;
100 DataConstant testData1(tmp_fns, shape, data1);
101
102 for (int k=0;k<shape[2];k++) {
103 for (int j=0;j<shape[1];j++) {
104 for (int i=0;i<shape[0];i++) {
105 assert(testData1.getPointDataView()(i,j,k)==1.0);
106 }
107 }
108 }
109
110 cout << "\tTest getLength." << endl;
111 assert(testData1.getLength()==126);
112
113 cout << "\tVerify data point attributes." << endl;
114 dataView=testData1.getPointDataView();
115 assert(dataView.getRank()==3);
116 assert(dataView.noValues()==126);
117 assert(dataView.getShape()[0]==2);
118 assert(dataView.getShape()[1]==3);
119 assert(dataView.getShape()[2]==21);
120
121 cout << "\tTesting copy constructor." << endl;
122 DataConstant testData2(testData);
123
124 for (int k=0;k<shape[2];k++) {
125 for (int j=0;j<shape[1];j++) {
126 for (int i=0;i<shape[0];i++) {
127 assert(testData2.getPointDataView()(i,j,k)==pointData());
128 }
129 }
130 }
131
132 cout << "\tTest getLength." << endl;
133 assert(testData2.getLength()==126);
134
135 cout << "\tVerify data point attributes." << endl;
136 dataView=testData2.getPointDataView();
137 assert(dataView.getRank()==3);
138 assert(dataView.noValues()==126);
139 assert(dataView.getShape()[0]==2);
140 assert(dataView.getShape()[1]==3);
141 assert(dataView.getShape()[2]==21);
142
143 cout << "\tTest slicing (whole object)." << endl;
144
145 DataArrayView::RegionType region;
146 region.push_back(DataArrayView::RegionType::value_type(0,shape[0]));
147 region.push_back(DataArrayView::RegionType::value_type(0,shape[1]));
148 region.push_back(DataArrayView::RegionType::value_type(0,shape[2]));
149
150 DataAbstract* testData3=testData2.getSlice(region);
151
152 for (int k=0;k<shape[2];k++) {
153 for (int j=0;j<shape[1];j++) {
154 for (int i=0;i<shape[0];i++) {
155 assert(testData3->getPointDataView()(i,j,k)==pointData());
156 }
157 }
158 }
159
160 assert(testData3->getLength()==126);
161
162 cout << "\tVerify data point attributes." << endl;
163 dataView=testData3->getPointDataView();
164 assert(dataView.getRank()==3);
165 assert(dataView.noValues()==126);
166 assert(dataView.getShape()[0]==2);
167 assert(dataView.getShape()[1]==3);
168 assert(dataView.getShape()[2]==21);
169
170 cout << "\tTest slicing (part object)." << endl;
171
172 DataArrayView::RegionType region2;
173 region2.push_back(DataArrayView::RegionType::value_type(0,2));
174 region2.push_back(DataArrayView::RegionType::value_type(0,2));
175 region2.push_back(DataArrayView::RegionType::value_type(0,2));
176
177 DataAbstract* testData4=testData3->getSlice(region2);
178
179 for (int k=0;k<2;k++) {
180 for (int j=0;j<2;j++) {
181 for (int i=0;i<2;i++) {
182 assert(testData4->getPointDataView()(i,j,k)==pointData());
183 }
184 }
185 }
186
187 assert(testData4->getLength()==8);
188
189 cout << "\tVerify data point attributes." << endl;
190 dataView=testData4->getPointDataView();
191 assert(dataView.getRank()==3);
192 assert(dataView.noValues()==8);
193 assert(dataView.getShape()[0]==2);
194 assert(dataView.getShape()[1]==2);
195 assert(dataView.getShape()[2]==2);
196
197 cout << "\tTest slicing (part object)." << endl;
198
199 DataArrayView::RegionType region3;
200 region3.push_back(DataArrayView::RegionType::value_type(1,2));
201 region3.push_back(DataArrayView::RegionType::value_type(1,3));
202 region3.push_back(DataArrayView::RegionType::value_type(5,9));
203
204 DataAbstract* testData5=testData3->getSlice(region3);
205
206 for (int k=0;k<4;k++) {
207 for (int j=0;j<2;j++) {
208 for (int i=0;i<1;i++) {
209 assert(testData5->getPointDataView()(i,j,k)==pointData());
210 }
211 }
212 }
213
214 assert(testData5->getLength()==8);
215
216 cout << "\tVerify data point attributes." << endl;
217 dataView=testData5->getPointDataView();
218 assert(dataView.getRank()==3);
219 assert(dataView.noValues()==8);
220 assert(dataView.getShape()[0]==1);
221 assert(dataView.getShape()[1]==2);
222 assert(dataView.getShape()[2]==4);
223
224 cout << "\tTest slice setting (1)." << endl;
225
226 DataArrayView::RegionType region4;
227 region4.push_back(DataArrayView::RegionType::value_type(0,1));
228 region4.push_back(DataArrayView::RegionType::value_type(0,2));
229 region4.push_back(DataArrayView::RegionType::value_type(0,4));
230
231 DataAbstract* testData6=testData3->getSlice(region3);
232
233 testData5->setSlice(testData6,region4);
234
235 for (int k=0;k<4;k++) {
236 for (int j=0;j<2;j++) {
237 for (int i=0;i<1;i++) {
238 assert(testData5->getPointDataView()(i,j,k)==pointData());
239 }
240 }
241 }
242
243 assert(testData5->getLength()==8);
244
245 cout << "\tVerify data point attributes." << endl;
246 dataView=testData5->getPointDataView();
247 assert(dataView.getRank()==3);
248 assert(dataView.noValues()==8);
249 assert(dataView.getShape()[0]==1);
250 assert(dataView.getShape()[1]==2);
251 assert(dataView.getShape()[2]==4);
252
253 delete testData3;
254 delete testData4;
255 delete testData5;
256 delete testData6;
257 }
258
259 TestSuite* DataConstantTestCase::suite ()
260 {
261 //
262 // create the suite of tests to perform.
263 TestSuite *testSuite = new TestSuite ("DataConstantTestCase");
264
265 testSuite->addTest (new TestCaller< DataConstantTestCase>("testAll",&DataConstantTestCase::testAll));
266 return testSuite;
267 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26