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

Diff of /trunk/escript/test/DataArrayTestCase.cpp

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

revision 107 by jgs, Fri Dec 17 07:43:12 2004 UTC revision 108 by jgs, Thu Jan 27 06:21:59 2005 UTC
# Line 1  Line 1 
1  /*  /*
2   *****************************************************************************   *****************************************************************************
3   *                                                                           *   *                                                                           *
4   *       COPYRIGHT  ACcESS  -  All Rights Reserved                           *   *       COPYRIGHT  ACcESS  -  All Rights Reserved                           *
# Line 11  Line 11 
11   *                                                                           *   *                                                                           *
12   *****************************************************************************   *****************************************************************************
13  */  */
14    
15  #include "escript/Data/DataArrayView.h"  #include "escript/Data/DataArrayView.h"
16  #include "escript/Data/DataArray.h"  #include "escript/Data/DataArray.h"
 #include "DataArrayTestCase.h"  
17  #include "esysUtils/EsysException.h"  #include "esysUtils/EsysException.h"
18    
19    #include "DataArrayTestCase.h"
20    
21  #include <iostream>  #include <iostream>
22  #include <vector>  #include <vector>
23    
# Line 47  void DataArrayTestCase::testAll() { Line 49  void DataArrayTestCase::testAll() {
49    
50    {    {
51      cout << endl;      cout << endl;
52      cout << "\tTest default DataArray constructor." << endl;      cout << "\tTest default DataArray constructor - default value." << endl;
53    
54      cout << "\tConstruct Default DataArray." << endl;      cout << "\tConstruct Default DataArray." << endl;
55        DataArrayView::ShapeType newShape;
56      DataArray newArray;      DataArray newArray;
57      DataArrayView newView = newArray.getView();      DataArrayView newView = newArray.getView();
     DataArrayView::ShapeType newShape = newView.getShape();  
58    
59      cout << "\tCheck DataArray shape." << endl;      cout << "\tCheck DataArray view shape." << endl;
60      assert(newView.getShape()==newShape);      assert(newView.getShape()==newShape);
61      assert(newView.getRank()==0);      assert(newView.getRank()==0);
62      assert(newView.noValues()==1);      assert(newView.noValues()==1);
63    
64      cout << "\tCheck DataArray data values." << endl;      cout << "\tCheck DataArray data vector values." << endl;
65      DataArrayView::ValueType arrayData = newArray.getData();      DataArrayView::ValueType arrayData = newArray.getData();
66      DataArrayView::ValueType viewData = newView.getData();      DataArrayView::ValueType viewData = newView.getData();
67      assert(viewData==arrayData);      assert(viewData==arrayData);
68      assert(arrayData[0]==0.0);      int noValues = newView.noValues();
69        for (int i=0; i<noValues; i++) {
70          assert(arrayData[i]==0.0);
71        }
72      assert(newView()==0.0);      assert(newView()==0.0);
73    }    }
74    
75    {    {
76      cout << endl;      cout << endl;
77      cout << "\tTest DataArray shape constructor, shape()." << endl;      cout << "\tTest default DataArray constructor - value 5.0." << endl;
78    
79        cout << "\tConstruct Default DataArray." << endl;
80        DataArrayView::ShapeType newShape;
81        DataArray newArray(5.0);
82        DataArrayView newView = newArray.getView();
83    
84        cout << "\tCheck DataArray view shape." << endl;
85        assert(newView.getShape()==newShape);
86        assert(newView.getRank()==0);
87        assert(newView.noValues()==1);
88    
89        cout << "\tCheck DataArray data vector values." << endl;
90        DataArrayView::ValueType arrayData = newArray.getData();
91        DataArrayView::ValueType viewData = newView.getData();
92        assert(viewData==arrayData);
93        int noValues = newView.noValues();
94        for (int i=0; i<noValues; i++) {
95          assert(arrayData[i]==5.0);
96        }
97        assert(newView()==5.0);
98      }
99    
100      {
101        cout << endl;
102        cout << "\tTest DataArray shape constructor, shape() - default value." << endl;
103    
104      cout << "\tConstruct new DataArray, rank 0." << endl;      cout << "\tConstruct new DataArray with rank 0 view." << endl;
105      DataArrayView::ShapeType newShape;      DataArrayView::ShapeType newShape;
106      DataArray newArray(newShape);      DataArray newArray(newShape);
107      DataArrayView newView = newArray.getView();      DataArrayView newView = newArray.getView();
108    
109      cout << "\tCheck DataArray shape." << endl;      cout << "\tCheck DataArray view shape." << endl;
110      assert(newView.getShape()==newShape);      assert(newView.getShape()==newShape);
111      assert(newView.getRank()==0);      assert(newView.getRank()==0);
112      assert(newView.noValues()==1);      assert(newView.noValues()==1);
113    
114      cout << "\tCheck DataArray data values." << endl;      cout << "\tCheck DataArray data vector values." << endl;
115      DataArrayView::ValueType arrayData = newArray.getData();      DataArrayView::ValueType arrayData = newArray.getData();
116      DataArrayView::ValueType viewData = newView.getData();      DataArrayView::ValueType viewData = newView.getData();
117      assert(viewData==arrayData);      assert(viewData==arrayData);
118      assert(arrayData[0]==0.0);      int noValues = newView.noValues();
119        for (int i=0; i<noValues; i++) {
120          assert(arrayData[i]==0.0);
121        }
122      assert(newView()==0.0);      assert(newView()==0.0);
123    }    }
124    
125    {    {
126      cout << endl;      cout << endl;
127        cout << "\tTest DataArray shape constructor, shape() - value 5.0." << endl;
128    
129        cout << "\tConstruct new DataArray with rank 0 view." << endl;
130        DataArrayView::ShapeType newShape;
131        DataArray newArray(newShape, 5.0);
132        DataArrayView newView = newArray.getView();
133    
134        cout << "\tCheck DataArray view shape." << endl;
135        assert(newView.getShape()==newShape);
136        assert(newView.getRank()==0);
137        assert(newView.noValues()==1);
138    
139        cout << "\tCheck DataArray data vector values." << endl;
140        DataArrayView::ValueType arrayData = newArray.getData();
141        DataArrayView::ValueType viewData = newView.getData();
142        assert(viewData==arrayData);
143        int noValues = newView.noValues();
144        for (int i=0; i<noValues; i++) {
145          assert(arrayData[i]==5.0);
146        }
147        assert(newView()==5.0);
148      }
149    
150      {
151        cout << endl;
152      cout << "\tTest DataArray shape constructor, shape(5)." << endl;      cout << "\tTest DataArray shape constructor, shape(5)." << endl;
153    
154      cout << "\tConstruct new DataArray, rank 1." << endl;      cout << "\tConstruct new DataArray with rank 1 view." << endl;
155      DataArrayView::ShapeType newShape;      DataArrayView::ShapeType newShape;
156      newShape.push_back(5);      newShape.push_back(5);
157      DataArray newArray(newShape);      DataArray newArray(newShape);
158      DataArrayView newView = newArray.getView();      DataArrayView newView = newArray.getView();
159    
160      cout << "\tCheck DataArray shape." << endl;      cout << "\tCheck DataArray view shape." << endl;
161      assert(newView.getShape()==newShape);      assert(newView.getShape()==newShape);
162      assert(newView.getRank()==1);      assert(newView.getRank()==1);
163      assert(newView.noValues()==5);      assert(newView.noValues()==5);
164    
165      cout << "\tCheck DataArray data values." << endl;      cout << "\tCheck DataArray data vector values." << endl;
166      DataArrayView::ValueType::size_type index;      DataArrayView::ValueType::size_type index;
167      DataArrayView::ValueType arrayData = newArray.getData();      DataArrayView::ValueType arrayData = newArray.getData();
168      DataArrayView::ValueType viewData = newView.getData();      DataArrayView::ValueType viewData = newView.getData();
169      assert(viewData==arrayData);      assert(viewData==arrayData);
170      for (int i=0;i<newShape[0];++i) {      for (int i=0; i<newShape[0]; i++) {
171        index=newView.index(i);        index=newView.index(i);
172        assert(arrayData[index]==0.0);        assert(arrayData[index]==0.0);
173        assert(arrayData[index]==newView(i));        assert(newView(i)==0.0);
174      }      }
175    }    }
176        
# Line 120  void DataArrayTestCase::testAll() { Line 178  void DataArrayTestCase::testAll() {
178      cout << endl;      cout << endl;
179      cout << "\tTest DataArray shape constructor, shape(2,3)." << endl;      cout << "\tTest DataArray shape constructor, shape(2,3)." << endl;
180    
181      cout << "\tConstruct new DataArray, rank 2." << endl;      cout << "\tConstruct new DataArray with rank 2 view." << endl;
182      DataArrayView::ShapeType newShape;      DataArrayView::ShapeType newShape;
183      newShape.push_back(2);      newShape.push_back(2);
184      newShape.push_back(3);      newShape.push_back(3);
185      DataArray newArray(newShape);      DataArray newArray(newShape);
186      DataArrayView newView = newArray.getView();      DataArrayView newView = newArray.getView();
187    
188      cout << "\tCheck DataArray shape." << endl;      cout << "\tCheck DataArray view shape." << endl;
189      assert(newView.getShape()==newShape);      assert(newView.getShape()==newShape);
190      assert(newView.getRank()==2);      assert(newView.getRank()==2);
191      assert(newView.noValues()==6);      assert(newView.noValues()==6);
192    
193        cout << "\tCheck DataArray data vector values." << endl;
194      DataArrayView::ValueType::size_type index;      DataArrayView::ValueType::size_type index;
     DataArrayView::ValueType viewData = newView.getData();  
