/[escript]/trunk/esys2/escript/test/DataExpanded/DataExpandedTestCase.cpp
ViewVC logotype

Diff of /trunk/esys2/escript/test/DataExpanded/DataExpandedTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.82  
changed lines
  Added in v.97

  ViewVC Help
Powered by ViewVC 1.1.26