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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3597 - (show annotations)
Thu Sep 15 06:03:17 2011 UTC (7 years, 7 months ago) by caltinay
File size: 6663 byte(s)
Switching to external cppunit:
-removed tools/CppUnitTest
-updated scons script and files
-updated tests to changed API
-updated readme

Bumped scons options file version to 201. Additions:
-cppunit*
-boomeramg*
-vsl_random


1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 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 "DataConstantTestCase.h"
16
17 #include "escript/DataConstant.h"
18 #include "escript/FunctionSpace.h"
19 #include "esysUtils/EsysException.h"
20
21 #include <cppunit/TestCaller.h>
22 #include <iostream>
23
24 using namespace CppUnit;
25 using namespace escript;
26 using namespace std;
27 using namespace esysUtils;
28 using namespace escript::DataTypes;
29
30 namespace
31 {
32
33 ValueType::const_reference
34 getRefRO(DataReady& data,int i, int j, int k)
35 {
36 return data.getVectorRO()[getRelIndex(data.getShape(),i,j,k)];
37 }
38
39
40 DataReady_ptr
41 resolveAndDelete(DataAbstract* p)
42 {
43 DataReady_ptr p2=p->resolve();
44 if (p!=p2.get())
45 {
46 delete p;
47 }
48 return p2;
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 CPPUNIT_ASSERT(testData.getLength()==1);
75
76 shape.push_back(2);
77 shape.push_back(3);
78 shape.push_back(21);
79
80 cout << "\tTesting alternative constructor." << endl;
81 DataTypes::ValueType data1(DataTypes::noValues(shape),1.0);
82 // do not call the FunctionSpace constructor directly
83 // in the argument of DataConstant
84 // GCC chokes on it.
85 FunctionSpace tmp_fns;
86 DataConstant testData1(tmp_fns, shape, data1);
87
88 for (int k=0;k<shape[2];k++) {
89 for (int j=0;j<shape[1];j++) {
90 for (int i=0;i<shape[0];i++) {
91 CPPUNIT_ASSERT(getRefRO(testData1,i,j,k)==1.0);
92 }
93 }
94 }
95
96 cout << "\tTest getLength." << endl;
97 CPPUNIT_ASSERT(testData1.getLength()==126);
98
99 cout << "\tTesting copy constructor." << endl;
100 DataConstant testData2(testData1);
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 CPPUNIT_ASSERT(getRefRO(testData2,i,j,k)==data[0]);
106 }
107 }
108 }
109
110 cout << "\tTest getLength." << endl;
111 CPPUNIT_ASSERT(testData2.getLength()==126);
112
113 cout << "\tVerify data point attributes." << endl;
114 CPPUNIT_ASSERT(testData2.getRank()==3);
115 CPPUNIT_ASSERT(testData2.getNoValues()==126);
116 CPPUNIT_ASSERT(testData2.getShape()[0]==2);
117 CPPUNIT_ASSERT(testData2.getShape()[1]==3);
118 CPPUNIT_ASSERT(testData2.getShape()[2]==21);
119
120 cout << "\tTest slicing (whole object)." << endl;
121
122 DataTypes::RegionType region;
123 region.push_back(DataTypes::RegionType::value_type(0,shape[0]));
124 region.push_back(DataTypes::RegionType::value_type(0,shape[1]));
125 region.push_back(DataTypes::RegionType::value_type(0,shape[2]));
126
127 DataReady_ptr testData3=resolveAndDelete(testData2.getSlice(region));
128
129 for (int k=0;k<shape[2];k++) {
130 for (int j=0;j<shape[1];j++) {
131 for (int i=0;i<shape[0];i++) {
132 CPPUNIT_ASSERT(getRefRO(*testData3,i,j,k)==data[0]);
133 }
134 }
135 }
136
137 CPPUNIT_ASSERT(testData3->getLength()==126);
138
139 cout << "\tVerify data point attributes." << endl;
140 CPPUNIT_ASSERT(testData3->getRank()==3);
141 CPPUNIT_ASSERT(testData3->getNoValues()==126);
142 CPPUNIT_ASSERT(testData3->getShape()[0]==2);
143 CPPUNIT_ASSERT(testData3->getShape()[1]==3);
144 CPPUNIT_ASSERT(testData3->getShape()[2]==21);
145
146 cout << "\tTest slicing (part object)." << endl;
147
148 DataTypes::RegionType region2;
149 region2.push_back(DataTypes::RegionType::value_type(0,2));
150 region2.push_back(DataTypes::RegionType::value_type(0,2));
151 region2.push_back(DataTypes::RegionType::value_type(0,2));
152
153 DataReady_ptr testData4=resolveAndDelete(testData3->getSlice(region2));
154
155 for (int k=0;k<2;k++) {
156 for (int j=0;j<2;j++) {
157 for (int i=0;i<2;i++) {
158 CPPUNIT_ASSERT(getRefRO(*testData4,i,j,k)==data[0]);
159 }
160 }
161 }
162
163 CPPUNIT_ASSERT(testData4->getLength()==8);
164
165 cout << "\tVerify data point attributes." << endl;
166 CPPUNIT_ASSERT(testData4->getRank()==3);
167 CPPUNIT_ASSERT(testData4->getNoValues()==8);
168 CPPUNIT_ASSERT(testData4->getShape()[0]==2);
169 CPPUNIT_ASSERT(testData4->getShape()[1]==2);
170 CPPUNIT_ASSERT(testData4->getShape()[2]==2);
171
172 cout << "\tTest slicing (part object)." << endl;
173
174 DataTypes::RegionType region3;
175 region3.push_back(DataTypes::RegionType::value_type(1,2));
176 region3.push_back(DataTypes::RegionType::value_type(1,3));
177 region3.push_back(DataTypes::RegionType::value_type(5,9));
178
179 DataReady_ptr testData5=resolveAndDelete(testData3->getSlice(region3));
180
181 for (int k=0;k<4;k++) {
182 for (int j=0;j<2;j++) {
183 for (int i=0;i<1;i++) {
184 CPPUNIT_ASSERT(getRefRO(*testData5,i,j,k)==data[0]);
185 }
186 }
187 }
188
189 CPPUNIT_ASSERT(testData5->getLength()==8);
190
191 cout << "\tVerify data point attributes." << endl;
192 // dataView=testData5->getPointDataView();
193 CPPUNIT_ASSERT(testData5->getRank()==3);
194 CPPUNIT_ASSERT(testData5->getNoValues()==8);
195 CPPUNIT_ASSERT(testData5->getShape()[0]==1);
196 CPPUNIT_ASSERT(testData5->getShape()[1]==2);
197 CPPUNIT_ASSERT(testData5->getShape()[2]==4);
198
199 cout << "\tTest slice setting (1)." << endl;
200
201 DataTypes::RegionType region4;
202 region4.push_back(DataTypes::RegionType::value_type(0,1));
203 region4.push_back(DataTypes::RegionType::value_type(0,2));
204 region4.push_back(DataTypes::RegionType::value_type(0,4));
205
206 DataAbstract* testData6=testData3->getSlice(region3);
207
208 testData5->setSlice(testData6,region4);
209
210 for (int k=0;k<4;k++) {
211 for (int j=0;j<2;j++) {
212 for (int i=0;i<1;i++) {
213 CPPUNIT_ASSERT(getRefRO(*testData5,i,j,k)==data[0]);
214 }
215 }
216 }
217
218 CPPUNIT_ASSERT(testData5->getLength()==8);
219
220 cout << "\tVerify data point attributes." << endl;
221 // dataView=testData5->getPointDataView();
222 CPPUNIT_ASSERT(testData5->getRank()==3);
223 CPPUNIT_ASSERT(testData5->getNoValues()==8);
224 CPPUNIT_ASSERT(testData5->getShape()[0]==1);
225 CPPUNIT_ASSERT(testData5->getShape()[1]==2);
226 CPPUNIT_ASSERT(testData5->getShape()[2]==4);
227
228 // delete testData3;
229 // delete testData4;
230 // delete testData5;
231 delete testData6;
232 }
233
234 TestSuite* DataConstantTestCase::suite()
235 {
236 TestSuite *testSuite = new TestSuite("DataConstantTestCase");
237
238 testSuite->addTest(new TestCaller<DataConstantTestCase>(
239 "testAll",&DataConstantTestCase::testAll));
240 return testSuite;
241 }
242

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26