195      DataArrayView::ValueType arrayData = newArray.getData();      DataArrayView::ValueType arrayData = newArray.getData();
196        DataArrayView::ValueType viewData = newView.getData();
     cout << "\tCheck DataArray data values." << endl;  
197      assert(viewData==arrayData);      assert(viewData==arrayData);
198      for (int i=0;i<newShape[0];++i) {      for (int i=0; i<newShape[0]; i++) {
199        for (int j=0;j<newShape[1];++j) {        for (int j=0; j<newShape[1]; j++) {
200          index=newView.index(i,j);          index=newView.index(i,j);
201          assert(arrayData[index]==0.0);          assert(arrayData[index]==0.0);
202          assert(arrayData[index]==newView(i,j));          assert(newView(i,j)==0.0);
203        }        }
204      }      }
205    }    }
# Line 151  void DataArrayTestCase::testAll() { Line 208  void DataArrayTestCase::testAll() {
208      cout << endl;      cout << endl;
209      cout << "\tTest DataArray shape constructor, shape(2,3,4)." << endl;      cout << "\tTest DataArray shape constructor, shape(2,3,4)." << endl;
210    
211      cout << "\tConstruct new DataArray, rank 3." << endl;      cout << "\tConstruct new DataArray with rank 3 view." << endl;
212      DataArrayView::ShapeType newShape;      DataArrayView::ShapeType newShape;
213      newShape.push_back(2);      newShape.push_back(2);
214      newShape.push_back(3);      newShape.push_back(3);
# Line 159  void DataArrayTestCase::testAll() { Line 216  void DataArrayTestCase::testAll() {
216      DataArray newArray(newShape);      DataArray newArray(newShape);
217      DataArrayView newView = newArray.getView();      DataArrayView newView = newArray.getView();
218    
219      cout << "\tCheck DataArray shape." << endl;      cout << "\tCheck DataArray view shape." << endl;
220      assert(newView.getShape()==newShape);      assert(newView.getShape()==newShape);
221      assert(newView.getRank()==3);      assert(newView.getRank()==3);
222      assert(newView.noValues()==24);      assert(newView.noValues()==24);
223    
224        cout << "\tCheck DataArray data vector values." << endl;
225      DataArrayView::ValueType::size_type index;      DataArrayView::ValueType::size_type index;
226      DataArrayView::ValueType viewData = newView.getData();      DataArrayView::ValueType viewData = newView.getData();
227      DataArrayView::ValueType arrayData = newArray.getData();      DataArrayView::ValueType arrayData = newArray.getData();
   
     cout << "\tCheck DataArray data values." << endl;  
