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

Annotation of /trunk/escript/test/DataTaggedTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 503 - (hide annotations)
Wed Feb 8 04:25:40 2006 UTC (13 years, 10 months ago) by jgs
Original Path: trunk/escript/test/DataTagged/DataTaggedTestCase.cpp
File size: 52759 byte(s)
add test for copy constructors

1 jgs 82 // $Id$
2     /*
3     *****************************************************************************
4     * *
5     * COPYRIGHT ACcESS - All Rights Reserved *
6     * *
7     * This software is the property of ACcESS. No part of this code *
8     * may be copied in any form or by any means without the expressed written *
9     * consent of ACcESS. Copying, use or modification of this software *
10     * by any unauthorised person is illegal unless that person has a software *
11     * license agreement with ACcESS. *
12     * *
13     *****************************************************************************
14     */
15 jgs 497
16     #include "EsysException.h"
17    
18 jgs 474 #include "DataTagged.h"
19 jgs 503 #include "DataConstant.h"
20 jgs 497
21     #include "DataTaggedTestCase.h"
22    
23 jgs 474 #include "BinaryOp.h"
24     #include "UnaryOp.h"
25     #include "FunctionSpaceFactory.h"
26     #include "DataFactory.h"
27 jgs 82
28     #include <iostream>
29     #include <functional>
30     #include <algorithm>
31    
32     using namespace CppUnitTest;
33     using namespace escript;
34     using namespace esysUtils;
35     using namespace std;
36    
37     void DataTaggedTestCase::setUp() {
38     //
39     // This is called before each test is run
40    
41     }
42    
43     void DataTaggedTestCase::tearDown() {
44     //
45     // This is called after each test has been run
46    
47     }
48    
49     void DataTaggedTestCase::testReshape() {
50    
51     cout << endl;
52    
53     {
54     cout << "\tTest reshape of default constructed DataTagged to rank 1." << endl;
55     DataTagged value;
56     value.getPointDataView()()=1.0;
57     DataArrayView::ShapeType shape;
58     shape.push_back(2);
59     value.reshapeDataPoint(shape);
60     for (int i=0;i<shape[0];++i) {
61     assert(value.getDefaultValue()(i)==1);
62     }
63     }
64     {
65     cout << "\tTest reshape of default constructed DataTagged to rank 2." << endl;
66     DataTagged value;
67     value.getPointDataView()()=0.0;
68     DataArray vOne(1.0);
69     DataArray vTwo(2.0);
70     value.addTaggedValue(1,vOne.getView());
71     value.addTaggedValue(2,vTwo.getView());
72     DataArrayView::ShapeType shape;
73     shape.push_back(2);
74     shape.push_back(5);
75     value.reshapeDataPoint(shape);
76     for (int j=0;j<shape[1];++j) {
77     for (int i=0;i<shape[0];++i) {
78     assert(value.getDefaultValue()(i,j)==0.0);
79     assert(value.getDataPointByTag(1)(i,j)==vOne.getView()());
80     assert(value.getDataPointByTag(2)(i,j)==vTwo.getView()());
81     }
82     }
83     }
84     }
85    
86     void DataTaggedTestCase::testOperations() {
87    
88     cout << endl;
89    
90     {
91     DataTagged left;
92     DataTagged right;
93 jgs 121
94     cout << "\tTest default DataTagged contains only a default value." << endl;
95 jgs 82 binaryOp(left,right,plus<double>());
96     assert(left.getPointDataView()()==0);
97     assert(right.getPointDataView()()==0);
98 jgs 121
99     cout << "\tTest binaryOp(plus)." << endl;
100 jgs 82 DataArray vOne(1.0);
101     DataArray vTwo(2.0);
102     right.addTaggedValue(1,vOne.getView());
103     right.addTaggedValue(2,vTwo.getView());
104     binaryOp(left,right,plus<double>());
105     assert(left.getPointDataView()()==0);
106     assert(left.getDataPointByTag(1)==vOne.getView());
107     assert(left.getDataPointByTag(2)==vTwo.getView());
108 jgs 121
109     cout << "\tTest binaryOp(multiplies)." << endl;
110 jgs 82 DataArray vZero(0.0);
111     right.setTaggedValue(1,vZero.getView());
112     right.setTaggedValue(2,vZero.getView());
113     binaryOp(left,right,multiplies<double>());
114     assert(left.getPointDataView()()==0);
115     assert(left.getDataPointByTag(1)==vZero.getView());
116     assert(left.getDataPointByTag(2)==vZero.getView());
117     }
118 jgs 501
119 jgs 82 {
120     DataArrayView::ShapeType viewShape;
121     viewShape.push_back(3);
122 jgs 121 DataArrayView::ValueType viewData(3);
123 jgs 82 DataTagged::TagListType keys;
124     DataTagged::ValueListType values;
125     for (int i=0;i<viewShape[0];++i) {
126 jgs 121 viewData[i]=i;
127 jgs 82 }
128     DataArrayView myView(viewData,viewShape);
129     cout << "\tCreate tagged data with no tag values just a default." << endl;
130     DataTagged left(keys,values,myView,FunctionSpace());
131     DataTagged right(keys,values,myView,FunctionSpace());
132     binaryOp(left,right,minus<double>());
133     for (int i=0;i<viewShape[0];++i) {
134     assert(left.getDefaultValue()(i)==0);
135     }
136     double mVal=10.0;
137     for (int i=0;i<viewShape[0];++i) {
138     viewData[i]=i*mVal;
139     }
140     cout << "\tTest binaryOp(minus) with the right hand side as a view." << endl;
141     binaryOp(left,myView,minus<double>());
142     for (int i=0;i<viewShape[0];++i) {
143     assert(left.getDefaultValue()(i)==-(i*mVal));
144     }
145     }
146 jgs 501
147 jgs 82 {
148     cout << "\tTest unaryOp(negate) on default DataTagged." << endl;
149     DataTagged data;
150     unaryOp(data,negate<double>());
151     assert(data.getDefaultValue()()==0);
152     DataArray vOne(1);
153     binaryOp(data,vOne.getView(),plus<double>());
154     assert(data.getDefaultValue()()==1);
155     unaryOp(data,negate<double>());
156     assert(data.getDefaultValue()()==-1);
157     }
158 jgs 501
159 jgs 82 {
160     cout << "\tTest unaryOp(negate) on DataTagged with 3 tags." << endl;
161     DataArrayView::ShapeType vShape;
162     vShape.push_back(3);
163     vShape.push_back(2);
164     vShape.push_back(1);
165     DataArray defData(vShape,0.0);
166     DataArrayView& defView=defData.getView();
167     DataArray tOneData(vShape,1.0);
168     DataArrayView& tOneView=tOneData.getView();
169     DataArray tTwoData(vShape,2.0);
170     DataArrayView& tTwoView=tTwoData.getView();
171     DataArray tThreeData(vShape,3.0);
172     DataArrayView& tThreeView=tThreeData.getView();
173     DataTagged::TagListType keys;
174     DataTagged::ValueListType values;
175     keys.push_back(1);
176     keys.push_back(2);
177     keys.push_back(3);
178     values.push_back(tOneView);
179     values.push_back(tTwoView);
180     values.push_back(tThreeView);
181     DataTagged tData(keys,values,defView,FunctionSpace());
182     unaryOp(tData,negate<double>());
183     unaryOp(tData,negate<double>());
184     assert(tData.getDataPointByTag(1)==tOneView);
185     assert(tData.getDataPointByTag(2)==tTwoView);
186     assert(tData.getDataPointByTag(3)==tThreeView);
187     }
188 jgs 501
189 jgs 82 }
190    
191 jgs 501 void DataTaggedTestCase::testAddTaggedValues() {
192    
193     cout << endl;
194    
195     {
196    
197     cout << "\tTest adding one key with empty value list to default DataTagged." << endl;
198     DataTagged myData;
199    
200     DataTagged::TagListType keys;
201     keys.push_back(1);
202    
203     DataTagged::ValueListType values;
204    
205     myData.addTaggedValues(keys,values);
206    
207     assert(myData.isCurrentTag(1));
208    
209     assert(myData.getTagLookup().size()==1);
210    
211     assert(myData.getLength()==2);
212    
213     // data-point 0 has tag number 1 by default
214     assert(myData.getTagNumber(0)==1);
215    
216     assert(myData.getPointOffset(0,0)==1);
217    
218     DataArrayView myDataView = myData.getDataPoint(0,0);
219     assert(!myDataView.isEmpty());
220     assert(myDataView.getOffset()==1);
221     assert(myDataView.getRank()==0);
222     assert(myDataView.noValues()==1);
223     assert(myDataView.getShape().size()==0);
224     assert(myDataView()==0.0);
225    
226     myDataView = myData.getDataPointByTag(1);
227     assert(!myDataView.isEmpty());
228     assert(myDataView.getOffset()==1);
229     assert(myDataView.getRank()==0);
230     assert(myDataView.noValues()==1);
231     assert(myDataView.getShape().size()==0);
232     assert(myDataView()==0.0);
233    
234     myDataView = myData.getDefaultValue();
235     assert(!myDataView.isEmpty());
236     assert(myDataView.getOffset()==0);
237     assert(myDataView.getRank()==0);
238     assert(myDataView.noValues()==1);
239     assert(myDataView.getShape().size()==0);
240     assert(myDataView()==0.0);
241    
242     }
243    
244     {
245    
246     cout << "\tTest adding one key with one value to default DataTagged." << endl;
247     DataTagged myData;
248    
249     DataTagged::TagListType keys;
250     keys.push_back(1);
251    
252     DataTagged::ValueListType values;
253    
254     DataArrayView::ShapeType viewShape;
255     DataArrayView::ValueType viewData(1);
256     viewData[0]=1.0;
257     DataArrayView myView(viewData,viewShape);
258     values.push_back(myView);
259    
260     myData.addTaggedValues(keys,values);
261    
262     assert(myData.isCurrentTag(1));
263    
264     assert(myData.getTagLookup().size()==1);
265    
266     assert(myData.getLength()==2);
267    
268     // data-point 0 has tag number 1 by default
269     assert(myData.getTagNumber(0)==1);
270    
271     assert(myData.getPointOffset(0,0)==1);
272    
273     DataArrayView myDataView = myData.getDataPoint(0,0);
274     assert(!myDataView.isEmpty());
275     assert(myDataView.getOffset()==1);
276     assert(myDataView.getRank()==0);
277     assert(myDataView.noValues()==1);
278     assert(myDataView.getShape().size()==0);
279     assert(myDataView()==1.0);
280    
281     myDataView = myData.getDataPointByTag(1);
282     assert(!myDataView.isEmpty());
283     assert(myDataView.getOffset()==1);
284     assert(myDataView.getRank()==0);
285     assert(myDataView.noValues()==1);
286     assert(myDataView.getShape().size()==0);
287     assert(myDataView()==1.0);
288    
289     myDataView = myData.getDefaultValue();
290     assert(!myDataView.isEmpty());
291     assert(myDataView.getOffset()==0);
292     assert(myDataView.getRank()==0);
293     assert(myDataView.noValues()==1);
294     assert(myDataView.getShape().size()==0);
295     assert(myDataView()==0.0);
296    
297     }
298    
299     {
300    
301     cout << "\tTest adding three keys with one value to default DataTagged." << endl;
302     DataTagged myData;
303    
304     DataTagged::TagListType keys;
305     keys.push_back(1);
306     keys.push_back(2);
307     keys.push_back(3);
308    
309     DataTagged::ValueListType values;
310    
311     DataArrayView::ShapeType viewShape;
312     DataArrayView::ValueType viewData(1);
313     viewData[0]=1.0;
314     DataArrayView myView(viewData,viewShape);
315     values.push_back(myView);
316    
317     myData.addTaggedValues(keys,values);
318    
319     assert(myData.isCurrentTag(1));
320     assert(myData.isCurrentTag(2));
321     assert(myData.isCurrentTag(3));
322    
323     assert(myData.getTagLookup().size()==3);
324    
325     assert(myData.getLength()==4);
326    
327     // data-point 0 has tag number 1 by default
328     assert(myData.getTagNumber(0)==1);
329    
330     assert(myData.getPointOffset(0,0)==1);
331    
332     DataArrayView myDataView = myData.getDataPoint(0,0);
333     assert(!myDataView.isEmpty());
334     assert(myDataView.getOffset()==1);
335     assert(myDataView.getRank()==0);
336     assert(myDataView.noValues()==1);
337     assert(myDataView.getShape().size()==0);
338     assert(myDataView()==1.0);
339    
340     myDataView = myData.getDataPointByTag(1);
341     assert(!myDataView.isEmpty());
342     assert(myDataView.getOffset()==1);
343     assert(myDataView.getRank()==0);
344     assert(myDataView.noValues()==1);
345     assert(myDataView.getShape().size()==0);
346     assert(myDataView()==1.0);
347    
348     myDataView = myData.getDataPointByTag(2);
349     assert(!myDataView.isEmpty());
350     assert(myDataView.getOffset()==2);
351     assert(myDataView.getRank()==0);
352     assert(myDataView.noValues()==1);
353     assert(myDataView.getShape().size()==0);
354     assert(myDataView()==1.0);
355    
356     myDataView = myData.getDataPointByTag(3);
357     assert(!myDataView.isEmpty());
358     assert(myDataView.getOffset()==3);
359     assert(myDataView.getRank()==0);
360     assert(myDataView.noValues()==1);
361     assert(myDataView.getShape().size()==0);
362     assert(myDataView()==1.0);
363    
364     myDataView = myData.getDefaultValue();
365     assert(!myDataView.isEmpty());
366     assert(myDataView.getOffset()==0);
367     assert(myDataView.getRank()==0);
368     assert(myDataView.noValues()==1);
369     assert(myDataView.getShape().size()==0);
370     assert(myDataView()==0.0);
371    
372     }
373    
374     {
375    
376     cout << "\tTest adding three keys with three values to default DataTagged." << endl;
377     DataTagged myData;
378    
379     DataTagged::TagListType keys;
380     keys.push_back(1);
381     keys.push_back(2);
382     keys.push_back(3);
383    
384     DataTagged::ValueListType values;
385    
386     DataArrayView::ShapeType viewShape;
387     DataArrayView::ValueType viewData1(1);
388     viewData1[0]=1.0;
389     DataArrayView::ValueType viewData2(1);
390     viewData2[0]=2.0;
391     DataArrayView::ValueType viewData3(1);
392     viewData3[0]=3.0;
393     DataArrayView myView1(viewData1,viewShape);
394     DataArrayView myView2(viewData2,viewShape);
395     DataArrayView myView3(viewData3,viewShape);
396     values.push_back(myView1);
397     values.push_back(myView2);
398     values.push_back(myView3);
399    
400     myData.addTaggedValues(keys,values);
401    
402     assert(myData.isCurrentTag(1));
403     assert(myData.isCurrentTag(2));
404     assert(myData.isCurrentTag(3));
405    
406     assert(myData.getTagLookup().size()==3);
407    
408     assert(myData.getLength()==4);
409    
410     // data-point 0 has tag number 1 by default
411     assert(myData.getTagNumber(0)==1);
412    
413     assert(myData.getPointOffset(0,0)==1);
414    
415     DataArrayView myDataView = myData.getDataPoint(0,0);
416     assert(!myDataView.isEmpty());
417     assert(myDataView.getOffset()==1);
418     assert(myDataView.getRank()==0);
419     assert(myDataView.noValues()==1);
420     assert(myDataView.getShape().size()==0);
421     assert(myDataView()==1.0);
422    
423     myDataView = myData.getDataPointByTag(1);
424     assert(!myDataView.isEmpty());
425     assert(myDataView.getOffset()==1);
426     assert(myDataView.getRank()==0);
427     assert(myDataView.noValues()==1);
428     assert(myDataView.getShape().size()==0);
429     assert(myDataView()==1.0);
430    
431     myDataView = myData.getDataPointByTag(2);
432     assert(!myDataView.isEmpty());
433     assert(myDataView.getOffset()==2);
434     assert(myDataView.getRank()==0);
435     assert(myDataView.noValues()==1);
436     assert(myDataView.getShape().size()==0);
437     assert(myDataView()==2.0);
438    
439     myDataView = myData.getDataPointByTag(3);
440     assert(!myDataView.isEmpty());
441     assert(myDataView.getOffset()==3);
442     assert(myDataView.getRank()==0);
443     assert(myDataView.noValues()==1);
444     assert(myDataView.getShape().size()==0);
445     assert(myDataView()==3.0);
446    
447     myDataView = myData.getDefaultValue();
448     assert(!myDataView.isEmpty());
449     assert(myDataView.getOffset()==0);
450     assert(myDataView.getRank()==0);
451     assert(myDataView.noValues()==1);
452     assert(myDataView.getShape().size()==0);
453     assert(myDataView()==0.0);
454    
455     }
456    
457     {
458    
459     cout << "\tTest adding one key with empty value list to DataTagged with default value only." << endl;
460    
461     DataArrayView::ShapeType viewShape;
462     viewShape.push_back(3);
463    
464     DataTagged::TagListType keys;
465    
466     DataTagged::ValueListType values;
467    
468     DataArrayView::ValueType viewData(3);
469     for (int i=0;i<viewShape[0];i++) {
470     viewData[i]=i;
471     }
472     DataArrayView myView(viewData,viewShape);
473    
474     DataTagged myData(keys,values,myView,FunctionSpace());
475    
476     keys.push_back(1);
477     values.clear();
478    
479     myData.addTaggedValues(keys,values);
480    
481     assert(myData.isCurrentTag(1));
482    
483     assert(myData.getTagLookup().size()==1);
484    
485     assert(myData.getLength()==6);
486    
487     // data-point 0 has tag number 1 by default
488     assert(myData.getTagNumber(0)==1);
489    
490     assert(myData.getPointOffset(0,0)==3);
491    
492     DataArrayView myDataView = myData.getDataPoint(0,0);
493     assert(myDataView==myView);
494     assert(!myDataView.isEmpty());
495     assert(myDataView.getOffset()==3);
496     assert(myDataView.getRank()==1);
497     assert(myDataView.noValues()==3);
498     assert(myDataView.getShape().size()==1);
499     assert(myDataView(0)==0);
500     assert(myDataView(1)==1);
501     assert(myDataView(2)==2);
502    
503     myDataView = myData.getDataPointByTag(1);
504     assert(myDataView==myView);
505     assert(!myDataView.isEmpty());
506     assert(myDataView.getOffset()==3);
507     assert(myDataView.getRank()==1);
508     assert(myDataView.noValues()==3);
509     assert(myDataView.getShape().size()==1);
510     assert(myDataView(0)==0);
511     assert(myDataView(1)==1);
512     assert(myDataView(2)==2);
513    
514     myDataView = myData.getDefaultValue();
515     assert(myDataView==myView);
516     assert(!myDataView.isEmpty());
517     assert(myDataView.getOffset()==0);
518     assert(myDataView.getRank()==1);
519     assert(myDataView.noValues()==3);
520     assert(myDataView.getShape().size()==1);
521     assert(myDataView(0)==0);
522     assert(myDataView(1)==1);
523     assert(myDataView(2)==2);
524    
525     }
526    
527     {
528    
529     cout << "\tTest adding one key with one value to DataTagged with default value only." << endl;
530    
531     DataArrayView::ShapeType viewShape;
532     viewShape.push_back(3);
533    
534     DataTagged::TagListType keys;
535    
536     DataTagged::ValueListType values;
537    
538     DataArrayView::ValueType viewData(3);
539     for (int i=0;i<viewShape[0];i++) {
540     viewData[i]=i;
541     }
542     DataArrayView myView(viewData,viewShape);
543    
544     DataTagged myData(keys,values,myView,FunctionSpace());
545    
546     keys.push_back(1);
547    
548     DataArrayView::ValueType viewData1(3);
549     for (int i=0;i<viewShape[0];i++) {
550     viewData1[i]=i+1;
551     }
552     DataArrayView myView1(viewData1,viewShape);
553     values.push_back(myView1);
554    
555     myData.addTaggedValues(keys,values);
556    
557     assert(myData.isCurrentTag(1));
558    
559     assert(myData.getTagLookup().size()==1);
560    
561     assert(myData.getLength()==6);
562    
563     // data-point 0 has tag number 1 by default
564     assert(myData.getTagNumber(0)==1);
565    
566     assert(myData.getPointOffset(0,0)==3);
567    
568     DataArrayView myDataView = myData.getDataPoint(0,0);
569     assert(myDataView==myView1);
570     assert(!myDataView.isEmpty());
571     assert(myDataView.getOffset()==3);
572     assert(myDataView.getRank()==1);
573     assert(myDataView.noValues()==3);
574     assert(myDataView.getShape().size()==1);
575     assert(myDataView(0)==1);
576     assert(myDataView(1)==2);
577     assert(myDataView(2)==3);
578    
579     myDataView = myData.getDataPointByTag(1);
580     assert(myDataView==myView1);
581     assert(!myDataView.isEmpty());
582     assert(myDataView.getOffset()==3);
583     assert(myDataView.getRank()==1);
584     assert(myDataView.noValues()==3);
585     assert(myDataView.getShape().size()==1);
586     assert(myDataView(0)==1);
587     assert(myDataView(1)==2);
588     assert(myDataView(2)==3);
589    
590     myDataView = myData.getDefaultValue();
591     assert(myDataView==myView);
592     assert(!myDataView.isEmpty());
593     assert(myDataView.getOffset()==0);
594     assert(myDataView.getRank()==1);
595     assert(myDataView.noValues()==3);
596     assert(myDataView.getShape().size()==1);
597     assert(myDataView(0)==0);
598     assert(myDataView(1)==1);
599     assert(myDataView(2)==2);
600    
601     }
602    
603     {
604    
605     cout << "\tTest adding three keys with one value to DataTagged with default value only." << endl;
606    
607     DataArrayView::ShapeType viewShape;
608     viewShape.push_back(3);
609    
610     DataTagged::TagListType keys;
611    
612     DataTagged::ValueListType values;
613    
614     DataArrayView::ValueType viewData(3);
615     for (int i=0;i<viewShape[0];i++) {
616     viewData[i]=i;
617     }
618     DataArrayView myView(viewData,viewShape);
619    
620     DataTagged myData(keys,values,myView,FunctionSpace());
621    
622     keys.push_back(1);
623     keys.push_back(2);
624     keys.push_back(3);
625    
626     DataArrayView::ValueType viewData1(3);
627     for (int i=0;i<viewShape[0];i++) {
628     viewData1[i]=i+1;
629     }
630     DataArrayView myView1(viewData1,viewShape);
631     values.push_back(myView1);
632    
633     myData.addTaggedValues(keys,values);
634    
635     assert(myData.isCurrentTag(1));
636     assert(myData.isCurrentTag(2));
637     assert(myData.isCurrentTag(3));
638    
639     assert(myData.getTagLookup().size()==3);
640    
641     assert(myData.getLength()==12);
642    
643     // data-point 0 has tag number 1 by default
644     assert(myData.getTagNumber(0)==1);
645    
646     assert(myData.getPointOffset(0,0)==3);
647    
648     DataArrayView myDataView = myData.getDataPoint(0,0);
649     assert(myDataView==myView1);
650     assert(!myDataView.isEmpty());
651     assert(myDataView.getOffset()==3);
652     assert(myDataView.getRank()==1);
653     assert(myDataView.noValues()==3);
654     assert(myDataView.getShape().size()==1);
655     assert(myDataView(0)==1);
656     assert(myDataView(1)==2);
657     assert(myDataView(2)==3);
658    
659     myDataView = myData.getDataPointByTag(1);
660     assert(myDataView==myView1);
661     assert(!myDataView.isEmpty());
662     assert(myDataView.getOffset()==3);
663     assert(myDataView.getRank()==1);
664     assert(myDataView.noValues()==3);
665     assert(myDataView.getShape().size()==1);
666     assert(myDataView(0)==1);
667     assert(myDataView(1)==2);
668     assert(myDataView(2)==3);
669    
670     myDataView = myData.getDataPointByTag(2);
671     assert(myDataView==myView1);
672     assert(!myDataView.isEmpty());
673     assert(myDataView.getOffset()==6);
674     assert(myDataView.getRank()==1);
675     assert(myDataView.noValues()==3);
676     assert(myDataView.getShape().size()==1);
677     assert(myDataView(0)==1);
678     assert(myDataView(1)==2);
679     assert(myDataView(2)==3);
680    
681     myDataView = myData.getDataPointByTag(3);
682     assert(myDataView==myView1);
683     assert(!myDataView.isEmpty());
684     assert(myDataView.getOffset()==9);
685     assert(myDataView.getRank()==1);
686     assert(myDataView.noValues()==3);
687     assert(myDataView.getShape().size()==1);
688     assert(myDataView(0)==1);
689     assert(myDataView(1)==2);
690     assert(myDataView(2)==3);
691    
692     myDataView = myData.getDefaultValue();
693     assert(myDataView==myView);
694     assert(!myDataView.isEmpty());
695     assert(myDataView.getOffset()==0);
696     assert(myDataView.getRank()==1);
697     assert(myDataView.noValues()==3);
698     assert(myDataView.getShape().size()==1);
699     assert(myDataView(0)==0);
700     assert(myDataView(1)==1);
701     assert(myDataView(2)==2);
702    
703     }
704    
705     {
706    
707     cout << "\tTest adding three keys with three values to DataTagged with default value only." << endl;
708    
709     DataArrayView::ShapeType viewShape;
710     viewShape.push_back(3);
711    
712     DataTagged::TagListType keys;
713    
714     DataTagged::ValueListType values;
715    
716     DataArrayView::ValueType viewData(3);
717     for (int i=0;i<viewShape[0];i++) {
718     viewData[i]=i;
719     }
720     DataArrayView myView(viewData,viewShape);
721    
722     DataTagged myData(keys,values,myView,FunctionSpace());
723    
724     keys.push_back(1);
725     keys.push_back(2);
726     keys.push_back(3);
727    
728     DataArrayView::ValueType viewData1(3);
729     for (int i=0;i<viewShape[0];i++) {
730     viewData1[i]=i+1;
731     }
732     DataArrayView myView1(viewData1,viewShape);
733     values.push_back(myView1);
734    
735     DataArrayView::ValueType viewData2(3);
736     for (int i=0;i<viewShape[0];i++) {
737     viewData2[i]=i+2;
738     }
739     DataArrayView myView2(viewData2,viewShape);
740     values.push_back(myView2);
741    
742     DataArrayView::ValueType viewData3(3);
743     for (int i=0;i<viewShape[0];i++) {
744     viewData3[i]=i+3;
745     }
746     DataArrayView myView3(viewData3,viewShape);
747     values.push_back(myView3);
748    
749     myData.addTaggedValues(keys,values);
750    
751     assert(myData.isCurrentTag(1));
752     assert(myData.isCurrentTag(2));
753     assert(myData.isCurrentTag(3));
754    
755     assert(myData.getTagLookup().size()==3);
756    
757     assert(myData.getLength()==12);
758    
759     // data-point 0 has tag number 1 by default
760     assert(myData.getTagNumber(0)==1);
761    
762     assert(myData.getPointOffset(0,0)==3);
763    
764     DataArrayView myDataView = myData.getDataPoint(0,0);
765     assert(myDataView==myView1);
766     assert(!myDataView.isEmpty());
767     assert(myDataView.getOffset()==3);
768     assert(myDataView.getRank()==1);
769     assert(myDataView.noValues()==3);
770     assert(myDataView.getShape().size()==1);
771     assert(myDataView(0)==1);
772     assert(myDataView(1)==2);
773     assert(myDataView(2)==3);
774    
775     myDataView = myData.getDataPointByTag(1);
776     assert(myDataView==myView1);
777     assert(!myDataView.isEmpty());
778     assert(myDataView.getOffset()==3);
779     assert(myDataView.getRank()==1);
780     assert(myDataView.noValues()==3);
781     assert(myDataView.getShape().size()==1);
782     assert(myDataView(0)==1);
783     assert(myDataView(1)==2);
784     assert(myDataView(2)==3);
785    
786     myDataView = myData.getDataPointByTag(2);
787     assert(myDataView==myView2);
788     assert(!myDataView.isEmpty());
789     assert(myDataView.getOffset()==6);
790     assert(myDataView.getRank()==1);
791     assert(myDataView.noValues()==3);
792     assert(myDataView.getShape().size()==1);
793     assert(myDataView(0)==2);
794     assert(myDataView(1)==3);
795     assert(myDataView(2)==4);
796    
797     myDataView = myData.getDataPointByTag(3);
798     assert(myDataView==myView3);
799     assert(!myDataView.isEmpty());
800     assert(myDataView.getOffset()==9);
801     assert(myDataView.getRank()==1);
802     assert(myDataView.noValues()==3);
803     assert(myDataView.getShape().size()==1);
804     assert(myDataView(0)==3);
805     assert(myDataView(1)==4);
806     assert(myDataView(2)==5);
807    
808     myDataView = myData.getDefaultValue();
809     assert(myDataView==myView);
810     assert(!myDataView.isEmpty());
811     assert(myDataView.getOffset()==0);
812     assert(myDataView.getRank()==1);
813     assert(myDataView.noValues()==3);
814     assert(myDataView.getShape().size()==1);
815     assert(myDataView(0)==0);
816     assert(myDataView(1)==1);
817     assert(myDataView(2)==2);
818    
819     }
820    
821     {
822    
823     cout << "\tTest adding one key with empty value list to DataTagged with three tags." << endl;
824    
825     DataTagged::TagListType keys;
826     keys.push_back(1);
827     keys.push_back(2);
828     keys.push_back(3);
829    
830     DataTagged::ValueListType values;
831    
832     DataArrayView::ShapeType viewShape;
833     viewShape.push_back(3);
834    
835     // default value
836     DataArrayView::ValueType viewData(3);
837     for (int i=0;i<viewShape[0];i++) {
838     viewData[i]=i;
839     }
840     DataArrayView myView(viewData,viewShape);
841    
842     // value for tag "1"
843     DataArray eOne(myView);
844     for (int i=0;i<eOne.getView().getShape()[0];i++) {
845     eOne.getView()(i)=i+1.0;
846     }
847     values.push_back(eOne.getView());
848    
849     // value for tag "2"
850     DataArray eTwo(myView);
851     for (int i=0;i<eTwo.getView().getShape()[0];i++) {
852     eTwo.getView()(i)=i+2.0;
853     }
854     values.push_back(eTwo.getView());
855    
856     // value for tag "3"
857     DataArray eThree(myView);
858     for (int i=0;i<eThree.getView().getShape()[0];i++) {
859     eThree.getView()(i)=i+3.0;
860     }
861     values.push_back(eThree.getView());
862    
863     DataTagged myData(keys,values,myView,FunctionSpace());
864    
865     keys.clear();
866     keys.push_back(4);
867     values.clear();
868    
869     myData.addTaggedValues(keys,values);
870    
871     assert(myData.isCurrentTag(4));
872    
873     assert(myData.getTagLookup().size()==4);
874    
875     assert(myData.getLength()==15);
876    
877     DataArrayView myDataView = myData.getDataPointByTag(4);
878     assert(myDataView==myView);
879     assert(!myDataView.isEmpty());
880     assert(myDataView.getOffset()==12);
881     assert(myDataView.getRank()==1);
882     assert(myDataView.noValues()==3);
883     assert(myDataView.getShape().size()==1);
884     assert(myDataView(0)==0);
885     assert(myDataView(1)==1);
886     assert(myDataView(2)==2);
887    
888     }
889    
890     {
891    
892     cout << "\tTest adding one key with one value to DataTagged with three tags." << endl;
893    
894     DataTagged::TagListType keys;
895     keys.push_back(1);
896     keys.push_back(2);
897     keys.push_back(3);
898    
899     DataTagged::ValueListType values;
900    
901     DataArrayView::ShapeType viewShape;
902     viewShape.push_back(3);
903    
904     // default value
905     DataArrayView::ValueType viewData(3);
906     for (int i=0;i<viewShape[0];i++) {
907     viewData[i]=i;
908     }
909     DataArrayView myView(viewData,viewShape);
910    
911     // value for tag "1"
912     DataArray eOne(myView);
913     for (int i=0;i<eOne.getView().getShape()[0];i++) {
914     eOne.getView()(i)=i+1.0;
915     }
916     values.push_back(eOne.getView());
917    
918     // value for tag "2"
919     DataArray eTwo(myView);
920     for (int i=0;i<eTwo.getView().getShape()[0];i++) {
921     eTwo.getView()(i)=i+2.0;
922     }
923     values.push_back(eTwo.getView());
924    
925     // value for tag "3"
926     DataArray eThree(myView);
927     for (int i=0;i<eThree.getView().getShape()[0];i++) {
928     eThree.getView()(i)=i+3.0;
929     }
930     values.push_back(eThree.getView());
931    
932     DataTagged myData(keys,values,myView,FunctionSpace());
933    
934     keys.clear();
935     keys.push_back(4);
936    
937     values.clear();
938     // value for tag "4"
939     DataArray eFour(myView);
940     for (int i=0;i<eFour.getView().getShape()[0];i++) {
941     eFour.getView()(i)=i+4.0;
942     }
943     values.push_back(eFour.getView());
944    
945     myData.addTaggedValues(keys,values);
946    
947     assert(myData.isCurrentTag(4));
948    
949     assert(myData.getTagLookup().size()==4);
950    
951     assert(myData.getLength()==15);
952    
953     DataArrayView myDataView = myData.getDataPointByTag(4);
954     assert(myDataView==eFour.getView());
955     assert(!myDataView.isEmpty());
956     assert(myDataView.getOffset()==12);
957     assert(myDataView.getRank()==1);
958     assert(myDataView.noValues()==3);
959     assert(myDataView.getShape().size()==1);
960     assert(myDataView(0)==4);
961     assert(myDataView(1)==5);
962     assert(myDataView(2)==6);
963    
964     }
965    
966     {
967    
968     cout << "\tTest adding three keys with one value to DataTagged with three tags." << endl;
969    
970     DataTagged::TagListType keys;
971     keys.push_back(1);
972     keys.push_back(2);
973     keys.push_back(3);
974    
975     DataTagged::ValueListType values;
976    
977     DataArrayView::ShapeType viewShape;
978     viewShape.push_back(3);
979    
980     // default value
981     DataArrayView::ValueType viewData(3);
982     for (int i=0;i<viewShape[0];i++) {
983     viewData[i]=i;
984     }
985     DataArrayView myView(viewData,viewShape);
986    
987     // value for tag "1"
988     DataArray eOne(myView);
989     for (int i=0;i<eOne.getView().getShape()[0];i++) {
990     eOne.getView()(i)=i+1.0;
991     }
992     values.push_back(eOne.getView());
993    
994     // value for tag "2"
995     DataArray eTwo(myView);
996     for (int i=0;i<eTwo.getView().getShape()[0];i++) {
997     eTwo.getView()(i)=i+2.0;
998     }
999     values.push_back(eTwo.getView());
1000    
1001     // value for tag "3"
1002     DataArray eThree(myView);
1003     for (int i=0;i<eThree.getView().getShape()[0];i++) {
1004     eThree.getView()(i)=i+3.0;
1005     }
1006     values.push_back(eThree.getView());
1007    
1008     DataTagged myData(keys,values,myView,FunctionSpace());
1009    
1010     keys.clear();
1011     keys.push_back(4);
1012     keys.push_back(5);
1013     keys.push_back(6);
1014    
1015     values.clear();
1016     // value for tags "4", "5" and "6"
1017     DataArray eFour(myView);
1018     for (int i=0;i<eFour.getView().getShape()[0];i++) {
1019     eFour.getView()(i)=i+4.0;
1020     }
1021     values.push_back(eFour.getView());
1022    
1023     myData.addTaggedValues(keys,values);
1024    
1025     assert(myData.isCurrentTag(4));
1026     assert(myData.isCurrentTag(5));
1027     assert(myData.isCurrentTag(6));
1028    
1029     assert(myData.getTagLookup().size()==6);
1030    
1031     assert(myData.getLength()==21);
1032    
1033     DataArrayView myDataView = myData.getDataPointByTag(4);
1034     assert(myDataView==eFour.getView());
1035     assert(!myDataView.isEmpty());
1036     assert(myDataView.getOffset()==12);
1037     assert(myDataView.getRank()==1);
1038     assert(myDataView.noValues()==3);
1039     assert(myDataView.getShape().size()==1);
1040     assert(myDataView(0)==4);
1041     assert(myDataView(1)==5);
1042     assert(myDataView(2)==6);
1043    
1044     myDataView = myData.getDataPointByTag(5);
1045     assert(myDataView==eFour.getView());
1046     assert(!myDataView.isEmpty());
1047     assert(myDataView.getOffset()==15);
1048     assert(myDataView.getRank()==1);
1049     assert(myDataView.noValues()==3);
1050     assert(myDataView.getShape().size()==1);
1051     assert(myDataView(0)==4);
1052     assert(myDataView(1)==5);
1053     assert(myDataView(2)==6);
1054    
1055     myDataView = myData.getDataPointByTag(6);
1056     assert(myDataView==eFour.getView());
1057     assert(!myDataView.isEmpty());
1058     assert(myDataView.getOffset()==18);
1059     assert(myDataView.getRank()==1);
1060     assert(myDataView.noValues()==3);
1061     assert(myDataView.getShape().size()==1);
1062     assert(myDataView(0)==4);
1063     assert(myDataView(1)==5);
1064     assert(myDataView(2)==6);
1065    
1066     }
1067    
1068     {
1069    
1070     cout << "\tTest adding three keys with three values to DataTagged with three tags." << endl;
1071    
1072     DataTagged::TagListType keys;
1073     keys.push_back(1);
1074     keys.push_back(2);
1075     keys.push_back(3);
1076    
1077     DataTagged::ValueListType values;
1078    
1079     DataArrayView::ShapeType viewShape;
1080     viewShape.push_back(3);
1081    
1082     // default value
1083     DataArrayView::ValueType viewData(3);
1084     for (int i=0;i<viewShape[0];i++) {
1085     viewData[i]=i;
1086     }
1087     DataArrayView myView(viewData,viewShape);
1088    
1089     // value for tag "1"
1090     DataArray eOne(myView);
1091     for (int i=0;i<eOne.getView().getShape()[0];i++) {
1092     eOne.getView()(i)=i+1.0;
1093     }
1094     values.push_back(eOne.getView());
1095    
1096     // value for tag "2"
1097     DataArray eTwo(myView);
1098     for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1099     eTwo.getView()(i)=i+2.0;
1100     }
1101     values.push_back(eTwo.getView());
1102    
1103     // value for tag "3"
1104     DataArray eThree(myView);
1105     for (int i=0;i<eThree.getView().getShape()[0];i++) {
1106     eThree.getView()(i)=i+3.0;
1107     }
1108     values.push_back(eThree.getView());
1109    
1110     DataTagged myData(keys,values,myView,FunctionSpace());
1111    
1112     keys.clear();
1113     keys.push_back(4);
1114     keys.push_back(5);
1115     keys.push_back(6);
1116    
1117     values.clear();
1118    
1119     // value for tag "4"
1120     DataArray eFour(myView);
1121     for (int i=0;i<eFour.getView().getShape()[0];i++) {
1122     eFour.getView()(i)=i+4.0;
1123     }
1124     values.push_back(eFour.getView());
1125    
1126     // value for tag "5"
1127     DataArray eFive(myView);
1128     for (int i=0;i<eFive.getView().getShape()[0];i++) {
1129     eFive.getView()(i)=i+5.0;
1130     }
1131     values.push_back(eFive.getView());
1132    
1133     // value for tag "6"
1134     DataArray eSix(myView);
1135     for (int i=0;i<eSix.getView().getShape()[0];i++) {
1136     eSix.getView()(i)=i+6.0;
1137     }
1138     values.push_back(eSix.getView());
1139    
1140     myData.addTaggedValues(keys,values);
1141    
1142     assert(myData.isCurrentTag(4));
1143     assert(myData.isCurrentTag(5));
1144     assert(myData.isCurrentTag(6));
1145    
1146     assert(myData.getTagLookup().size()==6);
1147    
1148     assert(myData.getLength()==21);
1149    
1150     DataArrayView myDataView = myData.getDataPointByTag(4);
1151     assert(myDataView==eFour.getView());
1152     assert(!myDataView.isEmpty());
1153     assert(myDataView.getOffset()==12);
1154     assert(myDataView.getRank()==1);
1155     assert(myDataView.noValues()==3);
1156     assert(myDataView.getShape().size()==1);
1157     assert(myDataView(0)==4);
1158     assert(myDataView(1)==5);
1159     assert(myDataView(2)==6);
1160    
1161     myDataView = myData.getDataPointByTag(5);
1162     assert(myDataView==eFive.getView());
1163     assert(!myDataView.isEmpty());
1164     assert(myDataView.getOffset()==15);
1165     assert(myDataView.getRank()==1);
1166     assert(myDataView.noValues()==3);
1167     assert(myDataView.getShape().size()==1);
1168     assert(myDataView(0)==5);
1169     assert(myDataView(1)==6);
1170     assert(myDataView(2)==7);
1171    
1172     myDataView = myData.getDataPointByTag(6);
1173     assert(myDataView==eSix.getView());
1174     assert(!myDataView.isEmpty());
1175     assert(myDataView.getOffset()==18);
1176     assert(myDataView.getRank()==1);
1177     assert(myDataView.noValues()==3);
1178     assert(myDataView.getShape().size()==1);
1179     assert(myDataView(0)==6);
1180     assert(myDataView(1)==7);
1181     assert(myDataView(2)==8);
1182    
1183     }
1184    
1185     }
1186    
1187 jgs 502 void DataTaggedTestCase::testSetTaggedValue() {
1188    
1189     cout << endl;
1190    
1191     {
1192    
1193     cout << "\tTest setting key in DataTagged with three tags." << endl;
1194    
1195     DataTagged::TagListType keys;
1196     keys.push_back(1);
1197     keys.push_back(2);
1198     keys.push_back(3);
1199    
1200     DataTagged::ValueListType values;
1201    
1202     DataArrayView::ShapeType viewShape;
1203     viewShape.push_back(3);
1204    
1205     // default value
1206     DataArrayView::ValueType viewData(3);
1207     for (int i=0;i<viewShape[0];i++) {
1208     viewData[i]=i;
1209     }
1210     DataArrayView myView(viewData,viewShape);
1211    
1212     // value for tag "1"
1213     DataArray eOne(myView);
1214     for (int i=0;i<eOne.getView().getShape()[0];i++) {
1215     eOne.getView()(i)=i+1.0;
1216     }
1217     values.push_back(eOne.getView());
1218    
1219     // value for tag "2"
1220     DataArray eTwo(myView);
1221     for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1222     eTwo.getView()(i)=i+2.0;
1223     }
1224     values.push_back(eTwo.getView());
1225    
1226     // value for tag "3"
1227     DataArray eThree(myView);
1228     for (int i=0;i<eThree.getView().getShape()[0];i++) {
1229     eThree.getView()(i)=i+3.0;
1230     }
1231     values.push_back(eThree.getView());
1232    
1233     DataTagged myData(keys,values,myView,FunctionSpace());
1234    
1235     // new value for tag "2"
1236     for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1237     eTwo.getView()(i)=i+5.0;
1238     }
1239    
1240     myData.setTaggedValue(2,eTwo.getView());
1241    
1242     assert(myData.isCurrentTag(2));
1243    
1244     assert(myData.getTagLookup().size()==3);
1245    
1246     assert(myData.getLength()==12);
1247    
1248     DataArrayView myDataView = myData.getDataPointByTag(2);
1249     assert(myDataView==eTwo.getView());
1250     assert(!myDataView.isEmpty());
1251     assert(myDataView.getOffset()==6);
1252     assert(myDataView.getRank()==1);
1253     assert(myDataView.noValues()==3);
1254     assert(myDataView.getShape().size()==1);
1255     assert(myDataView(0)==5);
1256     assert(myDataView(1)==6);
1257     assert(myDataView(2)==7);
1258    
1259     }
1260    
1261     }
1262    
1263 jgs 82 void DataTaggedTestCase::testAll() {
1264 jgs 121
1265 jgs 82 cout << endl;
1266 jgs 121
1267 jgs 82 {
1268 jgs 497
1269     cout << "\tTest default DataTagged." << endl;
1270 jgs 82 DataTagged myData;
1271 jgs 497
1272 jgs 499 //cout << myData.toString() << endl;
1273    
1274 jgs 497 assert(myData.getNumSamples()==1);
1275 jgs 82 assert(myData.getNumDPPSample()==1);
1276 jgs 497
1277     assert(myData.validSamplePointNo(0));
1278     assert(myData.validSampleNo(0));
1279     assert(!myData.validSamplePointNo(1));
1280     assert(!myData.validSampleNo(1));
1281    
1282 jgs 501 // data-point 0 has tag number 1 by default
1283 jgs 497 assert(myData.getTagNumber(0)==1);
1284    
1285     assert(!myData.isCurrentTag(1));
1286    
1287     assert(myData.getTagLookup().size()==0);
1288    
1289     assert(myData.getLength()==1);
1290    
1291     assert(myData.getPointOffset(0,0)==0);
1292    
1293     DataArrayView myDataView = myData.getDataPoint(0,0);
1294     assert(!myDataView.isEmpty());
1295     assert(myDataView.getOffset()==0);
1296     assert(myDataView.getRank()==0);
1297     assert(myDataView.noValues()==1);
1298     assert(myDataView.getShape().size()==0);
1299     assert(myDataView()==0.0);
1300    
1301 jgs 499 // Test non-existent tag returns the default value.
1302 jgs 497 myDataView = myData.getDataPointByTag(1);
1303     assert(!myDataView.isEmpty());
1304     assert(myDataView.getOffset()==0);
1305     assert(myDataView.getRank()==0);
1306     assert(myDataView.noValues()==1);
1307     assert(myDataView.getShape().size()==0);
1308     assert(myDataView()==0.0);
1309    
1310     myDataView = myData.getDefaultValue();
1311     assert(!myDataView.isEmpty());
1312     assert(myDataView.getOffset()==0);
1313     assert(myDataView.getRank()==0);
1314     assert(myDataView.noValues()==1);
1315     assert(myDataView.getShape().size()==0);
1316     assert(myDataView()==0.0);
1317    
1318 jgs 82 }
1319 jgs 497
1320 jgs 82 {
1321 jgs 497
1322 jgs 499 cout << "\tTest DataTagged with default value only." << endl;
1323    
1324     DataArrayView::ShapeType viewShape;
1325     viewShape.push_back(3);
1326    
1327     DataTagged::TagListType keys;
1328    
1329     DataTagged::ValueListType values;
1330    
1331     DataArrayView::ValueType viewData(3);
1332     for (int i=0;i<viewShape[0];i++) {
1333     viewData[i]=i;
1334     }
1335     DataArrayView myView(viewData,viewShape);
1336    
1337     DataTagged myData(keys,values,myView,FunctionSpace());
1338    
1339     //cout << myData.toString() << endl;
1340    
1341     assert(myData.getNumSamples()==1);
1342     assert(myData.getNumDPPSample()==1);
1343    
1344     assert(myData.validSamplePointNo(0));
1345     assert(myData.validSampleNo(0));
1346     assert(!myData.validSamplePointNo(1));
1347     assert(!myData.validSampleNo(1));
1348    
1349 jgs 501 // data-point 0 has tag number 1 by default
1350 jgs 499 assert(myData.getTagNumber(0)==1);
1351    
1352     assert(!myData.isCurrentTag(1));
1353    
1354     assert(myData.getTagLookup().size()==0);
1355    
1356     assert(myData.getLength()==3);
1357    
1358     assert(myData.getPointOffset(0,0)==0);
1359    
1360     DataArrayView myDataView = myData.getDataPoint(0,0);
1361     assert(myDataView==myView);
1362     assert(!myDataView.isEmpty());
1363     assert(myDataView.getOffset()==0);
1364     assert(myDataView.getRank()==1);
1365     assert(myDataView.noValues()==3);
1366     assert(myDataView.getShape().size()==1);
1367     assert(myDataView(0)==0);
1368     assert(myDataView(1)==1);
1369     assert(myDataView(2)==2);
1370    
1371     // Test non-existent tag returns the default value.
1372     myDataView = myData.getDataPointByTag(1);
1373     assert(myDataView==myView);
1374     assert(!myDataView.isEmpty());
1375     assert(myDataView.getOffset()==0);
1376     assert(myDataView.getRank()==1);
1377     assert(myDataView.noValues()==3);
1378     assert(myDataView.getShape().size()==1);
1379     assert(myDataView(0)==0);
1380     assert(myDataView(1)==1);
1381     assert(myDataView(2)==2);
1382    
1383     myDataView = myData.getDefaultValue();
1384     assert(myDataView==myView);
1385     assert(!myDataView.isEmpty());
1386     assert(myDataView.getOffset()==0);
1387     assert(myDataView.getRank()==1);
1388     assert(myDataView.noValues()==3);
1389     assert(myDataView.getShape().size()==1);
1390     assert(myDataView(0)==0);
1391     assert(myDataView(1)==1);
1392     assert(myDataView(2)==2);
1393    
1394 jgs 82 }
1395 jgs 497
1396 jgs 82 {
1397 jgs 497
1398 jgs 499 cout << "\tTest DataTagged with one tag." << endl;
1399    
1400     // the one data-point has tag value "1"
1401    
1402     DataTagged::TagListType keys;
1403     keys.push_back(1);
1404    
1405     DataTagged::ValueListType values;
1406    
1407     DataArrayView::ShapeType viewShape;
1408     viewShape.push_back(3);
1409    
1410     // default value
1411     DataArrayView::ValueType viewData(3);
1412     for (int i=0;i<viewShape[0];i++) {
1413     viewData[i]=i;
1414     }
1415     DataArrayView myView(viewData,viewShape);
1416    
1417     // value for tag "1"
1418     DataArray eOne(myView);
1419     for (int i=0;i<eOne.getView().getShape()[0];i++) {
1420     eOne.getView()(i)=i+1.0;
1421     }
1422     values.push_back(eOne.getView());
1423    
1424     DataTagged myData(keys,values,myView,FunctionSpace());
1425    
1426     //cout << myData.toString() << endl;
1427    
1428     assert(myData.getNumSamples()==1);
1429     assert(myData.getNumDPPSample()==1);
1430    
1431     assert(myData.validSamplePointNo(0));
1432     assert(myData.validSampleNo(0));
1433     assert(!myData.validSamplePointNo(1));
1434     assert(!myData.validSampleNo(1));
1435    
1436 jgs 501 // data-point 0 has tag number 1 by default
1437 jgs 499 assert(myData.getTagNumber(0)==1);
1438    
1439     assert(!myData.isCurrentTag(0));
1440     assert(myData.isCurrentTag(1));
1441    
1442     assert(myData.getTagLookup().size()==1);
1443    
1444     assert(myData.getLength()==6);
1445    
1446     assert(myData.getPointOffset(0,0)==3);
1447    
1448     DataArrayView myDataView = myData.getDataPoint(0,0);
1449     assert(myDataView==eOne.getView());
1450     assert(!myDataView.isEmpty());
1451     assert(myDataView.getOffset()==3);
1452     assert(myDataView.getRank()==1);
1453     assert(myDataView.noValues()==3);
1454     assert(myDataView.getShape().size()==1);
1455     assert(myDataView(0)==1);
1456     assert(myDataView(1)==2);
1457     assert(myDataView(2)==3);
1458    
1459     myDataView = myData.getDataPointByTag(1);
1460     assert(myDataView==eOne.getView());
1461     assert(!myDataView.isEmpty());
1462     assert(myDataView.getOffset()==3);
1463     assert(myDataView.getRank()==1);
1464     assert(myDataView.noValues()==3);
1465     assert(myDataView.getShape().size()==1);
1466     assert(myDataView(0)==1);
1467     assert(myDataView(1)==2);
1468     assert(myDataView(2)==3);
1469    
1470     // Test non-existent tag returns the default value.
1471     myDataView = myData.getDataPointByTag(0);
1472     assert(myDataView==myView);
1473     assert(!myDataView.isEmpty());
1474     assert(myDataView.getOffset()==0);
1475     assert(myDataView.getRank()==1);
1476     assert(myDataView.noValues()==3);
1477     assert(myDataView.getShape().size()==1);
1478     assert(myDataView(0)==0);
1479     assert(myDataView(1)==1);
1480     assert(myDataView(2)==2);
1481    
1482     myDataView = myData.getDefaultValue();
1483     assert(myDataView==myView);
1484     assert(!myDataView.isEmpty());
1485     assert(myDataView.getOffset()==0);
1486     assert(myDataView.getRank()==1);
1487     assert(myDataView.noValues()==3);
1488     assert(myDataView.getShape().size()==1);
1489     assert(myDataView(0)==0);
1490     assert(myDataView(1)==1);
1491     assert(myDataView(2)==2);
1492    
1493     }
1494    
1495     {
1496    
1497     cout << "\tTest DataTagged with multiple tags." << endl;
1498    
1499     // the one data-point has tag value "1"
1500    
1501     DataTagged::TagListType keys;
1502     keys.push_back(1);
1503     keys.push_back(2);
1504     keys.push_back(3);
1505    
1506     DataTagged::ValueListType values;
1507    
1508     DataArrayView::ShapeType viewShape;
1509     viewShape.push_back(3);
1510    
1511     // default value
1512     DataArrayView::ValueType viewData(3);
1513     for (int i=0;i<viewShape[0];i++) {
1514     viewData[i]=i;
1515     }
1516     DataArrayView myView(viewData,viewShape);
1517    
1518     // value for tag "1"
1519     DataArray eOne(myView);
1520     for (int i=0;i<eOne.getView().getShape()[0];i++) {
1521     eOne.getView()(i)=i+1.0;
1522     }
1523     values.push_back(eOne.getView());
1524    
1525     // value for tag "2"
1526     DataArray eTwo(myView);
1527     for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1528     eTwo.getView()(i)=i+2.0;
1529     }
1530     values.push_back(eTwo.getView());
1531    
1532     // value for tag "3"
1533     DataArray eThree(myView);
1534     for (int i=0;i<eThree.getView().getShape()[0];i++) {
1535     eThree.getView()(i)=i+3.0;
1536     }
1537     values.push_back(eThree.getView());
1538    
1539     DataTagged myData(keys,values,myView,FunctionSpace());
1540    
1541     //cout << myData.toString() << endl;
1542    
1543     assert(myData.getNumSamples()==1);
1544     assert(myData.getNumDPPSample()==1);
1545    
1546     assert(myData.validSamplePointNo(0));
1547     assert(myData.validSampleNo(0));
1548     assert(!myData.validSamplePointNo(1));
1549     assert(!myData.validSampleNo(1));
1550    
1551 jgs 501 // data-point 0 has tag number 1 by default
1552 jgs 499 assert(myData.getTagNumber(0)==1);
1553    
1554     assert(!myData.isCurrentTag(0));
1555     assert(myData.isCurrentTag(1));
1556     assert(myData.isCurrentTag(2));
1557     assert(myData.isCurrentTag(3));
1558    
1559     assert(myData.getTagLookup().size()==3);
1560    
1561     assert(myData.getLength()==12);
1562    
1563     assert(myData.getPointOffset(0,0)==3);
1564    
1565     DataArrayView myDataView = myData.getDataPoint(0,0);
1566     assert(myDataView==eOne.getView());
1567     assert(!myDataView.isEmpty());
1568     assert(myDataView.getOffset()==3);
1569     assert(myDataView.getRank()==1);
1570     assert(myDataView.noValues()==3);
1571     assert(myDataView.getShape().size()==1);
1572     assert(myDataView(0)==1);
1573     assert(myDataView(1)==2);
1574     assert(myDataView(2)==3);
1575    
1576     myDataView = myData.getDataPointByTag(1);
1577     assert(myDataView==eOne.getView());
1578     assert(!myDataView.isEmpty());
1579     assert(myDataView.getOffset()==3);
1580     assert(myDataView.getRank()==1);
1581     assert(myDataView.noValues()==3);
1582     assert(myDataView.getShape().size()==1);
1583     assert(myDataView(0)==1);
1584     assert(myDataView(1)==2);
1585     assert(myDataView(2)==3);
1586    
1587     // Test non-existent tag returns the default value.
1588     myDataView = myData.getDataPointByTag(0);
1589     assert(myDataView==myView);
1590     assert(!myDataView.isEmpty());
1591     assert(myDataView.getOffset()==0);
1592     assert(myDataView.getRank()==1);
1593     assert(myDataView.noValues()==3);
1594     assert(myDataView.getShape().size()==1);
1595     assert(myDataView(0)==0);
1596     assert(myDataView(1)==1);
1597     assert(myDataView(2)==2);
1598    
1599     myDataView = myData.getDefaultValue();
1600     assert(myDataView==myView);
1601     assert(!myDataView.isEmpty());
1602     assert(myDataView.getOffset()==0);
1603     assert(myDataView.getRank()==1);
1604     assert(myDataView.noValues()==3);
1605     assert(myDataView.getShape().size()==1);
1606     assert(myDataView(0)==0);
1607     assert(myDataView(1)==1);
1608     assert(myDataView(2)==2);
1609    
1610     // Test data-points held for remaining tags
1611     myDataView = myData.getDataPointByTag(2);
1612     assert(myDataView==eTwo.getView());
1613     assert(!myDataView.isEmpty());
1614     assert(myDataView.getOffset()==6);
1615     assert(myDataView.getRank()==1);
1616     assert(myDataView.noValues()==3);
1617     assert(myDataView.getShape().size()==1);
1618     assert(myDataView(0)==2);
1619     assert(myDataView(1)==3);
1620     assert(myDataView(2)==4);
1621    
1622     myDataView = myData.getDataPointByTag(3);
1623     assert(myDataView==eThree.getView());
1624     assert(!myDataView.isEmpty());
1625     assert(myDataView.getOffset()==9);
1626     assert(myDataView.getRank()==1);
1627     assert(myDataView.noValues()==3);
1628     assert(myDataView.getShape().size()==1);
1629     assert(myDataView(0)==3);
1630     assert(myDataView(1)==4);
1631     assert(myDataView(2)==5);
1632    
1633 jgs 82 }
1634    
1635     }
1636    
1637 jgs 503 void DataTaggedTestCase::testCopyConstructors() {
1638    
1639     cout << endl;
1640    
1641     {
1642    
1643     cout << "\tTest DataTagged copy constructor for DataTagged with multiple tags." << endl;
1644    
1645     // the one data-point has tag value "1"
1646    
1647     DataTagged::TagListType keys;
1648     keys.push_back(1);
1649     keys.push_back(2);
1650     keys.push_back(3);
1651    
1652     DataTagged::ValueListType values;
1653    
1654     DataArrayView::ShapeType viewShape;
1655     viewShape.push_back(3);
1656    
1657     // default value
1658     DataArrayView::ValueType viewData(3);
1659     for (int i=0;i<viewShape[0];i++) {
1660     viewData[i]=i;
1661     }
1662     DataArrayView myView(viewData,viewShape);
1663    
1664     // value for tag "1"
1665     DataArray eOne(myView);
1666     for (int i=0;i<eOne.getView().getShape()[0];i++) {
1667     eOne.getView()(i)=i+1.0;
1668     }
1669     values.push_back(eOne.getView());
1670    
1671     // value for tag "2"
1672     DataArray eTwo(myView);
1673     for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1674     eTwo.getView()(i)=i+2.0;
1675     }
1676     values.push_back(eTwo.getView());
1677    
1678     // value for tag "3"
1679     DataArray eThree(myView);
1680     for (int i=0;i<eThree.getView().getShape()[0];i++) {
1681     eThree.getView()(i)=i+3.0;
1682     }
1683     values.push_back(eThree.getView());
1684    
1685     DataTagged myData(keys,values,myView,FunctionSpace());
1686    
1687     DataTagged myDataCopy(myData);
1688    
1689     //cout << myDataCopy.toString() << endl;
1690    
1691     assert(myDataCopy.getNumSamples()==1);
1692     assert(myDataCopy.getNumDPPSample()==1);
1693    
1694     assert(myDataCopy.validSamplePointNo(0));
1695     assert(myDataCopy.validSampleNo(0));
1696     assert(!myDataCopy.validSamplePointNo(1));
1697     assert(!myDataCopy.validSampleNo(1));
1698    
1699     // data-point 0 has tag number 1 by default
1700     assert(myDataCopy.getTagNumber(0)==1);
1701    
1702     assert(!myDataCopy.isCurrentTag(0));
1703     assert(myDataCopy.isCurrentTag(1));
1704     assert(myDataCopy.isCurrentTag(2));
1705     assert(myDataCopy.isCurrentTag(3));
1706    
1707     assert(myDataCopy.getTagLookup().size()==3);
1708    
1709     assert(myDataCopy.getLength()==12);
1710    
1711     assert(myDataCopy.getPointOffset(0,0)==3);
1712    
1713     DataArrayView myDataView = myDataCopy.getDataPoint(0,0);
1714     assert(myDataView==eOne.getView());
1715     assert(!myDataView.isEmpty());
1716     assert(myDataView.getOffset()==3);
1717     assert(myDataView.getRank()==1);
1718     assert(myDataView.noValues()==3);
1719     assert(myDataView.getShape().size()==1);
1720     assert(myDataView(0)==1);
1721     assert(myDataView(1)==2);
1722     assert(myDataView(2)==3);
1723    
1724     myDataView = myDataCopy.getDataPointByTag(1);
1725     assert(myDataView==eOne.getView());
1726     assert(!myDataView.isEmpty());
1727     assert(myDataView.getOffset()==3);
1728     assert(myDataView.getRank()==1);
1729     assert(myDataView.noValues()==3);
1730     assert(myDataView.getShape().size()==1);
1731     assert(myDataView(0)==1);
1732     assert(myDataView(1)==2);
1733     assert(myDataView(2)==3);
1734    
1735     // Test non-existent tag returns the default value.
1736     myDataView = myDataCopy.getDataPointByTag(0);
1737     assert(myDataView==myView);
1738     assert(!myDataView.isEmpty());
1739     assert(myDataView.getOffset()==0);
1740     assert(myDataView.getRank()==1);
1741     assert(myDataView.noValues()==3);
1742     assert(myDataView.getShape().size()==1);
1743     assert(myDataView(0)==0);
1744     assert(myDataView(1)==1);
1745     assert(myDataView(2)==2);
1746    
1747     myDataView = myDataCopy.getDefaultValue();
1748     assert(myDataView==myView);
1749     assert(!myDataView.isEmpty());
1750     assert(myDataView.getOffset()==0);
1751     assert(myDataView.getRank()==1);
1752     assert(myDataView.noValues()==3);
1753     assert(myDataView.getShape().size()==1);
1754     assert(myDataView(0)==0);
1755     assert(myDataView(1)==1);
1756     assert(myDataView(2)==2);
1757    
1758     // Test data-points held for remaining tags
1759     myDataView = myDataCopy.getDataPointByTag(2);
1760     assert(myDataView==eTwo.getView());
1761     assert(!myDataView.isEmpty());
1762     assert(myDataView.getOffset()==6);
1763     assert(myDataView.getRank()==1);
1764     assert(myDataView.noValues()==3);
1765     assert(myDataView.getShape().size()==1);
1766     assert(myDataView(0)==2);
1767     assert(myDataView(1)==3);
1768     assert(myDataView(2)==4);
1769    
1770     myDataView = myDataCopy.getDataPointByTag(3);
1771     assert(myDataView==eThree.getView());
1772     assert(!myDataView.isEmpty());
1773     assert(myDataView.getOffset()==9);
1774     assert(myDataView.getRank()==1);
1775     assert(myDataView.noValues()==3);
1776     assert(myDataView.getShape().size()==1);
1777     assert(myDataView(0)==3);
1778     assert(myDataView(1)==4);
1779     assert(myDataView(2)==5);
1780    
1781     }
1782    
1783     {
1784    
1785     cout << "\tTest DataTagged copy constructor for DataConstant." << endl;
1786    
1787     // Create a DataConstant
1788     DataArrayView::ShapeType shape;
1789     DataArrayView::ValueType data(DataArrayView::noValues(shape),0);
1790     DataArrayView pointData(data,shape);
1791     pointData()=1.0;
1792     DataConstant myConstantData(pointData, FunctionSpace());
1793    
1794     // use this DataConstant to initialise a DataTagged
1795     DataTagged myData(myConstantData);
1796    
1797     //cout << myData.toString() << endl;
1798    
1799     assert(myData.getNumSamples()==1);
1800     assert(myData.getNumDPPSample()==1);
1801    
1802     assert(myData.validSamplePointNo(0));
1803     assert(myData.validSampleNo(0));
1804     assert(!myData.validSamplePointNo(1));
1805     assert(!myData.validSampleNo(1));
1806    
1807     // data-point 0 has tag number 1 by default
1808     assert(myData.getTagNumber(0)==1);
1809    
1810     assert(!myData.isCurrentTag(1));
1811    
1812     assert(myData.getTagLookup().size()==0);
1813    
1814     assert(myData.getLength()==1);
1815    
1816     assert(myData.getPointOffset(0,0)==0);
1817    
1818     DataArrayView myDataView = myData.getDataPoint(0,0);
1819     assert(!myDataView.isEmpty());
1820     assert(myDataView.getOffset()==0);
1821     assert(myDataView.getRank()==0);
1822     assert(myDataView.noValues()==1);
1823     assert(myDataView.getShape().size()==0);
1824     assert(myDataView()==1.0);
1825    
1826     // Test non-existent tag returns the default value.
1827     myDataView = myData.getDataPointByTag(1);
1828     assert(!myDataView.isEmpty());
1829     assert(myDataView.getOffset()==0);
1830     assert(myDataView.getRank()==0);
1831     assert(myDataView.noValues()==1);
1832     assert(myDataView.getShape().size()==0);
1833     assert(myDataView()==1.0);
1834    
1835     myDataView = myData.getDefaultValue();
1836     assert(!myDataView.isEmpty());
1837     assert(myDataView.getOffset()==0);
1838     assert(myDataView.getRank()==0);
1839     assert(myDataView.noValues()==1);
1840     assert(myDataView.getShape().size()==0);
1841     assert(myDataView()==1.0);
1842    
1843     }
1844    
1845     }
1846    
1847 jgs 82 TestSuite* DataTaggedTestCase::suite ()
1848     {
1849     //
1850     // create the suite of tests to perform.
1851     TestSuite *testSuite = new TestSuite ("DataTaggedTestCase");
1852     testSuite->addTest (new TestCaller< DataTaggedTestCase>("testAll",&DataTaggedTestCase::testAll));
1853 jgs 501 testSuite->addTest (new TestCaller< DataTaggedTestCase>("testAddTaggedValues",&DataTaggedTestCase::testAddTaggedValues));
1854 jgs 502 testSuite->addTest (new TestCaller< DataTaggedTestCase>("testSetTaggedValue",&DataTaggedTestCase::testSetTaggedValue));
1855 jgs 503 testSuite->addTest (new TestCaller< DataTaggedTestCase>("testCopyConstructors",&DataTaggedTestCase::testCopyConstructors));
1856 jgs 497 // testSuite->addTest (new TestCaller< DataTaggedTestCase>("testOperations",&DataTaggedTestCase::testOperations));
1857     // testSuite->addTest (new TestCaller< DataTaggedTestCase>("testReshape",&DataTaggedTestCase::testReshape));
1858 jgs 82 return testSuite;
1859     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26