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

Annotation of /branches/arrayview_from_1695_trunk/escript/test/DataExpandedTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1698 - (hide annotations)
Tue Aug 12 01:13:16 2008 UTC (12 years, 8 months ago) by jfenwick
File size: 16247 byte(s)
Branch commit DO NOT PANIC.

Moved shapeToString and noValues from DataArrayView to 
DataTypes{.h,.cpp}


1 ksteube 1312
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 robwdcock 670 #include "escript/FunctionSpace.h"
17     #include "escript/DataExpanded.h"
18 robwdcock 638 #include "esysUtils/EsysException.h"
19 jgs 82 #include "DataExpandedTestCase.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 DataExpandedTestCase::setUp() {
29     //
30     // This is called before each test is run
31    
32     }
33    
34     void DataExpandedTestCase::tearDown() {
35     //
36     // This is called after each test has been run
37    
38     }
39    
40 jgs 102 void DataExpandedTestCase::testAll() {
41    
42     cout << endl;
43    
44     //
45     // Create a rank 1 pointData
46 jfenwick 1697 DataTypes::ShapeType shape;
47 jgs 102 shape.push_back(3);
48 jfenwick 1698 DataTypes::ValueType data(DataTypes::noValues(shape),0);
49 jgs 102 DataArrayView pointData(data,shape);
50    
51     //
52     // Assign an arbitrary value
53     pointData(0)=0.0;
54     pointData(1)=1.0;
55     pointData(2)=2.0;
56    
57     //
58     // Test constructor
59     cout << "\tTest DataExpanded constructor." << endl;
60     DataExpanded testData(pointData,FunctionSpace());
61    
62     cout << "\tTest getLength." << endl;
63     assert(testData.getLength()==pointData.noValues());
64    
65     cout << "\tTest getPointDataView." << endl;
66     for (int i=0;i<testData.getPointDataView().getShape()[0];i++) {
67     assert(testData.getPointDataView()(i)==pointData(i));
68     }
69    
70     cout << "\tVerify data point attributes." << endl;
71     DataArrayView dataView=testData.getPointDataView();
72     assert(dataView.getRank()==shape.size());
73     assert(dataView.noValues()==shape[0]*1);
74     assert(dataView.getShape()[0]==shape[0]);
75 jgs 117 assert(testData.getNumDPPSample()==1);
76     assert(testData.getNumSamples()==1);
77     assert(testData.validSamplePointNo(testData.getNumDPPSample()-1));
78     assert(testData.validSampleNo(testData.getNumSamples()-1));
79 jgs 102
80     //
81 jgs 119 // Test alternative constructor
82     cout << "\tTest DataExpanded alternative constructor." << endl;
83     data[0]=0.0;
84     data[1]=1.0;
85     data[2]=2.0;
86 phornby 152 FunctionSpace tmp_fns;
87     DataExpanded testData1(tmp_fns,shape,data);
88 jgs 119
89     cout << "\tTest getLength." << endl;
90     assert(testData1.getLength()==pointData.noValues());
91    
92     cout << "\tTest getPointDataView." << endl;
93     for (int i=0;i<testData1.getPointDataView().getShape()[0];i++) {
94     assert(testData1.getPointDataView()(i)==pointData(i));
95     }
96    
97     cout << "\tVerify data point attributes." << endl;
98     dataView=testData1.getPointDataView();
99     assert(dataView.getRank()==shape.size());
100     assert(dataView.noValues()==shape[0]*1);
101     assert(dataView.getShape()[0]==shape[0]);
102     assert(testData.getNumDPPSample()==1);
103     assert(testData.getNumSamples()==1);
104     assert(testData.validSamplePointNo(testData.getNumDPPSample()-1));
105     assert(testData.validSampleNo(testData.getNumSamples()-1));
106    
107     //
108 jgs 102 // Test copy constructor
109     cout << "\tTest DataExpanded copy constructor." << endl;
110     DataExpanded testData2(testData);
111    
112     cout << "\tTest getLength." << endl;
113     assert(testData2.getLength()==pointData.noValues());
114    
115     cout << "\tTest getPointDataView." << endl;
116     for (int i=0;i<testData2.getPointDataView().getShape()[0];i++) {
117     assert(testData2.getPointDataView()(i)==pointData(i));
118     }
119    
120     cout << "\tVerify data point attributes." << endl;
121     dataView=testData2.getPointDataView();
122     assert(dataView.getRank()==shape.size());
123     assert(dataView.noValues()==shape[0]*1);
124     assert(dataView.getShape()[0]==shape[0]);
125 jgs 117 assert(testData2.getNumDPPSample()==1);
126     assert(testData2.getNumSamples()==1);
127     assert(testData2.validSamplePointNo(testData2.getNumDPPSample()-1));
128     assert(testData2.validSampleNo(testData2.getNumSamples()-1));
129 jgs 102
130     }
131    
132 jgs 82
133 jgs 102 void DataExpandedTestCase::testSlicing() {
134 jgs 82
135     cout << endl;
136    
137     //
138 jgs 102 // Create a rank 1 pointData
139 jfenwick 1697 DataTypes::ShapeType shape;
140 jgs 82 shape.push_back(3);
141 jfenwick 1698 DataTypes::ValueType data(DataTypes::noValues(shape),0);
142 jgs 82 DataArrayView pointData(data,shape);
143    
144     //
145 jgs 102 // Assign an arbitrary value
146 jgs 82 pointData(0)=0.0;
147     pointData(1)=1.0;
148     pointData(2)=2.0;
149    
150 jgs 102 //
151     // Create object to test
152     cout << "\tCreate rank 1 DataExpanded object." << endl;
153     DataExpanded testData(pointData,FunctionSpace());
154 jgs 82
155 jgs 102 cout << "\tTest slicing (whole object)." << endl;
156 jfenwick 1697 DataTypes::RegionType region;
157     region.push_back(DataTypes::RegionType::value_type(0,shape[0]));
158 jgs 149
159 jgs 102 DataAbstract* testData2=testData.getSlice(region);
160    
161 jgs 82 //
162 jgs 102 // Verify data values
163     cout << "\tVerify data point values." << endl;
164     for (int i=0;i<testData2->getPointDataView().getShape()[0];i++) {
165     assert(testData2->getPointDataView()(i)==pointData(region[0].first+i));
166     }
167    
168     cout << "\tVerify data point attributes." << endl;
169     DataArrayView dataView=testData2->getPointDataView();
170     assert(dataView.getRank()==shape.size());
171     assert(dataView.noValues()==shape[0]*1);
172     assert(dataView.getShape()[0]==shape[0]);
173    
174 jgs 149 delete testData2;
175 jgs 102 }
176    
177     void DataExpandedTestCase::testSlicing2() {
178    
179     cout << endl;
180    
181     //
182     // Create a rank 2 pointData
183 jfenwick 1697 DataTypes::ShapeType shape;
184 jgs 102 shape.push_back(3);
185     shape.push_back(3);
186 jfenwick 1698 DataTypes::ValueType data(DataTypes::noValues(shape),0);
187 jgs 102 DataArrayView pointData(data,shape);
188    
189     //
190     // Assign an arbitrary value
191     pointData(0,0)=0.0;
192     pointData(1,0)=1.0;
193     pointData(2,0)=2.0;
194     pointData(0,1)=3.0;
195     pointData(1,1)=4.0;
196     pointData(2,1)=5.0;
197     pointData(0,2)=6.0;
198     pointData(1,2)=7.0;
199     pointData(2,2)=8.0;
200    
201     //
202     // Create object to test
203     cout << "\tCreate rank 2 DataExpanded object." << endl;
204 jgs 82 DataExpanded testData(pointData,FunctionSpace());
205    
206 jgs 102 cout << "\tTest slicing (part object)." << endl;
207 jfenwick 1697 DataTypes::RegionType region;
208     region.push_back(DataTypes::RegionType::value_type(0,2));
209     region.push_back(DataTypes::RegionType::value_type(0,2));
210 jgs 102 DataAbstract* testData2=testData.getSlice(region);
211 jgs 82
212 jgs 102 //
213     // Verify data values
214     cout << "\tVerify data point values." << endl;
215     for (int j=0;j<testData2->getPointDataView().getShape()[1];j++) {
216     for (int i=0;i<testData2->getPointDataView().getShape()[0];i++) {
217     assert(testData2->getPointDataView()(i,j)==pointData(region[0].first+i,region[1].first+j));
218     }
219     }
220 jgs 82
221 jgs 102 cout << "\tVerify data point attributes." << endl;
222     DataArrayView dataView=testData2->getPointDataView();
223     assert(dataView.getRank()==region.size());
224     assert(dataView.noValues()==(region[0].second-region[0].first)*(region[1].second-region[1].first));
225     assert(dataView.getShape()[0]==(region[0].second-region[0].first));
226     assert(dataView.getShape()[1]==(region[1].second-region[1].first));
227 jgs 82
228 jgs 102 cout << "\tTest slicing (part object)." << endl;
229 jfenwick 1697 DataTypes::RegionType region2;
230     region2.push_back(DataTypes::RegionType::value_type(1,3));
231     region2.push_back(DataTypes::RegionType::value_type(1,3));
232 jgs 102 DataAbstract* testData3=testData.getSlice(region2);
233 jgs 82
234 jgs 102 //
235     // Verify data values
236     cout << "\tVerify data point values." << endl;
237     for (int j=0;j<testData3->getPointDataView().getShape()[1];j++) {
238     for (int i=0;i<testData3->getPointDataView().getShape()[0];i++) {
239     assert(testData3->getPointDataView()(i,j)==pointData(region2[0].first+i,region2[1].first+j));
240     }
241     }
242    
243     cout << "\tVerify data point attributes." << endl;
244     dataView=testData3->getPointDataView();
245     assert(dataView.getRank()==region2.size());
246     assert(dataView.noValues()==(region2[0].second-region2[0].first)*(region2[1].second-region2[1].first));
247     assert(dataView.getShape()[0]==(region2[0].second-region2[0].first));
248     assert(dataView.getShape()[1]==(region2[1].second-region2[1].first));
249    
250 jgs 149 delete testData2;
251     delete testData3;
252    
253 jgs 82 }
254    
255 jgs 102 void DataExpandedTestCase::testSlicing3() {
256    
257     cout << endl;
258    
259     //
260     // Create a rank 3 pointData
261 jfenwick 1697 DataTypes::ShapeType shape;
262 jgs 102 shape.push_back(3);
263     shape.push_back(3);
264     shape.push_back(3);
265 jfenwick 1698 DataTypes::ValueType data(DataTypes::noValues(shape),0);
266 jgs 102 DataArrayView pointData(data,shape);
267    
268     //
269     // Assign an arbitrary value
270     pointData(0,0,0)=0.0;
271     pointData(1,0,0)=1.0;
272     pointData(2,0,0)=2.0;
273     pointData(0,1,0)=3.0;
274     pointData(1,1,0)=4.0;
275     pointData(2,1,0)=5.0;
276     pointData(0,2,0)=6.0;
277     pointData(1,2,0)=7.0;
278     pointData(2,2,0)=8.0;
279    
280     pointData(0,0,1)=9.0;
281     pointData(1,0,1)=10.0;
282     pointData(2,0,1)=11.0;
283     pointData(0,1,1)=12.0;
284     pointData(1,1,1)=13.0;
285     pointData(2,1,1)=14.0;
286     pointData(0,2,1)=15.0;
287     pointData(1,2,1)=16.0;
288     pointData(2,2,1)=17.0;
289    
290     pointData(0,0,2)=18.0;
291     pointData(1,0,2)=19.0;
292     pointData(2,0,2)=20.0;
293     pointData(0,1,2)=21.0;
294     pointData(1,1,2)=22.0;
295     pointData(2,1,2)=23.0;
296     pointData(0,2,2)=24.0;
297     pointData(1,2,2)=25.0;
298     pointData(2,2,2)=26.0;
299    
300     //
301     // Create object to test
302     cout << "\tCreate rank 3 DataExpanded object." << endl;
303     DataExpanded testData(pointData,FunctionSpace());
304    
305     cout << "\tTest slicing (part object)." << endl;
306 jfenwick 1697 DataTypes::RegionType region;
307     region.push_back(DataTypes::RegionType::value_type(0,2));
308     region.push_back(DataTypes::RegionType::value_type(0,2));
309     region.push_back(DataTypes::RegionType::value_type(0,2));
310 jgs 102 DataAbstract* testData2=testData.getSlice(region);
311    
312     //
313     // Verify data values
314     cout << "\tVerify data point values." << endl;
315     for (int k=0;k<testData2->getPointDataView().getShape()[2];k++) {
316     for (int j=0;j<testData2->getPointDataView().getShape()[1];j++) {
317     for (int i=0;i<testData2->getPointDataView().getShape()[0];i++) {
318     assert(testData2->getPointDataView()(i,j,k)==pointData(region[0].first+i,
319     region[1].first+j,
320     region[2].first+k));
321     }
322     }
323     }
324    
325     cout << "\tVerify data point attributes." << endl;
326     DataArrayView dataView=testData2->getPointDataView();
327     assert(dataView.getRank()==region.size());
328     assert(dataView.noValues()==(region[0].second-region[0].first)
329     *(region[1].second-region[1].first)
330     *(region[2].second-region[2].first));
331     assert(dataView.getShape()[0]==(region[0].second-region[0].first));
332     assert(dataView.getShape()[1]==(region[1].second-region[1].first));
333     assert(dataView.getShape()[2]==(region[2].second-region[2].first));
334    
335     cout << "\tTest slicing (part object)." << endl;
336 jfenwick 1697 DataTypes::RegionType region2;
337     region2.push_back(DataTypes::RegionType::value_type(1,3));
338     region2.push_back(DataTypes::RegionType::value_type(1,3));
339     region2.push_back(DataTypes::RegionType::value_type(1,3));
340 jgs 102 DataAbstract* testData3=testData.getSlice(region2);
341    
342     //
343     // Verify data values
344     cout << "\tVerify data point values." << endl;
345     for (int k=0;k<testData3->getPointDataView().getShape()[2];k++) {
346     for (int j=0;j<testData3->getPointDataView().getShape()[1];j++) {
347     for (int i=0;i<testData3->getPointDataView().getShape()[0];i++) {
348     assert(testData3->getPointDataView()(i,j,k)==pointData(region2[0].first+i,
349     region2[1].first+j,
350     region2[2].first+k));
351     }
352     }
353     }
354    
355     cout << "\tVerify data point attributes." << endl;
356     dataView=testData2->getPointDataView();
357     assert(dataView.getRank()==region.size());
358     assert(dataView.noValues()==(region[0].second-region[0].first)
359     *(region[1].second-region[1].first)
360     *(region[2].second-region[2].first));
361     assert(dataView.getShape()[0]==(region[0].second-region[0].first));
362     assert(dataView.getShape()[1]==(region[1].second-region[1].first));
363     assert(dataView.getShape()[2]==(region[2].second-region[2].first));
364    
365 jgs 149 delete testData2;
366     delete testData3;
367    
368 jgs 102 }
369    
370    
371     void DataExpandedTestCase::testSliceSetting() {
372    
373     cout << endl;
374    
375     //
376     // Create a rank 2 pointData
377 jfenwick 1697 DataTypes::ShapeType shape;
378 jgs 102 shape.push_back(2);
379     shape.push_back(2);
380 jfenwick 1698 DataTypes::ValueType data(DataTypes::noValues(shape),0);
381 jgs 102 DataArrayView pointData(data,shape);
382    
383     //
384     // Assign an arbitrary value
385     pointData(0,0)=0.0;
386     pointData(0,1)=1.0;
387     pointData(1,0)=2.0;
388     pointData(1,1)=3.0;
389    
390     //
391     // Create object to test
392     cout << "\tCreate rank 2 DataExpanded object." << endl;
393     DataExpanded testData(pointData,FunctionSpace());
394    
395     //
396     // Create another rank 2 pointData
397 jfenwick 1697 DataTypes::ShapeType shape2;
398 jgs 102 shape2.push_back(3);
399     shape2.push_back(3);
400 jfenwick 1698 DataTypes::ValueType data2(DataTypes::noValues(shape2),0);
401 jgs 102 DataArrayView pointData2(data2,shape2);
402    
403     //
404     // Assign an arbitrary value
405     pointData2(0,0)=0.1;
406     pointData2(0,1)=1.1;
407     pointData2(0,2)=2.1;
408     pointData2(1,0)=3.1;
409     pointData2(1,1)=4.1;
410     pointData2(1,2)=5.1;
411     pointData2(2,0)=6.1;
412     pointData2(2,1)=7.1;
413     pointData2(2,2)=8.1;
414    
415     //
416     // Create object to test
417     cout << "\tCreate second rank 2 DataExpanded object." << endl;
418     DataExpanded testData2(pointData2,FunctionSpace());
419    
420     cout << "\tTest slice setting (1)." << endl;
421    
422 jfenwick 1697 DataTypes::RegionType region;
423     region.push_back(DataTypes::RegionType::value_type(0,2));
424     region.push_back(DataTypes::RegionType::value_type(0,2));
425 jgs 102
426 jfenwick 1697 DataTypes::RegionType region2;
427     region2.push_back(DataTypes::RegionType::value_type(1,3));
428     region2.push_back(DataTypes::RegionType::value_type(1,3));
429 jgs 102
430     DataAbstract* testData3=testData.getSlice(region);
431    
432     testData2.setSlice(testData3,region2);
433    
434     //
435     // Verify data values
436     cout << "\tVerify data point values." << endl;
437     for (int j=region2[1].first;j<region2[1].second;j++) {
438     for (int i=region2[0].first;i<region2[0].second;i++) {
439     assert(testData2.getPointDataView()(i,j)==pointData(i-(region[0].second-1),j-(region[1].second-1)));
440     }
441     }
442    
443 jgs 149 delete testData3;
444    
445 jgs 102 }
446    
447     void DataExpandedTestCase::testSliceSetting2() {
448    
449     cout << endl;
450    
451     //
452     // Create a rank 0 pointData
453 jfenwick 1697 DataTypes::ShapeType shape;
454 jfenwick 1698 DataTypes::ValueType data(DataTypes::noValues(shape),0);
455 jgs 102 DataArrayView pointData(data,shape);
456    
457     //
458     // Assign an arbitrary value
459     pointData()=0.0;
460    
461     //
462     // Create object to test
463     cout << "\tCreate rank 0 DataExpanded object." << endl;
464     DataExpanded testData(pointData,FunctionSpace());
465    
466     //
467     // Create a rank 2 pointData
468 jfenwick 1697 DataTypes::ShapeType shape2;
469 jgs 102 shape2.push_back(3);
470     shape2.push_back(3);
471 jfenwick 1698 DataTypes::ValueType data2(DataTypes::noValues(shape2),0);
472 jgs 102 DataArrayView pointData2(data2,shape2);
473    
474     //
475     // Assign an arbitrary value
476     pointData2(0,0)=0.1;
477     pointData2(0,1)=1.1;
478     pointData2(0,2)=2.1;
479     pointData2(1,0)=3.1;
480     pointData2(1,1)=4.1;
481     pointData2(1,2)=5.1;
482     pointData2(2,0)=6.1;
483     pointData2(2,1)=7.1;
484     pointData2(2,2)=8.1;
485    
486     //
487     // Create object to test
488     cout << "\tCreate rank 2 DataExpanded object." << endl;
489     DataExpanded testData2(pointData2,FunctionSpace());
490    
491     cout << "\tTest slice setting (1)." << endl;
492    
493 jfenwick 1697 DataTypes::RegionType region;
494 jgs 102
495 jfenwick 1697 DataTypes::RegionType region2;
496     region2.push_back(DataTypes::RegionType::value_type(1,1));
497     region2.push_back(DataTypes::RegionType::value_type(1,1));
498 jgs 102
499     DataAbstract* testData3=testData.getSlice(region);
500    
501     testData2.setSlice(testData3,region2);
502    
503     //
504     // Verify data values
505     cout << "\tVerify data point values." << endl;
506     for (int j=region2[1].first;j<region2[1].second;j++) {
507     for (int i=region2[0].first;i<region2[0].second;i++) {
508     assert(testData2.getPointDataView()(i,j)==pointData());
509     }
510     }
511    
512 jgs 149 delete testData3;
513    
514 jgs 102 }
515    
516 jgs 110
517 jgs 82 TestSuite* DataExpandedTestCase::suite ()
518     {
519     //
520 jgs 102 // Create the suite of tests to perform.
521 jgs 82 TestSuite *testSuite = new TestSuite ("DataExpandedTestCase");
522     testSuite->addTest (new TestCaller< DataExpandedTestCase>("testAll",&DataExpandedTestCase::testAll));
523 jgs 102 testSuite->addTest (new TestCaller< DataExpandedTestCase>("testSlicing",&DataExpandedTestCase::testSlicing));
524     testSuite->addTest (new TestCaller< DataExpandedTestCase>("testSlicing2",&DataExpandedTestCase::testSlicing2));
525     testSuite->addTest (new TestCaller< DataExpandedTestCase>("testSlicing3",&DataExpandedTestCase::testSlicing3));
526     testSuite->addTest (new TestCaller< DataExpandedTestCase>("testSliceSetting",&DataExpandedTestCase::testSliceSetting));
527     testSuite->addTest (new TestCaller< DataExpandedTestCase>("testSliceSetting2",&DataExpandedTestCase::testSliceSetting2));
528 jgs 82 return testSuite;
529     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26