228      assert(viewData==arrayData);      assert(viewData==arrayData);
229      for (int i=0;i<newShape[0];++i) {      for (int i=0; i<newShape[0]; i++) {
230        for (int j=0;j<newShape[1];++j) {        for (int j=0; j<newShape[1]; j++) {
231          for (int k=0;k<newShape[2];++k) {          for (int k=0; k<newShape[2]; k++) {
232            index=newView.index(i,j,k);            index=newView.index(i,j,k);
233            assert(arrayData[index]==0.0);            assert(arrayData[index]==0.0);
234            assert(arrayData[index]==newView(i,j,k));            assert(newView(i,j,k)==0.0);
235          }          }
236        }        }
237      }      }
# Line 185  void DataArrayTestCase::testAll() { Line 241  void DataArrayTestCase::testAll() {
241      cout << endl;      cout << endl;
242      cout << "\tTest DataArray shape constructor, shape(2,3,4,7)." << endl;      cout << "\tTest DataArray shape constructor, shape(2,3,4,7)." << endl;
243    
244      cout << "\tConstruct new DataArray, rank 4." << endl;      cout << "\tConstruct new DataArray with rank 4 view." << endl;
245      DataArrayView::ShapeType newShape;      DataArrayView::ShapeType newShape;
246      newShape.push_back(2);      newShape.push_back(2);
247      newShape.push_back(3);      newShape.push_back(3);
# Line 194  void DataArrayTestCase::testAll() { Line 250  void DataArrayTestCase::testAll() {
250      DataArray newArray(newShape);      DataArray newArray(newShape);
251      DataArrayView newView = newArray.getView();      DataArrayView newView = newArray.getView();
252    
253      cout << "\tCheck DataArray shape." << endl;      cout << "\tCheck DataArray view shape." << endl;
254      assert(newView.getShape()==newShape);      assert(newView.getShape()==newShape);
255      assert(newView.getRank()==4);      assert(newView.getRank()==4);
256      assert(newView.noValues()==168);      assert(newView.noValues()==168);
257    
258        cout << "\tCheck DataArray data vector values." << endl;
259      DataArrayView::ValueType::size_type index;      DataArrayView::ValueType::size_type index;
260      DataArrayView::ValueType viewData = newView.getData();      DataArrayView::ValueType viewData = newView.getData();
261      DataArrayView::ValueType arrayData = newArray.getData();      DataArrayView::ValueType arrayData = newArray.getData();
   
     cout << "\tCheck DataArray data values." << endl;  
