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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26