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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2005 - (show annotations)
Mon Nov 10 01:21:39 2008 UTC (11 years ago) by jfenwick
File size: 6491 byte(s)
Bringing all changes across from schroedinger.
(Note this does not mean development is done, just that it will happen
on the trunk for now).
If anyone notices any problems please contact me.


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(DataReady& data,int i, int j, int k)
45 {
46 return data.getVector()[getRelIndex(data.getShape(),i,j,k)];
47 }
48
49
50 DataReady_ptr
51 resolveAndDelete(DataAbstract* p)
52 {
53 DataReady_ptr p2=p->resolve();
54 if (p!=p2.get())
55 {
56 delete p;
57 }
58 return p2;
59 }
60
61 }
62
63
64 void DataConstantTestCase::testAll() {
65
66 cout << endl;
67
68 //
69 // Create a scalar pointData
70 DataTypes::ShapeType shape;
71 DataTypes::ValueType data(DataTypes::noValues(shape),0);
72 // DataArrayView pointData(data,shape);
73
74 //
75 // assign an arbitrary value
76 data[0]=1.0;
77
78 //
79 // Test construction
80 cout << "\tTesting default constructor." << endl;
81 DataConstant testData(FunctionSpace(),shape,data);
82
83 cout << "\tTest getLength." << endl;
84 assert(testData.getLength()==1);
85
86 shape.push_back(2);
87 shape.push_back(3);
88 shape.push_back(21);
89
90 cout << "\tTesting alternative constructor." << endl;
91 DataTypes::ValueType data1(DataTypes::noValues(shape),1.0);
92 // do not call the FunctionSpace constructor directly
93 // in the argument of DataConstant
94 // GCC chokes on it.
95 FunctionSpace tmp_fns;
96 DataConstant testData1(tmp_fns, 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(getRef(testData1,i,j,k)==1.0);
102 }
103 }
104 }
105
106 cout << "\tTest getLength." << endl;
107 assert(testData1.getLength()==126);
108
109 cout << "\tTesting copy constructor." << endl;
110 DataConstant testData2(testData1);
111
112 for (int k=0;k<shape[2];k++) {
113 for (int j=0;j<shape[1];j++) {
114 for (int i=0;i<shape[0];i++) {
115 assert(getRef(testData2,i,j,k)==data[0]);
116 }
117 }
118 }
119
120 cout << "\tTest getLength." << endl;
121 assert(testData2.getLength()==126);
122
123 cout << "\tVerify data point attributes." << endl;
124 assert(testData2.getRank()==3);
125 assert(testData2.getNoValues()==126);
126 assert(testData2.getShape()[0]==2);
127 assert(testData2.getShape()[1]==3);
128 assert(testData2.getShape()[2]==21);
129
130 cout << "\tTest slicing (whole object)." << endl;
131
132 DataTypes::RegionType region;
133 region.push_back(DataTypes::RegionType::value_type(0,shape[0]));
134 region.push_back(DataTypes::RegionType::value_type(0,shape[1]));
135 region.push_back(DataTypes::RegionType::value_type(0,shape[2]));
136
137 DataReady_ptr testData3=resolveAndDelete(testData2.getSlice(region));
138
139 for (int k=0;k<shape[2];k++) {
140 for (int j=0;j<shape[1];j++) {
141 for (int i=0;i<shape[0];i++) {
142 assert(getRef(*testData3,i,j,k)==data[0]);
143 }
144 }
145 }
146
147 assert(testData3->getLength()==126);
148
149 cout << "\tVerify data point attributes." << endl;
150 assert(testData3->getRank()==3);
151 assert(testData3->getNoValues()==126);
152 assert(testData3->getShape()[0]==2);
153 assert(testData3->getShape()[1]==3);
154 assert(testData3->getShape()[2]==21);
155
156 cout << "\tTest slicing (part object)." << endl;
157
158 DataTypes::RegionType region2;
159 region2.push_back(DataTypes::RegionType::value_type(0,2));
160 region2.push_back(DataTypes::RegionType::value_type(0,2));
161 region2.push_back(DataTypes::RegionType::value_type(0,2));
162
163 DataReady_ptr testData4=resolveAndDelete(testData3->getSlice(region2));
164
165 for (int k=0;k<2;k++) {
166 for (int j=0;j<2;j++) {
167 for (int i=0;i<2;i++) {
168 assert(getRef(*testData4,i,j,k)==data[0]);
169 }
170 }
171 }
172
173 assert(testData4->getLength()==8);
174
175 cout << "\tVerify data point attributes." << endl;
176 assert(testData4->getRank()==3);
177 assert(testData4->getNoValues()==8);
178 assert(testData4->getShape()[0]==2);
179 assert(testData4->getShape()[1]==2);
180 assert(testData4->getShape()[2]==2);
181
182 cout << "\tTest slicing (part object)." << endl;
183
184 DataTypes::RegionType region3;
185 region3.push_back(DataTypes::RegionType::value_type(1,2));
186 region3.push_back(DataTypes::RegionType::value_type(1,3));
187 region3.push_back(DataTypes::RegionType::value_type(5,9));
188
189 DataReady_ptr testData5=resolveAndDelete(testData3->getSlice(region3));
190
191 for (int k=0;k<4;k++) {
192 for (int j=0;j<2;j++) {
193 for (int i=0;i<1;i++) {
194 assert(getRef(*testData5,i,j,k)==data[0]);
195 }
196 }
197 }
198
199 assert(testData5->getLength()==8);
200
201 cout << "\tVerify data point attributes." << endl;
202 // dataView=testData5->getPointDataView();
203 assert(testData5->getRank()==3);
204 assert(testData5->getNoValues()==8);
205 assert(testData5->getShape()[0]==1);
206 assert(testData5->getShape()[1]==2);
207 assert(testData5->getShape()[2]==4);
208
209 cout << "\tTest slice setting (1)." << endl;
210
211 DataTypes::RegionType region4;
212 region4.push_back(DataTypes::RegionType::value_type(0,1));
213 region4.push_back(DataTypes::RegionType::value_type(0,2));
214 region4.push_back(DataTypes::RegionType::value_type(0,4));
215
216 DataAbstract* testData6=testData3->getSlice(region3);
217
218 testData5->setSlice(testData6,region4);
219
220 for (int k=0;k<4;k++) {
221 for (int j=0;j<2;j++) {
222 for (int i=0;i<1;i++) {
223 assert(getRef(*testData5,i,j,k)==data[0]);
224 }
225 }
226 }
227
228 assert(testData5->getLength()==8);
229
230 cout << "\tVerify data point attributes." << endl;
231 // dataView=testData5->getPointDataView();
232 assert(testData5->getRank()==3);
233 assert(testData5->getNoValues()==8);
234 assert(testData5->getShape()[0]==1);
235 assert(testData5->getShape()[1]==2);
236 assert(testData5->getShape()[2]==4);
237
238 // delete testData3;
239 // delete testData4;
240 // delete testData5;
241 delete testData6;
242 }
243
244 TestSuite* DataConstantTestCase::suite ()
245 {
246 //
247 // create the suite of tests to perform.
248 TestSuite *testSuite = new TestSuite ("DataConstantTestCase");
249
250 testSuite->addTest (new TestCaller< DataConstantTestCase>("testAll",&DataConstantTestCase::testAll));
251 return testSuite;
252 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26