262      assert(viewData==arrayData);      assert(viewData==arrayData);
263      for (int i=0;i<newShape[0];++i) {      for (int i=0; i<newShape[0]; i++) {
264        for (int j=0;j<newShape[1];++j) {        for (int j=0; j<newShape[1]; j++) {
265          for (int k=0;k<newShape[2];++k) {          for (int k=0; k<newShape[2]; k++) {
266            for (int l=0;l<newShape[3];++l) {            for (int l=0; l<newShape[3]; l++) {
267              index=newView.index(i,j,k,l);              index=newView.index(i,j,k,l);
268              assert(arrayData[index]==0.0);              assert(arrayData[index]==0.0);
269              assert(arrayData[index]==newView(i,j,k,l));              assert(newView(i,j,k,l)==0.0);
270            }            }
271          }          }
272        }        }
# Line 226  void DataArrayTestCase::testAll() { Line 281  void DataArrayTestCase::testAll() {
281      DataArray oldArray;      DataArray oldArray;
282    
283      cout << "\tCopy Default DataArray." << endl;      cout << "\tCopy Default DataArray." << endl;
284        DataArrayView::ShapeType newShape;
285      DataArray newArray(oldArray);      DataArray newArray(oldArray);
286      DataArrayView newView = newArray.getView();      DataArrayView newView = newArray.getView();
     DataArrayView::ShapeType newShape = newView.getShape();  
287    
288      cout << "\tCheck DataArray shape." << endl;      cout << "\tCheck DataArray view shape." << endl;
289      assert(newView.getShape()==newShape);      assert(newView.getShape()==newShape);
290      assert(newView.getRank()==0);      assert(newView.getRank()==0);
291      assert(newView.noValues()==1);      assert(newView.noValues()==1);
292    
293      cout << "\tCheck DataArray data values." << endl;      cout << "\tCheck DataArray data vector values." << endl;
294      DataArrayView::ValueType arrayData = newArray.getData();      DataArrayView::ValueType arrayData = newArray.getData();
295      DataArrayView::ValueType viewData = newView.getData();      DataArrayView::ValueType viewData = newView.getData();
296      assert(viewData==arrayData);      assert(viewData==arrayData);
# Line 247  void DataArrayTestCase::testAll() { Line 302  void DataArrayTestCase::testAll() {
302      cout << endl;      cout << endl;
303      cout << "\tTest DataArray copy constructor, shape(2,3)." << endl;      cout << "\tTest DataArray copy constructor, shape(2,3)." << endl;
304    
305      cout << "\tConstruct new DataArray, rank 2." << endl;      cout << "\tConstruct new DataArray with rank 2 view." << endl;
306      DataArrayView::ShapeType oldShape;      DataArrayView::ShapeType oldShape;
307      oldShape.push_back(2);      oldShape.push_back(2);
308      oldShape.push_back(3);      oldShape.push_back(3);
309      DataArray oldArray(oldShape);      DataArray oldArray(oldShape);
310    
311      cout << "\tCopy rank 2 DataArray." << endl;      cout << "\tCopy rank 2 DataArray." << endl;
312        DataArrayView::ShapeType newShape = oldShape;
313      DataArray newArray(oldArray);      DataArray newArray(oldArray);
314      DataArrayView newView = newArray.getView();      DataArrayView newView = newArray.getView();
     DataArrayView::ShapeType newShape = newView.getShape();  
315    
316      cout << "\tCheck DataArray shape." << endl;      cout << "\tCheck DataArray view shape." << endl;
317      assert(newShape==oldShape);      assert(newView.getShape()==newShape);
318      assert(newView.getRank()==2);      assert(newView.getRank()==2);
319      assert(newView.noValues()==6);      assert(newView.noValues()==6);
320    
321        cout << "\tCheck DataArray data vector values." << endl;
322      DataArrayView::ValueType::size_type index;      DataArrayView::ValueType::size_type index;
323      DataArrayView::ValueType viewData = newView.getData();      DataArrayView::ValueType viewData = newView.getData();
324      DataArrayView::ValueType arrayData = newArray.getData();      DataArrayView::ValueType arrayData = newArray.getData();
   
     cout << "\tCheck DataArray data values." << endl;  
325      assert(viewData==arrayData);      assert(viewData==arrayData);
326      for (int i=0;i<newShape[0];++i) {      for (int i=0; i<newShape[0]; i++) {
327        for (int j=0;j<newShape[1];++j) {        for (int j=0; j<newShape[1]; j++) {
328          index=newView.index(i,j);          index=newView.index(i,j);
329          assert(arrayData[index]==0.0);          assert(arrayData[index]==0.0);
330          assert(arrayData[index]==newView(i,j));          assert(newView(i,j)==0.0);
331          }
332        }
333      }
334    
335      {
336        cout << endl;
337        cout << "\tTest DataArray copy constructor, shape(2,3,4,7)." << endl;
338    
339        cout << "\tConstruct new DataArray with rank 4 view." << endl;
340        DataArrayView::ShapeType oldShape;
341        oldShape.push_back(2);
342        oldShape.push_back(3);
343        oldShape.push_back(4);
344        oldShape.push_back(7);
345        DataArray oldArray(oldShape);
346    
347        cout << "\tCopy rank 4 DataArray." << endl;
348        DataArrayView::ShapeType newShape = oldShape;
349        DataArray newArray(oldArray);
350        DataArrayView newView = newArray.getView();
351    
352        cout << "\tCheck DataArray view shape." << endl;
353        assert(newView.getShape()==newShape);
354        assert(newView.getRank()==4);
355        assert(newView.noValues()==168);
356    
357        cout << "\tCheck DataArray data vector values." << endl;
358        DataArrayView::ValueType::size_type index;
359        DataArrayView::ValueType viewData = newView.getData();
360        DataArrayView::ValueType arrayData = newArray.getData();
361        assert(viewData==arrayData);
362        for (int i=0; i<newShape[0]; i++) {
363          for (int j=0; j<newShape[1]; j++) {
364            for (int k=0; k<newShape[2]; k++) {
365              for (int l=0; l<newShape[3]; l++) {
366                index=newView.index(i,j,k,l);
367                assert(arrayData[index]==0.0);
368                assert(newView(i,j,k,l)==0.0);
369              }
370            }
371        }        }
372      }      }
373    }    }
# Line 289  void DataArrayTestCase::testAll() { Line 383  void DataArrayTestCase::testAll() {
383      DataArrayView oldView = oldArray.getView();      DataArrayView oldView = oldArray.getView();
384    
385      cout << "\tCopy Default DataArray from DataArrayView." << endl;      cout << "\tCopy Default DataArray from DataArrayView." << endl;
386        DataArrayView::ShapeType newShape;
387      DataArray newArray(oldView);      DataArray newArray(oldView);
388      DataArrayView newView = newArray.getView();      DataArrayView newView = newArray.getView();
     DataArrayView::ShapeType newShape = newView.getShape();  
389    
390      cout << "\tCheck DataArray shape." << endl;      cout << "\tCheck DataArray view shape." << endl;
391      assert(newView.getShape()==newShape);      assert(newView.getShape()==newShape);
392      assert(newView.getRank()==0);      assert(newView.getRank()==0);
393      assert(newView.noValues()==1);      assert(newView.noValues()==1);
394    
395      cout << "\tCheck DataArray data values." << endl;      cout << "\tCheck DataArray data vector values." << endl;
396      DataArrayView::ValueType arrayData = newArray.getData();      DataArrayView::ValueType arrayData = newArray.getData();
397      DataArrayView::ValueType viewData = newView.getData();      DataArrayView::ValueType viewData = newView.getData();
398      assert(viewData==arrayData);      assert(viewData==arrayData);
# Line 310  void DataArrayTestCase::testAll() { Line 404  void DataArrayTestCase::testAll() {
404      cout << endl;      cout << endl;
405      cout << "\tTest DataArray DataArrayView constructor, shape(2,3)." << endl;      cout << "\tTest DataArray DataArrayView constructor, shape(2,3)." << endl;
406    
407      cout << "\tConstruct new DataArray, rank 2." << endl;      cout << "\tConstruct new DataArray with rank 2 view." << endl;
408      DataArrayView::ShapeType oldShape;      DataArrayView::ShapeType oldShape;
409      oldShape.push_back(2);      oldShape.push_back(2);
410      oldShape.push_back(3);      oldShape.push_back(3);
411      DataArray oldArray(oldShape);      DataArray oldArray(oldShape);
412    
413      cout << "\tExtract rank2 DataArray DataArrayView." << endl;      cout << "\tExtract rank 2 DataArray DataArrayView." << endl;
414      DataArrayView oldView = oldArray.getView();      DataArrayView oldView = oldArray.getView();
415    
416      cout << "\tCopy rank 2 DataArray from DataArrayView." << endl;      cout << "\tCopy rank 2 DataArray from DataArrayView." << endl;
417        DataArrayView::ShapeType newShape = oldShape;
418      DataArray newArray(oldView);      DataArray newArray(oldView);
419      DataArrayView newView = newArray.getView();      DataArrayView newView = newArray.getView();
     DataArrayView::ShapeType newShape = newView.getShape();  
420    
421      cout << "\tCheck DataArray shape." << endl;      cout << "\tCheck DataArray view shape." << endl;
422      assert(newShape==oldShape);      assert(newView.getShape()==newShape);
423      assert(newView.getRank()==2);      assert(newView.getRank()==2);
424      assert(newView.noValues()==6);      assert(newView.noValues()==6);
425    
426        cout << "\tCheck DataArray data vector values." << endl;
427      DataArrayView::ValueType::size_type index;      DataArrayView::ValueType::size_type index;
428      DataArrayView::ValueType viewData = newView.getData();      DataArrayView::ValueType viewData = newView.getData();
429      DataArrayView::ValueType arrayData = newArray.getData();      DataArrayView::ValueType arrayData = newArray.getData();
   
     cout << "\tCheck DataArray data values." << endl;  
430      assert(viewData==arrayData);      assert(viewData==arrayData);
431      for (int i=0;i<newShape[0];++i) {      for (int i=0; i<newShape[0]; i++) {
432        for (int j=0;j<newShape[1];++j) {        for (int j=0; j<newShape[1]; j++) {
433          index=newView.index(i,j);          index=newView.index(i,j);
434          assert(arrayData[index]==0.0);          assert(arrayData[index]==0.0);
435          assert(arrayData[index]==newView(i,j));          assert(newView(i,j)==0.0);
436          }
437        }
438      }
439    
440      {
441        cout << endl;
442        cout << "\tTest DataArray DataArrayView constructor, shape(2,3,4,7)." << endl;
443    
444        cout << "\tConstruct new DataArray with rank 4 view." << endl;
445        DataArrayView::ShapeType oldShape;
446        oldShape.push_back(2);
447        oldShape.push_back(3);
448        oldShape.push_back(4);
449        oldShape.push_back(7);
450        DataArray oldArray(oldShape);
451    
452        cout << "\tExtract rank 4 DataArray DataArrayView." << endl;
453        DataArrayView oldView = oldArray.getView();
454    
455        cout << "\tCopy rank 4 DataArray from DataArrayView." << endl;
456        DataArrayView::ShapeType newShape = oldShape;
457        DataArray newArray(oldView);
458        DataArrayView newView = newArray.getView();
459    
460        cout << "\tCheck DataArray view shape." << endl;
461        assert(newView.getShape()==newShape);
462        assert(newView.getRank()==4);
463        assert(newView.noValues()==168);
464    
465        cout << "\tCheck DataArray data vector values." << endl;
466        DataArrayView::ValueType::size_type index;
467        DataArrayView::ValueType viewData = newView.getData();
468        DataArrayView::ValueType arrayData = newArray.getData();
469        assert(viewData==arrayData);
470        for (int i=0; i<newShape[0]; i++) {
471          for (int j=0; j<newShape[1]; j++) {
472            for (int k=0; k<newShape[2]; k++) {
473              for (int l=0; l<newShape[3]; l++) {
474                index=newView.index(i,j,k,l);
475                assert(arrayData[index]==0.0);
476                assert(newView(i,j,k,l)==0.0);
477              }
478            }
479        }        }
480      }      }
481    }    }
# Line 355  TestSuite* DataArrayTestCase::suite () Line 491  TestSuite* DataArrayTestCase::suite ()
491    testSuite->addTest (new TestCaller< DataArrayTestCase>("testAll",&DataArrayTestCase::testAll));    testSuite->addTest (new TestCaller< DataArrayTestCase>("testAll",&DataArrayTestCase::testAll));
492    return testSuite;    return testSuite;
493  }  }
   

Legend:
Removed from v.107  
changed lines
  Added in v.108

  ViewVC Help
Powered by ViewVC 1.1.26