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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1325 - (hide annotations)
Mon Oct 1 06:28:24 2007 UTC (12 years, 1 month ago) by matt
File size: 152322 byte(s)
DataArray has been removed as it is no longer used. Unit tests have been
updated accordingly with substitute constructs. Any files pertaining to
DataArray have been removed.


1 jgs 548
2 ksteube 1312 /* $Id$ */
3 jgs 497
4 ksteube 1312 /*******************************************************
5     *
6     * Copyright 2003-2007 by ACceSS MNRF
7     * Copyright 2007 by University of Queensland
8     *
9     * http://esscc.uq.edu.au
10     * Primary Business: Queensland, Australia
11     * Licensed under the Open Software License version 3.0
12     * http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16 robwdcock 638 #include "esysUtils/EsysException.h"
17 jgs 497
18 matt 1325 #include "escript/DataVector.h"
19 robwdcock 670 #include "escript/DataTagged.h"
20     #include "escript/DataConstant.h"
21 jgs 497
22     #include "DataTaggedTestCase.h"
23    
24 robwdcock 670 #include "escript/BinaryOp.h"
25     #include "escript/UnaryOp.h"
26     #include "escript/FunctionSpaceFactory.h"
27     #include "escript/DataFactory.h"
28 jgs 82
29     #include <iostream>
30     #include <functional>
31     #include <algorithm>
32    
33     using namespace CppUnitTest;
34     using namespace escript;
35     using namespace esysUtils;
36     using namespace std;
37    
38     void DataTaggedTestCase::setUp() {
39     //
40     // This is called before each test is run
41 matt 1325
42 jgs 82 }
43    
44     void DataTaggedTestCase::tearDown() {
45     //
46     // This is called after each test has been run
47 matt 1325
48 jgs 82 }
49    
50    
51     void DataTaggedTestCase::testOperations() {
52    
53     cout << endl;
54    
55     {
56 jgs 506 cout << "\tTest binaryOp addition of two default DataTagged objects." << endl;
57    
58 jgs 504 DataTagged myData;
59 jgs 82 DataTagged right;
60 jgs 121
61 jgs 504 binaryOp(myData,right,plus<double>());
62    
63     //cout << myData.toString() << endl;
64    
65     assert(myData.getNumSamples()==1);
66     assert(myData.getNumDPPSample()==1);
67    
68     assert(myData.validSamplePointNo(0));
69     assert(myData.validSampleNo(0));
70     assert(!myData.validSamplePointNo(1));
71     assert(!myData.validSampleNo(1));
72    
73     // data-point 0 has tag number 1 by default
74     assert(myData.getTagNumber(0)==1);
75    
76     assert(!myData.isCurrentTag(1));
77    
78     assert(myData.getTagLookup().size()==0);
79    
80     assert(myData.getLength()==1);
81    
82     assert(myData.getPointOffset(0,0)==0);
83    
84     DataArrayView myDataView = myData.getDataPoint(0,0);
85     assert(!myDataView.isEmpty());
86     assert(myDataView.getOffset()==0);
87     assert(myDataView.getRank()==0);
88     assert(myDataView.noValues()==1);
89     assert(myDataView.getShape().size()==0);
90     assert(myDataView()==0.0);
91    
92     // Test non-existent tag returns the default value.
93     myDataView = myData.getDataPointByTag(1);
94     assert(!myDataView.isEmpty());
95     assert(myDataView.getOffset()==0);
96     assert(myDataView.getRank()==0);
97     assert(myDataView.noValues()==1);
98     assert(myDataView.getShape().size()==0);
99     assert(myDataView()==0.0);
100    
101     myDataView = myData.getDefaultValue();
102     assert(!myDataView.isEmpty());
103     assert(myDataView.getOffset()==0);
104     assert(myDataView.getRank()==0);
105     assert(myDataView.noValues()==1);
106     assert(myDataView.getShape().size()==0);
107     assert(myDataView()==0.0);
108 jgs 506
109     // use a non-existent tag so we get a pointer to
110     // the first element of the data array
111     double* sampleData=myData.getSampleDataByTag(9);
112     for (int i=0; i<myData.getLength(); i++) {
113     assert(sampleData[i]==i);
114     }
115    
116 jgs 504 }
117    
118     {
119 jgs 506 cout << "\tTest binaryOp addition of two DataTagged objects with default values only." << endl;
120    
121     DataArrayView::ShapeType viewShape;
122     viewShape.push_back(3);
123    
124     DataTagged::TagListType keys;
125    
126     DataTagged::ValueListType values;
127    
128     DataArrayView::ValueType viewData(3);
129     for (int i=0;i<viewShape[0];i++) {
130     viewData[i]=i;
131     }
132     DataArrayView myView(viewData,viewShape);
133    
134     DataTagged myData(keys,values,myView,FunctionSpace());
135     DataTagged right(keys,values,myView,FunctionSpace());
136    
137     binaryOp(myData,right,plus<double>());
138    
139     //cout << myData.toString() << endl;
140    
141     assert(myData.getNumSamples()==1);
142     assert(myData.getNumDPPSample()==1);
143    
144     assert(myData.validSamplePointNo(0));
145     assert(myData.validSampleNo(0));
146     assert(!myData.validSamplePointNo(1));
147     assert(!myData.validSampleNo(1));
148    
149     // data-point 0 has tag number 1 by default
150     assert(myData.getTagNumber(0)==1);
151    
152     assert(!myData.isCurrentTag(1));
153    
154     assert(myData.getTagLookup().size()==0);
155    
156     assert(myData.getLength()==3);
157    
158     assert(myData.getPointOffset(0,0)==0);
159    
160     DataArrayView myDataView = myData.getDefaultValue();
161     assert(!myDataView.isEmpty());
162     assert(myDataView.getOffset()==0);
163     assert(myDataView.getRank()==1);
164     assert(myDataView.noValues()==3);
165     assert(myDataView.getShape().size()==1);
166     assert(myDataView(0)==0);
167     assert(myDataView(1)==2);
168     assert(myDataView(2)==4);
169    
170     // use a non-existent tag so we get a pointer to
171     // the first element of the data array
172     double* sampleData=myData.getSampleDataByTag(9);
173     for (int i=0; i<myData.getLength(); i++) {
174     assert(sampleData[i]==i*2);
175     }
176    
177     }
178    
179     {
180     cout << "\tTest binaryOp addition of two DataTagged objects with one identical tag each." << endl;
181    
182 jgs 504 DataTagged myData;
183     DataTagged right;
184    
185 matt 1325 DataVector vOneData(1, 1.0 ,1);
186     // create a view with an empty shape, a scalar.
187     DataArrayView vOneView(vOneData,DataArrayView::ShapeType());
188 jgs 121
189 matt 1325 myData.addTaggedValue(1,vOneView);
190     right.addTaggedValue(1,vOneView);
191    
192 jgs 504 binaryOp(myData,right,plus<double>());
193    
194 jgs 506 assert(myData.getNumSamples()==1);
195     assert(myData.getNumDPPSample()==1);
196    
197     assert(myData.validSamplePointNo(0));
198     assert(myData.validSampleNo(0));
199     assert(!myData.validSamplePointNo(1));
200     assert(!myData.validSampleNo(1));
201    
202     // data-point 0 has tag number 1 by default
203     assert(myData.getTagNumber(0)==1);
204    
205     assert(myData.isCurrentTag(1));
206    
207     assert(myData.getTagLookup().size()==1);
208    
209     assert(myData.getLength()==2);
210    
211     assert(myData.getPointOffset(0,0)==1);
212    
213 jgs 504 // check result value for tag "1"
214     DataArrayView myDataView = myData.getDataPointByTag(1);
215     assert(!myDataView.isEmpty());
216     assert(myDataView.getOffset()==1);
217     assert(myDataView.getRank()==0);
218     assert(myDataView.noValues()==1);
219     assert(myDataView.getShape().size()==0);
220     assert(myDataView()==2.0);
221    
222     // check result for default value
223     myDataView = myData.getDefaultValue();
224     assert(!myDataView.isEmpty());
225     assert(myDataView.getOffset()==0);
226     assert(myDataView.getRank()==0);
227     assert(myDataView.noValues()==1);
228     assert(myDataView.getShape().size()==0);
229     assert(myDataView()==0.0);
230 jgs 506
231     // use a non-existent tag so we get a pointer to
232     // the first element of the data array
233     double* sampleData=myData.getSampleDataByTag(9);
234     for (int i=0; i<myData.getLength(); i++) {
235     assert(sampleData[i]==i*2);
236     }
237    
238 jgs 82 }
239 jgs 501
240 jgs 82 {
241 jgs 506 cout << "\tTest binaryOp addition of two DataTagged objects with one different tag each." << endl;
242    
243 jgs 504 DataTagged myData;
244     DataTagged right;
245    
246 jgs 548 // it's important that default values are different, as we need to be able to
247     // verify that the tag values in each object are being added to the correct
248     // default values - since the tag lists don't match, the default values will
249     // be used for missing tags in each object
250     myData.getDefaultValue()()=1.0;
251     right.getDefaultValue()()=2.0;
252    
253 matt 1325 DataVector vOneData(1, 3.0 ,1);
254     // create a view with an empty shape, a scalar.
255     DataArrayView vOneView(vOneData,DataArrayView::ShapeType());
256 jgs 504
257 matt 1325 DataVector vTwoData(1, 4.0 ,1);
258     // create a view with an empty shape, a scalar.
259     DataArrayView vTwoView(vTwoData,DataArrayView::ShapeType());
260    
261     myData.addTaggedValue(1,vOneView);
262     right.addTaggedValue(2,vTwoView);
263    
264 jgs 548 //cout << myData.toString() << endl;
265     //cout << right.toString() << endl;
266    
267 jgs 504 binaryOp(myData,right,plus<double>());
268    
269 jgs 548 //cout << myData.toString() << endl;
270    
271 jgs 506 assert(myData.getNumSamples()==1);
272     assert(myData.getNumDPPSample()==1);
273    
274     assert(myData.validSamplePointNo(0));
275     assert(myData.validSampleNo(0));
276     assert(!myData.validSamplePointNo(1));
277     assert(!myData.validSampleNo(1));
278    
279     // data-point 0 has tag number 1 by default
280     assert(myData.getTagNumber(0)==1);
281    
282     assert(myData.isCurrentTag(1));
283     assert(myData.isCurrentTag(2));
284    
285     assert(myData.getTagLookup().size()==2);
286    
287     assert(myData.getLength()==3);
288    
289     assert(myData.getPointOffset(0,0)==1);
290    
291 jgs 504 // check result value for tag "1"
292     DataArrayView myDataView = myData.getDataPointByTag(1);
293     assert(!myDataView.isEmpty());
294     assert(myDataView.getOffset()==1);
295     assert(myDataView.getRank()==0);
296     assert(myDataView.noValues()==1);
297     assert(myDataView.getShape().size()==0);
298 jgs 548 assert(myDataView()==5.0);
299 jgs 504
300     // check result value for tag "2"
301     myDataView = myData.getDataPointByTag(2);
302     assert(!myDataView.isEmpty());
303     assert(myDataView.getOffset()==2);
304     assert(myDataView.getRank()==0);
305     assert(myDataView.noValues()==1);
306     assert(myDataView.getShape().size()==0);
307 jgs 548 assert(myDataView()==5.0);
308 jgs 504
309     // check result for default value
310     myDataView = myData.getDefaultValue();
311     assert(!myDataView.isEmpty());
312     assert(myDataView.getOffset()==0);
313     assert(myDataView.getRank()==0);
314     assert(myDataView.noValues()==1);
315     assert(myDataView.getShape().size()==0);
316 jgs 548 assert(myDataView()==3.0);
317 jgs 506
318     // use a non-existent tag so we get a pointer to
319     // the first element of the data array
320     double* sampleData=myData.getSampleDataByTag(9);
321 jgs 548 assert(sampleData[0]==3);
322     assert(sampleData[1]==5);
323     assert(sampleData[2]==5);
324 jgs 506
325 jgs 82 }
326 jgs 501
327 jgs 82 {
328 jgs 506 cout << "\tTest binaryOp addition of two DataTagged objects with overlapping tag sets." << endl;
329    
330 jgs 504 DataTagged myData;
331     DataTagged right;
332    
333 jgs 548 // it's important that default values are different, as we need to be able to
334     // verify that the tag values in each object are being added to the correct
335     // default values - since the tag lists don't match, the default values will
336     // be used for missing tags in each object
337     myData.getDefaultValue()()=2.0;
338     right.getDefaultValue()()=3.0;
339    
340 matt 1325 DataVector vOneData(1, 1.0 ,1);
341     // create a view with an empty shape, a scalar.
342     DataArrayView vOneView(vOneData,DataArrayView::ShapeType());
343 jgs 504
344 matt 1325 myData.addTaggedValue(1,vOneView);
345     myData.addTaggedValue(2,vOneView);
346     right.addTaggedValue(2,vOneView);
347     right.addTaggedValue(3,vOneView);
348    
349 jgs 548 //cout << myData.toString() << endl;
350     //cout << right.toString() << endl;
351    
352 jgs 504 binaryOp(myData,right,plus<double>());
353    
354 jgs 548 //cout << myData.toString() << endl;
355    
356 jgs 506 assert(myData.getNumSamples()==1);
357     assert(myData.getNumDPPSample()==1);
358    
359     assert(myData.validSamplePointNo(0));
360     assert(myData.validSampleNo(0));
361     assert(!myData.validSamplePointNo(1));
362     assert(!myData.validSampleNo(1));
363    
364     // data-point 0 has tag number 1 by default
365     assert(myData.getTagNumber(0)==1);
366    
367     assert(myData.isCurrentTag(1));
368     assert(myData.isCurrentTag(2));
369     assert(myData.isCurrentTag(3));
370    
371     assert(myData.getTagLookup().size()==3);
372    
373     assert(myData.getLength()==4);
374    
375     assert(myData.getPointOffset(0,0)==1);
376    
377 jgs 504 // check result value for tag "1"
378     DataArrayView myDataView = myData.getDataPointByTag(1);
379     assert(!myDataView.isEmpty());
380     assert(myDataView.getOffset()==1);
381     assert(myDataView.getRank()==0);
382     assert(myDataView.noValues()==1);
383     assert(myDataView.getShape().size()==0);
384 jgs 548 assert(myDataView()==4.0);
385 jgs 504
386     // check result value for tag "2"
387     myDataView = myData.getDataPointByTag(2);
388     assert(!myDataView.isEmpty());
389     assert(myDataView.getOffset()==2);
390     assert(myDataView.getRank()==0);
391     assert(myDataView.noValues()==1);
392     assert(myDataView.getShape().size()==0);
393     assert(myDataView()==2.0);
394    
395     // check result value for tag "3"
396     myDataView = myData.getDataPointByTag(3);
397     assert(!myDataView.isEmpty());
398     assert(myDataView.getOffset()==3);
399     assert(myDataView.getRank()==0);
400     assert(myDataView.noValues()==1);
401     assert(myDataView.getShape().size()==0);
402 jgs 548 assert(myDataView()==3.0);
403 jgs 504
404     // check result for default value
405     myDataView = myData.getDefaultValue();
406     assert(!myDataView.isEmpty());
407     assert(myDataView.getOffset()==0);
408     assert(myDataView.getRank()==0);
409     assert(myDataView.noValues()==1);
410     assert(myDataView.getShape().size()==0);
411 jgs 548 assert(myDataView()==5.0);
412 jgs 506
413     // use a non-existent tag so we get a pointer to
414     // the first element of the data array
415     double* sampleData=myData.getSampleDataByTag(9);
416 jgs 548 assert(sampleData[0]==5);
417     assert(sampleData[1]==4);
418     assert(sampleData[2]==2);
419     assert(sampleData[3]==3);
420 jgs 506
421 jgs 82 }
422 jgs 501
423 jgs 82 {
424 jgs 506 cout << "\tTest binaryOp multiplication of two DataTagged objects with default values only." << endl;
425 jgs 504
426 jgs 506 DataArrayView::ShapeType viewShape;
427     viewShape.push_back(3);
428    
429     DataTagged::TagListType keys;
430    
431     DataTagged::ValueListType values;
432    
433     DataArrayView::ValueType viewData(3);
434     for (int i=0;i<viewShape[0];i++) {
435     viewData[i]=i;
436     }
437     DataArrayView myView(viewData,viewShape);
438    
439     DataTagged myData(keys,values,myView,FunctionSpace());
440     DataTagged right(keys,values,myView,FunctionSpace());
441    
442     binaryOp(myData,right,multiplies<double>());
443    
444     //cout << myData.toString() << endl;
445    
446     assert(myData.getNumSamples()==1);
447     assert(myData.getNumDPPSample()==1);
448    
449     assert(myData.validSamplePointNo(0));
450     assert(myData.validSampleNo(0));
451     assert(!myData.validSamplePointNo(1));
452     assert(!myData.validSampleNo(1));
453    
454     // data-point 0 has tag number 1 by default
455     assert(myData.getTagNumber(0)==1);
456    
457     assert(!myData.isCurrentTag(1));
458    
459     assert(myData.getTagLookup().size()==0);
460    
461     assert(myData.getLength()==3);
462    
463     assert(myData.getPointOffset(0,0)==0);
464    
465     DataArrayView myDataView = myData.getDefaultValue();
466     assert(!myDataView.isEmpty());
467     assert(myDataView.getOffset()==0);
468     assert(myDataView.getRank()==1);
469     assert(myDataView.noValues()==3);
470     assert(myDataView.getShape().size()==1);
471     assert(myDataView(0)==0);
472     assert(myDataView(1)==1);
473     assert(myDataView(2)==4);
474    
475     // use a non-existent tag so we get a pointer to
476     // the first element of the data array
477     double* sampleData=myData.getSampleDataByTag(9);
478     for (int i=0; i<myData.getLength(); i++) {
479     assert(sampleData[i]==i*i);
480     }
481    
482 jgs 82 }
483 jgs 501
484 jgs 504 {
485 jgs 557
486     cout << "\tTest binaryOp multiplication of DataTagged object with a scalar." << endl;
487    
488     DataTagged myData;
489    
490 matt 1325 DataVector vOneData(1, 1.0 ,1);
491     // create a view with an empty shape, a scalar.
492     DataArrayView vOneView(vOneData,DataArrayView::ShapeType());
493 jgs 557
494 matt 1325 DataVector vTwoData(1, 2.0 ,1);
495     // create a view with an empty shape, a scalar.
496     DataArrayView vTwoView(vTwoData,DataArrayView::ShapeType());
497 jgs 557
498 matt 1325 myData.addTaggedValue(1,vOneView);
499     myData.addTaggedValue(2,vTwoView);
500    
501     DataVector vThreeData(1, 3.0 ,1);
502     // create a view with an empty shape, a scalar.
503     DataArrayView vThreeView(vThreeData,DataArrayView::ShapeType());
504    
505     DataArrayView right=vThreeView;
506    
507 jgs 557 //cout << myData.toString() << endl;
508     //cout << right.toString() << endl;
509    
510     binaryOp(myData,right,multiplies<double>());
511    
512     //cout << myData.toString() << endl;
513    
514     assert(myData.getNumSamples()==1);
515     assert(myData.getNumDPPSample()==1);
516    
517     assert(myData.validSamplePointNo(0));
518     assert(myData.validSampleNo(0));
519     assert(!myData.validSamplePointNo(1));
520     assert(!myData.validSampleNo(1));
521    
522     // data-point 0 has tag number 1 by default
523     assert(myData.getTagNumber(0)==1);
524    
525     assert(myData.isCurrentTag(1));
526     assert(myData.isCurrentTag(2));
527    
528     assert(myData.getTagLookup().size()==2);
529    
530     assert(myData.getLength()==3);
531    
532     assert(myData.getPointOffset(0,0)==1);
533    
534     // check result value for tag "1"
535     DataArrayView myDataView = myData.getDataPointByTag(1);
536     assert(!myDataView.isEmpty());
537     assert(myDataView.getOffset()==1);
538     assert(myDataView.getRank()==0);
539     assert(myDataView.noValues()==1);
540     assert(myDataView.getShape().size()==0);
541     assert(myDataView()==3.0);
542    
543     // check result value for tag "2"
544     myDataView = myData.getDataPointByTag(2);
545     assert(!myDataView.isEmpty());
546     assert(myDataView.getOffset()==2);
547     assert(myDataView.getRank()==0);
548     assert(myDataView.noValues()==1);
549     assert(myDataView.getShape().size()==0);
550     assert(myDataView()==6.0);
551    
552     // check result for default value
553     myDataView = myData.getDefaultValue();
554     assert(!myDataView.isEmpty());
555     assert(myDataView.getOffset()==0);
556     assert(myDataView.getRank()==0);
557     assert(myDataView.noValues()==1);
558     assert(myDataView.getShape().size()==0);
559     assert(myDataView()==0.0);
560    
561     // use a non-existent tag so we get a pointer to
562     // the first element of the data array
563     double* sampleData=myData.getSampleDataByTag(9);
564     assert(sampleData[0]==0);
565     assert(sampleData[1]==3);
566     assert(sampleData[2]==6);
567    
568     }
569    
570     {
571 jgs 506 cout << "\tTest binaryOp multiplication of two DataTagged objects with overlapping tag sets." << endl;
572    
573     DataTagged myData;
574     DataTagged right;
575    
576 jgs 548 // it's important that default values are different, as we need to be able to
577     // verify that the tag values in each object are being added to the correct
578     // default values - since the tag lists don't match, the default values will
579     // be used for missing tags in each object
580     myData.getDefaultValue()()=2.0;
581     right.getDefaultValue()()=3.0;
582    
583 matt 1325 DataVector vOneData(1, 1.0 ,1);
584     // create a view with an empty shape, a scalar.
585     DataArrayView vOneView(vOneData,DataArrayView::ShapeType());
586 jgs 506
587 matt 1325 DataVector vTwoData(1, 2.0 ,1);
588     // create a view with an empty shape, a scalar.
589     DataArrayView vTwoView(vTwoData,DataArrayView::ShapeType());
590    
591     myData.addTaggedValue(1,vOneView);
592     myData.addTaggedValue(2,vOneView);
593     right.addTaggedValue(2,vTwoView);
594     right.addTaggedValue(3,vTwoView);
595    
596 jgs 548 //cout << myData.toString() << endl;
597     //cout << right.toString() << endl;
598    
599 jgs 506 binaryOp(myData,right,multiplies<double>());
600    
601 jgs 548 //cout << myData.toString() << endl;
602    
603 jgs 506 assert(myData.getNumSamples()==1);
604     assert(myData.getNumDPPSample()==1);
605    
606     assert(myData.validSamplePointNo(0));
607     assert(myData.validSampleNo(0));
608     assert(!myData.validSamplePointNo(1));
609     assert(!myData.validSampleNo(1));
610    
611     // data-point 0 has tag number 1 by default
612     assert(myData.getTagNumber(0)==1);
613    
614     assert(myData.isCurrentTag(1));
615     assert(myData.isCurrentTag(2));
616     assert(myData.isCurrentTag(3));
617    
618     assert(myData.getTagLookup().size()==3);
619    
620     assert(myData.getLength()==4);
621    
622     assert(myData.getPointOffset(0,0)==1);
623    
624     // check result value for tag "1"
625     DataArrayView myDataView = myData.getDataPointByTag(1);
626     assert(!myDataView.isEmpty());
627     assert(myDataView.getOffset()==1);
628     assert(myDataView.getRank()==0);
629     assert(myDataView.noValues()==1);
630     assert(myDataView.getShape().size()==0);
631 jgs 548 assert(myDataView()==3.0);
632 jgs 506
633     // check result value for tag "2"
634     myDataView = myData.getDataPointByTag(2);
635     assert(!myDataView.isEmpty());
636     assert(myDataView.getOffset()==2);
637     assert(myDataView.getRank()==0);
638     assert(myDataView.noValues()==1);
639     assert(myDataView.getShape().size()==0);
640     assert(myDataView()==2.0);
641    
642     // check result value for tag "3"
643     myDataView = myData.getDataPointByTag(3);
644     assert(!myDataView.isEmpty());
645     assert(myDataView.getOffset()==3);
646     assert(myDataView.getRank()==0);
647     assert(myDataView.noValues()==1);
648     assert(myDataView.getShape().size()==0);
649 jgs 548 assert(myDataView()==4.0);
650 jgs 506
651     // check result for default value
652     myDataView = myData.getDefaultValue();
653     assert(!myDataView.isEmpty());
654     assert(myDataView.getOffset()==0);
655     assert(myDataView.getRank()==0);
656     assert(myDataView.noValues()==1);
657     assert(myDataView.getShape().size()==0);
658 jgs 548 assert(myDataView()==6.0);
659 jgs 506
660     // use a non-existent tag so we get a pointer to
661     // the first element of the data array
662     double* sampleData=myData.getSampleDataByTag(9);
663 jgs 548 assert(sampleData[0]==6);
664     assert(sampleData[1]==3);
665     assert(sampleData[2]==2);
666     assert(sampleData[3]==4);
667 jgs 506
668 jgs 504 }
669    
670     {
671 jgs 506 cout << "\tTest unaryOp negate on default DataTagged object." << endl;
672    
673     DataTagged myData;
674    
675     unaryOp(myData,negate<double>());
676    
677     //cout << myData.toString() << endl;
678    
679     assert(myData.getNumSamples()==1);
680     assert(myData.getNumDPPSample()==1);
681    
682     assert(myData.validSamplePointNo(0));
683     assert(myData.validSampleNo(0));
684     assert(!myData.validSamplePointNo(1));
685     assert(!myData.validSampleNo(1));
686    
687     // data-point 0 has tag number 1 by default
688     assert(myData.getTagNumber(0)==1);
689    
690     assert(!myData.isCurrentTag(1));
691    
692     assert(myData.getTagLookup().size()==0);
693    
694     assert(myData.getLength()==1);
695    
696     assert(myData.getPointOffset(0,0)==0);
697    
698     DataArrayView myDataView = myData.getDataPoint(0,0);
699     assert(!myDataView.isEmpty());
700     assert(myDataView.getOffset()==0);
701     assert(myDataView.getRank()==0);
702     assert(myDataView.noValues()==1);
703     assert(myDataView.getShape().size()==0);
704     assert(myDataView()==0.0);
705    
706     // Test non-existent tag returns the default value.
707     myDataView = myData.getDataPointByTag(1);
708     assert(!myDataView.isEmpty());
709     assert(myDataView.getOffset()==0);
710     assert(myDataView.getRank()==0);
711     assert(myDataView.noValues()==1);
712     assert(myDataView.getShape().size()==0);
713     assert(myDataView()==0.0);
714    
715     myDataView = myData.getDefaultValue();
716     assert(!myDataView.isEmpty());
717     assert(myDataView.getOffset()==0);
718     assert(myDataView.getRank()==0);
719     assert(myDataView.noValues()==1);
720     assert(myDataView.getShape().size()==0);
721     assert(myDataView()==0.0);
722    
723     // use a non-existent tag so we get a pointer to
724     // the first element of the data array
725     double* sampleData=myData.getSampleDataByTag(9);
726     for (int i=0; i<myData.getLength(); i++) {
727     assert(sampleData[i]==i);
728     }
729    
730 jgs 504 }
731    
732     {
733 jgs 506 cout << "\tTest unaryOp negate on DataTagged object with default value only." << endl;
734    
735     DataArrayView::ShapeType viewShape;
736     viewShape.push_back(3);
737    
738     DataTagged::TagListType keys;
739    
740     DataTagged::ValueListType values;
741    
742     DataArrayView::ValueType viewData(3);
743     for (int i=0;i<viewShape[0];i++) {
744     viewData[i]=i;
745     }
746     DataArrayView myView(viewData,viewShape);
747    
748     DataTagged myData(keys,values,myView,FunctionSpace());
749    
750     unaryOp(myData,negate<double>());
751    
752     //cout << myData.toString() << endl;
753    
754     assert(myData.getNumSamples()==1);
755     assert(myData.getNumDPPSample()==1);
756    
757     assert(myData.validSamplePointNo(0));
758     assert(myData.validSampleNo(0));
759     assert(!myData.validSamplePointNo(1));
760     assert(!myData.validSampleNo(1));
761    
762     // data-point 0 has tag number 1 by default
763     assert(myData.getTagNumber(0)==1);
764    
765     assert(!myData.isCurrentTag(1));
766    
767     assert(myData.getTagLookup().size()==0);
768    
769     assert(myData.getLength()==3);
770    
771     assert(myData.getPointOffset(0,0)==0);
772    
773     DataArrayView myDataView = myData.getDefaultValue();
774     assert(!myDataView.isEmpty());
775     assert(myDataView.getOffset()==0);
776     assert(myDataView.getRank()==1);
777     assert(myDataView.noValues()==3);
778     assert(myDataView.getShape().size()==1);
779     assert(myDataView(0)==0);
780     assert(myDataView(1)==-1);
781     assert(myDataView(2)==-2);
782    
783     // use a non-existent tag so we get a pointer to
784     // the first element of the data array
785     double* sampleData=myData.getSampleDataByTag(9);
786     for (int i=0; i<myData.getLength(); i++) {
787     assert(sampleData[i]==0-i);
788     }
789    
790 jgs 504 }
791    
792 jgs 506 {
793 matt 1325 cout << "\tTest unnaryOp negate on DataTagged object with two tags." << endl;
794 jgs 506
795     DataTagged myData;
796    
797 matt 1325 DataVector vOneData(1, 1.0 ,1);
798     // create a view with an empty shape, a scalar.
799     DataArrayView vOneView(vOneData,DataArrayView::ShapeType());
800 jgs 506
801 matt 1325 DataVector vTwoData(1, 2.0 ,1);
802     // create a view with an empty shape, a scalar.
803     DataArrayView vTwoView(vTwoData,DataArrayView::ShapeType());
804    
805     myData.addTaggedValue(1,vOneView);
806     myData.addTaggedValue(2,vTwoView);
807    
808 jgs 506 unaryOp(myData,negate<double>());
809    
810     assert(myData.getNumSamples()==1);
811     assert(myData.getNumDPPSample()==1);
812    
813     assert(myData.validSamplePointNo(0));
814     assert(myData.validSampleNo(0));
815     assert(!myData.validSamplePointNo(1));
816     assert(!myData.validSampleNo(1));
817    
818     // data-point 0 has tag number 1 by default
819     assert(myData.getTagNumber(0)==1);
820    
821     assert(myData.isCurrentTag(1));
822     assert(myData.isCurrentTag(2));
823    
824     assert(myData.getTagLookup().size()==2);
825    
826     assert(myData.getLength()==3);
827    
828     assert(myData.getPointOffset(0,0)==1);
829    
830     // check result value for tag "1"
831     DataArrayView myDataView = myData.getDataPointByTag(1);
832     assert(!myDataView.isEmpty());
833     assert(myDataView.getOffset()==1);
834     assert(myDataView.getRank()==0);
835     assert(myDataView.noValues()==1);
836     assert(myDataView.getShape().size()==0);
837     assert(myDataView()==-1.0);
838    
839     // check result value for tag "2"
840     myDataView = myData.getDataPointByTag(2);
841     assert(!myDataView.isEmpty());
842     assert(myDataView.getOffset()==2);
843     assert(myDataView.getRank()==0);
844     assert(myDataView.noValues()==1);
845     assert(myDataView.getShape().size()==0);
846     assert(myDataView()==-2.0);
847    
848     // check result for default value
849     myDataView = myData.getDefaultValue();
850     assert(!myDataView.isEmpty());
851     assert(myDataView.getOffset()==0);
852     assert(myDataView.getRank()==0);
853     assert(myDataView.noValues()==1);
854     assert(myDataView.getShape().size()==0);
855     assert(myDataView()==0.0);
856    
857     // use a non-existent tag so we get a pointer to
858     // the first element of the data array
859     double* sampleData=myData.getSampleDataByTag(9);
860     for (int i=0; i<myData.getLength(); i++) {
861     assert(sampleData[i]==0-i);
862     }
863    
864     }
865    
866 jgs 82 }
867    
868 jgs 501 void DataTaggedTestCase::testAddTaggedValues() {
869    
870     cout << endl;
871    
872     {
873    
874     cout << "\tTest adding one key with empty value list to default DataTagged." << endl;
875     DataTagged myData;
876    
877     DataTagged::TagListType keys;
878     keys.push_back(1);
879    
880     DataTagged::ValueListType values;
881    
882     myData.addTaggedValues(keys,values);
883    
884     assert(myData.isCurrentTag(1));
885    
886     assert(myData.getTagLookup().size()==1);
887    
888     assert(myData.getLength()==2);
889    
890     // data-point 0 has tag number 1 by default
891     assert(myData.getTagNumber(0)==1);
892    
893     assert(myData.getPointOffset(0,0)==1);
894    
895     DataArrayView myDataView = myData.getDataPoint(0,0);
896     assert(!myDataView.isEmpty());
897     assert(myDataView.getOffset()==1);
898     assert(myDataView.getRank()==0);
899     assert(myDataView.noValues()==1);
900     assert(myDataView.getShape().size()==0);
901     assert(myDataView()==0.0);
902    
903     myDataView = myData.getDataPointByTag(1);
904     assert(!myDataView.isEmpty());
905     assert(myDataView.getOffset()==1);
906     assert(myDataView.getRank()==0);
907     assert(myDataView.noValues()==1);
908     assert(myDataView.getShape().size()==0);
909     assert(myDataView()==0.0);
910    
911     myDataView = myData.getDefaultValue();
912     assert(!myDataView.isEmpty());
913     assert(myDataView.getOffset()==0);
914     assert(myDataView.getRank()==0);
915     assert(myDataView.noValues()==1);
916     assert(myDataView.getShape().size()==0);
917     assert(myDataView()==0.0);
918    
919 jgs 506 // use a non-existent tag so we get a pointer to
920     // the first element of the data array
921     double* sampleData=myData.getSampleDataByTag(9);
922     for (int i=0; i<myData.getLength(); i++) {
923     assert(sampleData[i]==0);
924     }
925    
926 jgs 501 }
927    
928     {
929    
930     cout << "\tTest adding one key with one value to default DataTagged." << endl;
931     DataTagged myData;
932    
933     DataTagged::TagListType keys;
934     keys.push_back(1);
935    
936     DataTagged::ValueListType values;
937    
938     DataArrayView::ShapeType viewShape;
939     DataArrayView::ValueType viewData(1);
940     viewData[0]=1.0;
941     DataArrayView myView(viewData,viewShape);
942     values.push_back(myView);
943    
944     myData.addTaggedValues(keys,values);
945    
946     assert(myData.isCurrentTag(1));
947    
948     assert(myData.getTagLookup().size()==1);
949    
950     assert(myData.getLength()==2);
951    
952     // data-point 0 has tag number 1 by default
953     assert(myData.getTagNumber(0)==1);
954    
955     assert(myData.getPointOffset(0,0)==1);
956    
957     DataArrayView myDataView = myData.getDataPoint(0,0);
958     assert(!myDataView.isEmpty());
959     assert(myDataView.getOffset()==1);
960     assert(myDataView.getRank()==0);
961     assert(myDataView.noValues()==1);
962     assert(myDataView.getShape().size()==0);
963     assert(myDataView()==1.0);
964    
965     myDataView = myData.getDataPointByTag(1);
966     assert(!myDataView.isEmpty());
967     assert(myDataView.getOffset()==1);
968     assert(myDataView.getRank()==0);
969     assert(myDataView.noValues()==1);
970     assert(myDataView.getShape().size()==0);
971     assert(myDataView()==1.0);
972    
973     myDataView = myData.getDefaultValue();
974     assert(!myDataView.isEmpty());
975     assert(myDataView.getOffset()==0);
976     assert(myDataView.getRank()==0);
977     assert(myDataView.noValues()==1);
978     assert(myDataView.getShape().size()==0);
979     assert(myDataView()==0.0);
980    
981 jgs 506 // use a non-existent tag so we get a pointer to
982     // the first element of the data array
983     double* sampleData=myData.getSampleDataByTag(9);
984     for (int i=0; i<myData.getLength(); i++) {
985     assert(sampleData[i]==i);
986     }
987    
988 jgs 501 }
989    
990     {
991    
992     cout << "\tTest adding three keys with one value to default DataTagged." << endl;
993     DataTagged myData;
994    
995     DataTagged::TagListType keys;
996     keys.push_back(1);
997     keys.push_back(2);
998     keys.push_back(3);
999    
1000     DataTagged::ValueListType values;
1001    
1002     DataArrayView::ShapeType viewShape;
1003     DataArrayView::ValueType viewData(1);
1004     viewData[0]=1.0;
1005     DataArrayView myView(viewData,viewShape);
1006     values.push_back(myView);
1007    
1008     myData.addTaggedValues(keys,values);
1009    
1010     assert(myData.isCurrentTag(1));
1011     assert(myData.isCurrentTag(2));
1012     assert(myData.isCurrentTag(3));
1013    
1014     assert(myData.getTagLookup().size()==3);
1015    
1016     assert(myData.getLength()==4);
1017    
1018     // data-point 0 has tag number 1 by default
1019     assert(myData.getTagNumber(0)==1);
1020    
1021     assert(myData.getPointOffset(0,0)==1);
1022    
1023     DataArrayView myDataView = myData.getDataPoint(0,0);
1024     assert(!myDataView.isEmpty());
1025     assert(myDataView.getOffset()==1);
1026     assert(myDataView.getRank()==0);
1027     assert(myDataView.noValues()==1);
1028     assert(myDataView.getShape().size()==0);
1029     assert(myDataView()==1.0);
1030    
1031     myDataView = myData.getDataPointByTag(1);
1032     assert(!myDataView.isEmpty());
1033     assert(myDataView.getOffset()==1);
1034     assert(myDataView.getRank()==0);
1035     assert(myDataView.noValues()==1);
1036     assert(myDataView.getShape().size()==0);
1037     assert(myDataView()==1.0);
1038    
1039     myDataView = myData.getDataPointByTag(2);
1040     assert(!myDataView.isEmpty());
1041     assert(myDataView.getOffset()==2);
1042     assert(myDataView.getRank()==0);
1043     assert(myDataView.noValues()==1);
1044     assert(myDataView.getShape().size()==0);
1045     assert(myDataView()==1.0);
1046    
1047     myDataView = myData.getDataPointByTag(3);
1048     assert(!myDataView.isEmpty());
1049     assert(myDataView.getOffset()==3);
1050     assert(myDataView.getRank()==0);
1051     assert(myDataView.noValues()==1);
1052     assert(myDataView.getShape().size()==0);
1053     assert(myDataView()==1.0);
1054    
1055     myDataView = myData.getDefaultValue();
1056     assert(!myDataView.isEmpty());
1057     assert(myDataView.getOffset()==0);
1058     assert(myDataView.getRank()==0);
1059     assert(myDataView.noValues()==1);
1060     assert(myDataView.getShape().size()==0);
1061     assert(myDataView()==0.0);
1062    
1063 jgs 506 // use a non-existent tag so we get a pointer to
1064     // the first element of the data array
1065     double* sampleData=myData.getSampleDataByTag(9);
1066     for (int i=0; i<myData.getLength(); i++) {
1067     if (i==0) {
1068     assert(sampleData[i]==0);
1069     } else {
1070     assert(sampleData[i]==1);
1071     }
1072     }
1073    
1074 jgs 501 }
1075    
1076     {
1077    
1078     cout << "\tTest adding three keys with three values to default DataTagged." << endl;
1079     DataTagged myData;
1080    
1081     DataTagged::TagListType keys;
1082     keys.push_back(1);
1083     keys.push_back(2);
1084     keys.push_back(3);
1085    
1086     DataTagged::ValueListType values;
1087    
1088     DataArrayView::ShapeType viewShape;
1089     DataArrayView::ValueType viewData1(1);
1090     viewData1[0]=1.0;
1091     DataArrayView::ValueType viewData2(1);
1092     viewData2[0]=2.0;
1093     DataArrayView::ValueType viewData3(1);
1094     viewData3[0]=3.0;
1095     DataArrayView myView1(viewData1,viewShape);
1096     DataArrayView myView2(viewData2,viewShape);
1097     DataArrayView myView3(viewData3,viewShape);
1098     values.push_back(myView1);
1099     values.push_back(myView2);
1100     values.push_back(myView3);
1101    
1102     myData.addTaggedValues(keys,values);
1103    
1104     assert(myData.isCurrentTag(1));
1105     assert(myData.isCurrentTag(2));
1106     assert(myData.isCurrentTag(3));
1107    
1108     assert(myData.getTagLookup().size()==3);
1109    
1110     assert(myData.getLength()==4);
1111    
1112     // data-point 0 has tag number 1 by default
1113     assert(myData.getTagNumber(0)==1);
1114    
1115     assert(myData.getPointOffset(0,0)==1);
1116    
1117     DataArrayView myDataView = myData.getDataPoint(0,0);
1118     assert(!myDataView.isEmpty());
1119     assert(myDataView.getOffset()==1);
1120     assert(myDataView.getRank()==0);
1121     assert(myDataView.noValues()==1);
1122     assert(myDataView.getShape().size()==0);
1123     assert(myDataView()==1.0);
1124    
1125     myDataView = myData.getDataPointByTag(1);
1126     assert(!myDataView.isEmpty());
1127     assert(myDataView.getOffset()==1);
1128     assert(myDataView.getRank()==0);
1129     assert(myDataView.noValues()==1);
1130     assert(myDataView.getShape().size()==0);
1131     assert(myDataView()==1.0);
1132    
1133     myDataView = myData.getDataPointByTag(2);
1134     assert(!myDataView.isEmpty());
1135     assert(myDataView.getOffset()==2);
1136     assert(myDataView.getRank()==0);
1137     assert(myDataView.noValues()==1);
1138     assert(myDataView.getShape().size()==0);
1139     assert(myDataView()==2.0);
1140    
1141     myDataView = myData.getDataPointByTag(3);
1142     assert(!myDataView.isEmpty());
1143     assert(myDataView.getOffset()==3);
1144     assert(myDataView.getRank()==0);
1145     assert(myDataView.noValues()==1);
1146     assert(myDataView.getShape().size()==0);
1147     assert(myDataView()==3.0);
1148    
1149     myDataView = myData.getDefaultValue();
1150     assert(!myDataView.isEmpty());
1151     assert(myDataView.getOffset()==0);
1152     assert(myDataView.getRank()==0);
1153     assert(myDataView.noValues()==1);
1154     assert(myDataView.getShape().size()==0);
1155     assert(myDataView()==0.0);
1156    
1157 jgs 506 // use a non-existent tag so we get a pointer to
1158     // the first element of the data array
1159     double* sampleData=myData.getSampleDataByTag(9);
1160     for (int i=0; i<myData.getLength(); i++) {
1161     assert(sampleData[i]==i);
1162     }
1163    
1164 jgs 501 }
1165    
1166     {
1167    
1168     cout << "\tTest adding one key with empty value list to DataTagged with default value only." << endl;
1169    
1170     DataArrayView::ShapeType viewShape;
1171     viewShape.push_back(3);
1172    
1173     DataTagged::TagListType keys;
1174    
1175     DataTagged::ValueListType values;
1176    
1177     DataArrayView::ValueType viewData(3);
1178     for (int i=0;i<viewShape[0];i++) {
1179     viewData[i]=i;
1180     }
1181     DataArrayView myView(viewData,viewShape);
1182    
1183     DataTagged myData(keys,values,myView,FunctionSpace());
1184    
1185     keys.push_back(1);
1186     values.clear();
1187    
1188     myData.addTaggedValues(keys,values);
1189    
1190     assert(myData.isCurrentTag(1));
1191    
1192     assert(myData.getTagLookup().size()==1);
1193    
1194     assert(myData.getLength()==6);
1195    
1196     // data-point 0 has tag number 1 by default
1197     assert(myData.getTagNumber(0)==1);
1198    
1199     assert(myData.getPointOffset(0,0)==3);
1200    
1201     DataArrayView myDataView = myData.getDataPoint(0,0);
1202     assert(myDataView==myView);
1203     assert(!myDataView.isEmpty());
1204     assert(myDataView.getOffset()==3);
1205     assert(myDataView.getRank()==1);
1206     assert(myDataView.noValues()==3);
1207     assert(myDataView.getShape().size()==1);
1208     assert(myDataView(0)==0);
1209     assert(myDataView(1)==1);
1210     assert(myDataView(2)==2);
1211    
1212     myDataView = myData.getDataPointByTag(1);
1213     assert(myDataView==myView);
1214     assert(!myDataView.isEmpty());
1215     assert(myDataView.getOffset()==3);
1216     assert(myDataView.getRank()==1);
1217     assert(myDataView.noValues()==3);
1218     assert(myDataView.getShape().size()==1);
1219     assert(myDataView(0)==0);
1220     assert(myDataView(1)==1);
1221     assert(myDataView(2)==2);
1222    
1223     myDataView = myData.getDefaultValue();
1224     assert(myDataView==myView);
1225     assert(!myDataView.isEmpty());
1226     assert(myDataView.getOffset()==0);
1227     assert(myDataView.getRank()==1);
1228     assert(myDataView.noValues()==3);
1229     assert(myDataView.getShape().size()==1);
1230     assert(myDataView(0)==0);
1231     assert(myDataView(1)==1);
1232     assert(myDataView(2)==2);
1233    
1234 jgs 506 // use a non-existent tag so we get a pointer to
1235     // the first element of the data array
1236     double* sampleData=myData.getSampleDataByTag(9);
1237     for (int i=0; i<myData.getLength(); i++) {
1238     assert(sampleData[i]==i%3);
1239     }
1240    
1241 jgs 501 }
1242    
1243     {
1244    
1245     cout << "\tTest adding one key with one value to 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     keys.push_back(1);
1263    
1264     DataArrayView::ValueType viewData1(3);
1265     for (int i=0;i<viewShape[0];i++) {
1266 jgs 506 viewData1[i]=i+3;
1267 jgs 501 }
1268     DataArrayView myView1(viewData1,viewShape);
1269     values.push_back(myView1);
1270    
1271     myData.addTaggedValues(keys,values);
1272    
1273     assert(myData.isCurrentTag(1));
1274    
1275     assert(myData.getTagLookup().size()==1);
1276    
1277     assert(myData.getLength()==6);
1278    
1279     // data-point 0 has tag number 1 by default
1280     assert(myData.getTagNumber(0)==1);
1281    
1282     assert(myData.getPointOffset(0,0)==3);
1283    
1284     DataArrayView myDataView = myData.getDataPoint(0,0);
1285     assert(myDataView==myView1);
1286     assert(!myDataView.isEmpty());
1287     assert(myDataView.getOffset()==3);
1288     assert(myDataView.getRank()==1);
1289     assert(myDataView.noValues()==3);
1290     assert(myDataView.getShape().size()==1);
1291 jgs 506 assert(myDataView(0)==3);
1292     assert(myDataView(1)==4);
1293     assert(myDataView(2)==5);
1294 jgs 501
1295     myDataView = myData.getDataPointByTag(1);
1296     assert(myDataView==myView1);
1297     assert(!myDataView.isEmpty());
1298     assert(myDataView.getOffset()==3);
1299     assert(myDataView.getRank()==1);
1300     assert(myDataView.noValues()==3);
1301     assert(myDataView.getShape().size()==1);
1302 jgs 506 assert(myDataView(0)==3);
1303     assert(myDataView(1)==4);
1304     assert(myDataView(2)==5);
1305 jgs 501
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 506 // use a non-existent tag so we get a pointer to
1318     // the first element of the data array
1319     double* sampleData=myData.getSampleDataByTag(9);
1320     for (int i=0; i<myData.getLength(); i++) {
1321     assert(sampleData[i]==i);
1322     }
1323    
1324 jgs 501 }
1325    
1326     {
1327    
1328     cout << "\tTest adding three keys with one value to DataTagged with default value only." << endl;
1329    
1330     DataArrayView::ShapeType viewShape;
1331     viewShape.push_back(3);
1332    
1333     DataTagged::TagListType keys;
1334    
1335     DataTagged::ValueListType values;
1336    
1337     DataArrayView::ValueType viewData(3);
1338     for (int i=0;i<viewShape[0];i++) {
1339     viewData[i]=i;
1340     }
1341     DataArrayView myView(viewData,viewShape);
1342    
1343     DataTagged myData(keys,values,myView,FunctionSpace());
1344    
1345     keys.push_back(1);
1346     keys.push_back(2);
1347     keys.push_back(3);
1348    
1349     DataArrayView::ValueType viewData1(3);
1350     for (int i=0;i<viewShape[0];i++) {
1351 jgs 506 viewData1[i]=3;
1352 jgs 501 }
1353     DataArrayView myView1(viewData1,viewShape);
1354     values.push_back(myView1);
1355    
1356     myData.addTaggedValues(keys,values);
1357    
1358     assert(myData.isCurrentTag(1));
1359     assert(myData.isCurrentTag(2));
1360     assert(myData.isCurrentTag(3));
1361    
1362     assert(myData.getTagLookup().size()==3);
1363    
1364     assert(myData.getLength()==12);
1365    
1366     // data-point 0 has tag number 1 by default
1367     assert(myData.getTagNumber(0)==1);
1368    
1369     assert(myData.getPointOffset(0,0)==3);
1370    
1371     DataArrayView myDataView = myData.getDataPoint(0,0);
1372     assert(myDataView==myView1);
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 jgs 506 assert(myDataView(0)==3);
1379     assert(myDataView(1)==3);
1380 jgs 501 assert(myDataView(2)==3);
1381    
1382     myDataView = myData.getDataPointByTag(1);
1383     assert(myDataView==myView1);
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 jgs 506 assert(myDataView(0)==3);
1390     assert(myDataView(1)==3);
1391 jgs 501 assert(myDataView(2)==3);
1392    
1393     myDataView = myData.getDataPointByTag(2);
1394     assert(myDataView==myView1);
1395     assert(!myDataView.isEmpty());
1396     assert(myDataView.getOffset()==6);
1397     assert(myDataView.getRank()==1);
1398     assert(myDataView.noValues()==3);
1399     assert(myDataView.getShape().size()==1);
1400 jgs 506 assert(myDataView(0)==3);
1401     assert(myDataView(1)==3);
1402 jgs 501 assert(myDataView(2)==3);
1403    
1404     myDataView = myData.getDataPointByTag(3);
1405     assert(myDataView==myView1);
1406     assert(!myDataView.isEmpty());
1407     assert(myDataView.getOffset()==9);
1408     assert(myDataView.getRank()==1);
1409     assert(myDataView.noValues()==3);
1410     assert(myDataView.getShape().size()==1);
1411 jgs 506 assert(myDataView(0)==3);
1412     assert(myDataView(1)==3);
1413 jgs 501 assert(myDataView(2)==3);
1414    
1415     myDataView = myData.getDefaultValue();
1416     assert(myDataView==myView);
1417     assert(!myDataView.isEmpty());
1418     assert(myDataView.getOffset()==0);
1419     assert(myDataView.getRank()==1);
1420     assert(myDataView.noValues()==3);
1421     assert(myDataView.getShape().size()==1);
1422     assert(myDataView(0)==0);
1423     assert(myDataView(1)==1);
1424     assert(myDataView(2)==2);
1425    
1426 jgs 506 // use a non-existent tag so we get a pointer to
1427     // the first element of the data array
1428     double* sampleData=myData.getSampleDataByTag(9);
1429     for (int i=0; i<myData.getLength(); i++) {
1430     if (i<3) {
1431     assert(sampleData[i]==i);
1432     } else {
1433     assert(sampleData[i]==3);
1434     }
1435     }
1436    
1437 jgs 501 }
1438    
1439     {
1440    
1441     cout << "\tTest adding three keys with three values to DataTagged with default value only." << endl;
1442    
1443     DataArrayView::ShapeType viewShape;
1444     viewShape.push_back(3);
1445    
1446     DataTagged::TagListType keys;
1447    
1448     DataTagged::ValueListType values;
1449    
1450     DataArrayView::ValueType viewData(3);
1451     for (int i=0;i<viewShape[0];i++) {
1452     viewData[i]=i;
1453     }
1454     DataArrayView myView(viewData,viewShape);
1455    
1456     DataTagged myData(keys,values,myView,FunctionSpace());
1457    
1458     keys.push_back(1);
1459     keys.push_back(2);
1460     keys.push_back(3);
1461    
1462     DataArrayView::ValueType viewData1(3);
1463     for (int i=0;i<viewShape[0];i++) {
1464     viewData1[i]=i+1;
1465     }
1466     DataArrayView myView1(viewData1,viewShape);
1467     values.push_back(myView1);
1468    
1469     DataArrayView::ValueType viewData2(3);
1470     for (int i=0;i<viewShape[0];i++) {
1471     viewData2[i]=i+2;
1472     }
1473     DataArrayView myView2(viewData2,viewShape);
1474     values.push_back(myView2);
1475    
1476     DataArrayView::ValueType viewData3(3);
1477     for (int i=0;i<viewShape[0];i++) {
1478     viewData3[i]=i+3;
1479     }
1480     DataArrayView myView3(viewData3,viewShape);
1481     values.push_back(myView3);
1482    
1483     myData.addTaggedValues(keys,values);
1484    
1485     assert(myData.isCurrentTag(1));
1486     assert(myData.isCurrentTag(2));
1487     assert(myData.isCurrentTag(3));
1488    
1489     assert(myData.getTagLookup().size()==3);
1490    
1491     assert(myData.getLength()==12);
1492    
1493     // data-point 0 has tag number 1 by default
1494     assert(myData.getTagNumber(0)==1);
1495    
1496     assert(myData.getPointOffset(0,0)==3);
1497    
1498     DataArrayView myDataView = myData.getDataPoint(0,0);
1499     assert(myDataView==myView1);
1500     assert(!myDataView.isEmpty());
1501     assert(myDataView.getOffset()==3);
1502     assert(myDataView.getRank()==1);
1503     assert(myDataView.noValues()==3);
1504     assert(myDataView.getShape().size()==1);
1505     assert(myDataView(0)==1);
1506     assert(myDataView(1)==2);
1507     assert(myDataView(2)==3);
1508    
1509     myDataView = myData.getDataPointByTag(1);
1510     assert(myDataView==myView1);
1511     assert(!myDataView.isEmpty());
1512     assert(myDataView.getOffset()==3);
1513     assert(myDataView.getRank()==1);
1514     assert(myDataView.noValues()==3);
1515     assert(myDataView.getShape().size()==1);
1516     assert(myDataView(0)==1);
1517     assert(myDataView(1)==2);
1518     assert(myDataView(2)==3);
1519    
1520     myDataView = myData.getDataPointByTag(2);
1521     assert(myDataView==myView2);
1522     assert(!myDataView.isEmpty());
1523     assert(myDataView.getOffset()==6);
1524     assert(myDataView.getRank()==1);
1525     assert(myDataView.noValues()==3);
1526     assert(myDataView.getShape().size()==1);
1527     assert(myDataView(0)==2);
1528     assert(myDataView(1)==3);
1529     assert(myDataView(2)==4);
1530    
1531     myDataView = myData.getDataPointByTag(3);
1532     assert(myDataView==myView3);
1533     assert(!myDataView.isEmpty());
1534     assert(myDataView.getOffset()==9);
1535     assert(myDataView.getRank()==1);
1536     assert(myDataView.noValues()==3);
1537     assert(myDataView.getShape().size()==1);
1538     assert(myDataView(0)==3);
1539     assert(myDataView(1)==4);
1540     assert(myDataView(2)==5);
1541    
1542     myDataView = myData.getDefaultValue();
1543     assert(myDataView==myView);
1544     assert(!myDataView.isEmpty());
1545     assert(myDataView.getOffset()==0);
1546     assert(myDataView.getRank()==1);
1547     assert(myDataView.noValues()==3);
1548     assert(myDataView.getShape().size()==1);
1549     assert(myDataView(0)==0);
1550     assert(myDataView(1)==1);
1551     assert(myDataView(2)==2);
1552    
1553 jgs 506 // use a non-existent tag so we get a pointer to
1554     // the first element of the data array
1555     double* sampleData=myData.getSampleDataByTag(9);
1556     for (int i=0; i<myData.getLength(); i++) {
1557     if (i<3) {
1558     assert(sampleData[i]==i);
1559 jgs 508 } else if ((i>=3) && (i<6)) {
1560 jgs 506 assert(sampleData[i]==i-2);
1561 jgs 508 } else if ((i>=6) && (i<9)) {
1562 jgs 506 assert(sampleData[i]==i-4);
1563 jgs 508 } else {
1564 jgs 506 assert(sampleData[i]==i-6);
1565     }
1566     }
1567    
1568 jgs 501 }
1569    
1570     {
1571    
1572     cout << "\tTest adding one key with empty value list to DataTagged with three tags." << endl;
1573    
1574     DataTagged::TagListType keys;
1575     keys.push_back(1);
1576     keys.push_back(2);
1577     keys.push_back(3);
1578    
1579     DataTagged::ValueListType values;
1580    
1581     DataArrayView::ShapeType viewShape;
1582     viewShape.push_back(3);
1583    
1584     // default value
1585     DataArrayView::ValueType viewData(3);
1586     for (int i=0;i<viewShape[0];i++) {
1587     viewData[i]=i;
1588     }
1589     DataArrayView myView(viewData,viewShape);
1590    
1591     // value for tag "1"
1592 matt 1325 DataArrayView::ValueType eOneData(viewData);
1593     DataArrayView eOneView(eOneData, viewShape);
1594     for (int i=0;i<eOneView.getShape()[0];i++) {
1595     eOneView(i)=i+1.0;
1596 jgs 501 }
1597 matt 1325 values.push_back(eOneView);
1598 jgs 501
1599     // value for tag "2"
1600 matt 1325 DataArrayView::ValueType eTwoData(viewData);
1601     DataArrayView eTwoView(eTwoData, viewShape);
1602     for (int i=0;i<eTwoView.getShape()[0];i++) {
1603     eTwoView(i)=i+2.0;
1604 jgs 501 }
1605 matt 1325 values.push_back(eTwoView);
1606 jgs 501
1607     // value for tag "3"
1608 matt 1325 DataArrayView::ValueType eThreeData(viewData);
1609     DataArrayView eThreeView(eThreeData, viewShape);
1610     for (int i=0;i<eThreeView.getShape()[0];i++) {
1611     eThreeView(i)=i+3.0;
1612 jgs 501 }
1613 matt 1325 values.push_back(eThreeView);
1614 jgs 501
1615     DataTagged myData(keys,values,myView,FunctionSpace());
1616    
1617     keys.clear();
1618     keys.push_back(4);
1619     values.clear();
1620    
1621     myData.addTaggedValues(keys,values);
1622    
1623     assert(myData.isCurrentTag(4));
1624    
1625     assert(myData.getTagLookup().size()==4);
1626    
1627     assert(myData.getLength()==15);
1628    
1629     DataArrayView myDataView = myData.getDataPointByTag(4);
1630     assert(myDataView==myView);
1631     assert(!myDataView.isEmpty());
1632     assert(myDataView.getOffset()==12);
1633     assert(myDataView.getRank()==1);
1634     assert(myDataView.noValues()==3);
1635     assert(myDataView.getShape().size()==1);
1636     assert(myDataView(0)==0);
1637     assert(myDataView(1)==1);
1638     assert(myDataView(2)==2);
1639    
1640 jgs 506 // use a non-existent tag so we get a pointer to
1641     // the first element of the data array
1642     double* sampleData=myData.getSampleDataByTag(9);
1643     for (int i=0; i<myData.getLength(); i++) {
1644     if (i<3) {
1645     assert(sampleData[i]==i);
1646 jgs 508 } else if ((i>=3) && (i<6)) {
1647 jgs 506 assert(sampleData[i]==i-2);
1648 jgs 508 } else if ((i>=6) && (i<9)) {
1649 jgs 506 assert(sampleData[i]==i-4);
1650 jgs 508 } else if ((i>=9) && (i<12)) {
1651 jgs 506 assert(sampleData[i]==i-6);
1652 jgs 508 } else {
1653 jgs 506 assert(sampleData[i]==i-12);
1654     }
1655     }
1656    
1657 jgs 501 }
1658    
1659     {
1660    
1661     cout << "\tTest adding one key with one value to DataTagged with three tags." << endl;
1662    
1663     DataTagged::TagListType keys;
1664     keys.push_back(1);
1665     keys.push_back(2);
1666     keys.push_back(3);
1667    
1668     DataTagged::ValueListType values;
1669    
1670     DataArrayView::ShapeType viewShape;
1671     viewShape.push_back(3);
1672    
1673     // default value
1674     DataArrayView::ValueType viewData(3);
1675     for (int i=0;i<viewShape[0];i++) {
1676     viewData[i]=i;
1677     }
1678     DataArrayView myView(viewData,viewShape);
1679    
1680     // value for tag "1"
1681 matt 1325 DataArrayView::ValueType eOneData(viewData);
1682     DataArrayView eOneView(eOneData, viewShape);
1683     for (int i=0;i<eOneView.getShape()[0];i++) {
1684     eOneView(i)=i+1.0;
1685 jgs 501 }
1686 matt 1325 values.push_back(eOneView);
1687 jgs 501
1688     // value for tag "2"
1689 matt 1325 DataArrayView::ValueType eTwoData(viewData);
1690     DataArrayView eTwoView(eTwoData, viewShape);
1691     for (int i=0;i<eTwoView.getShape()[0];i++) {
1692     eTwoView(i)=i+2.0;
1693 jgs 501 }
1694 matt 1325 values.push_back(eTwoView);
1695 jgs 501
1696     // value for tag "3"
1697 matt 1325 DataArrayView::ValueType eThreeData(viewData);
1698     DataArrayView eThreeView(eThreeData, viewShape);
1699     for (int i=0;i<eThreeView.getShape()[0];i++) {
1700     eThreeView(i)=i+3.0;
1701 jgs 501 }
1702 matt 1325 values.push_back(eThreeView);
1703 jgs 501
1704     DataTagged myData(keys,values,myView,FunctionSpace());
1705    
1706     keys.clear();
1707     keys.push_back(4);
1708    
1709     values.clear();
1710     // value for tag "4"
1711 matt 1325 DataArrayView::ValueType eFourData(viewData);
1712     DataArrayView eFourView(eFourData, viewShape);
1713     for (int i=0;i<eFourView.getShape()[0];i++) {
1714     eFourView(i)=i+4.0;
1715 jgs 501 }
1716 matt 1325 values.push_back(eFourView);
1717 jgs 501
1718     myData.addTaggedValues(keys,values);
1719    
1720     assert(myData.isCurrentTag(4));
1721    
1722     assert(myData.getTagLookup().size()==4);
1723    
1724     assert(myData.getLength()==15);
1725    
1726     DataArrayView myDataView = myData.getDataPointByTag(4);
1727 matt 1325 assert(myDataView==eFourView);
1728 jgs 501 assert(!myDataView.isEmpty());
1729     assert(myDataView.getOffset()==12);
1730     assert(myDataView.getRank()==1);
1731     assert(myDataView.noValues()==3);
1732     assert(myDataView.getShape().size()==1);
1733     assert(myDataView(0)==4);
1734     assert(myDataView(1)==5);
1735     assert(myDataView(2)==6);
1736    
1737 jgs 506 // use a non-existent tag so we get a pointer to
1738     // the first element of the data array
1739     double* sampleData=myData.getSampleDataByTag(9);
1740     for (int i=0; i<myData.getLength(); i++) {
1741     if (i<3) {
1742     assert(sampleData[i]==i);
1743 jgs 508 } else if ((i>=3) && (i<6)) {
1744 jgs 506 assert(sampleData[i]==i-2);
1745 jgs 508 } else if ((i>=6) && (i<9)) {
1746 jgs 506 assert(sampleData[i]==i-4);
1747 jgs 508 } else if ((i>=9) && (i<12)) {
1748 jgs 506 assert(sampleData[i]==i-6);
1749 jgs 508 } else {
1750 jgs 506 assert(sampleData[i]==i-8);
1751     }
1752     }
1753    
1754 jgs 501 }
1755    
1756     {
1757    
1758     cout << "\tTest adding three keys with one value to DataTagged with three tags." << endl;
1759    
1760     DataTagged::TagListType keys;
1761     keys.push_back(1);
1762     keys.push_back(2);
1763     keys.push_back(3);
1764    
1765     DataTagged::ValueListType values;
1766    
1767     DataArrayView::ShapeType viewShape;
1768     viewShape.push_back(3);
1769    
1770     // default value
1771     DataArrayView::ValueType viewData(3);
1772     for (int i=0;i<viewShape[0];i++) {
1773     viewData[i]=i;
1774     }
1775     DataArrayView myView(viewData,viewShape);
1776    
1777     // value for tag "1"
1778 matt 1325 DataArrayView::ValueType eOneData(viewData);
1779     DataArrayView eOneView(eOneData, viewShape);
1780     for (int i=0;i<eOneView.getShape()[0];i++) {
1781     eOneView(i)=i+1.0;
1782 jgs 501 }
1783 matt 1325 values.push_back(eOneView);
1784 jgs 501
1785     // value for tag "2"
1786 matt 1325 DataArrayView::ValueType eTwoData(viewData);
1787     DataArrayView eTwoView(eTwoData, viewShape);
1788     for (int i=0;i<eTwoView.getShape()[0];i++) {
1789     eTwoView(i)=i+2.0;
1790 jgs 501 }
1791 matt 1325 values.push_back(eTwoView);
1792 jgs 501
1793     // value for tag "3"
1794 matt 1325 DataArrayView::ValueType eThreeData(viewData);
1795     DataArrayView eThreeView(eThreeData, viewShape);
1796     for (int i=0;i<eThreeView.getShape()[0];i++) {
1797     eThreeView(i)=i+3.0;
1798 jgs 501 }
1799 matt 1325 values.push_back(eThreeView);
1800 jgs 501
1801     DataTagged myData(keys,values,myView,FunctionSpace());
1802    
1803     keys.clear();
1804     keys.push_back(4);
1805     keys.push_back(5);
1806     keys.push_back(6);
1807    
1808     values.clear();
1809     // value for tags "4", "5" and "6"
1810 matt 1325 DataArrayView::ValueType eFourData(viewData);
1811     DataArrayView eFourView(eFourData, viewShape);
1812     for (int i=0;i<eFourView.getShape()[0];i++) {
1813     eFourView(i)=i+4.0;
1814 jgs 501 }
1815 matt 1325 values.push_back(eFourView);
1816 jgs 501
1817     myData.addTaggedValues(keys,values);
1818    
1819     assert(myData.isCurrentTag(4));
1820     assert(myData.isCurrentTag(5));
1821     assert(myData.isCurrentTag(6));
1822    
1823     assert(myData.getTagLookup().size()==6);
1824    
1825     assert(myData.getLength()==21);
1826    
1827     DataArrayView myDataView = myData.getDataPointByTag(4);
1828 matt 1325 assert(myDataView==eFourView);
1829 jgs 501 assert(!myDataView.isEmpty());
1830     assert(myDataView.getOffset()==12);
1831     assert(myDataView.getRank()==1);
1832     assert(myDataView.noValues()==3);
1833     assert(myDataView.getShape().size()==1);
1834     assert(myDataView(0)==4);
1835     assert(myDataView(1)==5);
1836     assert(myDataView(2)==6);
1837    
1838     myDataView = myData.getDataPointByTag(5);
1839 matt 1325 assert(myDataView==eFourView);
1840 jgs 501 assert(!myDataView.isEmpty());
1841     assert(myDataView.getOffset()==15);
1842     assert(myDataView.getRank()==1);
1843     assert(myDataView.noValues()==3);
1844     assert(myDataView.getShape().size()==1);
1845     assert(myDataView(0)==4);
1846     assert(myDataView(1)==5);
1847     assert(myDataView(2)==6);
1848    
1849     myDataView = myData.getDataPointByTag(6);
1850 matt 1325 assert(myDataView==eFourView);
1851 jgs 501 assert(!myDataView.isEmpty());
1852     assert(myDataView.getOffset()==18);
1853     assert(myDataView.getRank()==1);
1854     assert(myDataView.noValues()==3);
1855     assert(myDataView.getShape().size()==1);
1856     assert(myDataView(0)==4);
1857     assert(myDataView(1)==5);
1858     assert(myDataView(2)==6);
1859    
1860 jgs 506 // use a non-existent tag so we get a pointer to
1861     // the first element of the data array
1862     double* sampleData=myData.getSampleDataByTag(9);
1863     for (int i=0; i<myData.getLength(); i++) {
1864     if (i<3) {
1865     assert(sampleData[i]==i);
1866 jgs 508 } else if ((i>=3) && (i<6)) {
1867 jgs 506 assert(sampleData[i]==i-2);
1868 jgs 508 } else if ((i>=6) && (i<9)) {
1869 jgs 506 assert(sampleData[i]==i-4);
1870 jgs 508 } else if ((i>=9) && (i<12)) {
1871 jgs 506 assert(sampleData[i]==i-6);
1872 jgs 508 } else if ((i>=12) && (i<15)) {
1873 jgs 506 assert(sampleData[i]==i-8);
1874 jgs 508 } else if ((i>=15) && (i<18)) {
1875 jgs 506 assert(sampleData[i]==i-11);
1876 jgs 508 } else {
1877 jgs 506 assert(sampleData[i]==i-14);
1878     }
1879     }
1880    
1881 jgs 501 }
1882    
1883     {
1884    
1885     cout << "\tTest adding three keys with three values to DataTagged with three tags." << endl;
1886    
1887     DataTagged::TagListType keys;
1888     keys.push_back(1);
1889     keys.push_back(2);
1890     keys.push_back(3);
1891    
1892     DataTagged::ValueListType values;
1893    
1894     DataArrayView::ShapeType viewShape;
1895     viewShape.push_back(3);
1896    
1897     // default value
1898     DataArrayView::ValueType viewData(3);
1899     for (int i=0;i<viewShape[0];i++) {
1900     viewData[i]=i;
1901     }
1902     DataArrayView myView(viewData,viewShape);
1903    
1904     // value for tag "1"
1905 matt 1325 DataArrayView::ValueType eOneData(viewData);
1906     DataArrayView eOneView(eOneData, viewShape);
1907     for (int i=0;i<eOneView.getShape()[0];i++) {
1908     eOneView(i)=i+1.0;
1909 jgs 501 }
1910 matt 1325 values.push_back(eOneView);
1911 jgs 501
1912     // value for tag "2"
1913 matt 1325 DataArrayView::ValueType eTwoData(viewData);
1914     DataArrayView eTwoView(eTwoData, viewShape);
1915     for (int i=0;i<eTwoView.getShape()[0];i++) {
1916     eTwoView(i)=i+2.0;
1917 jgs 501 }
1918 matt 1325 values.push_back(eTwoView);
1919 jgs 501
1920     // value for tag "3"
1921 matt 1325 DataArrayView::ValueType eThreeData(viewData);
1922     DataArrayView eThreeView(eThreeData, viewShape);
1923     for (int i=0;i<eThreeView.getShape()[0];i++) {
1924     eThreeView(i)=i+3.0;
1925 jgs 501 }
1926 matt 1325 values.push_back(eThreeView);
1927 jgs 501
1928     DataTagged myData(keys,values,myView,FunctionSpace());
1929    
1930     keys.clear();
1931     keys.push_back(4);
1932     keys.push_back(5);
1933     keys.push_back(6);
1934    
1935     values.clear();
1936    
1937     // value for tag "4"
1938 matt 1325 DataArrayView::ValueType eFourData(viewData);
1939     DataArrayView eFourView(eFourData, viewShape);
1940     for (int i=0;i<eFourView.getShape()[0];i++) {
1941     eFourView(i)=i+4.0;
1942 jgs 501 }
1943 matt 1325 values.push_back(eFourView);
1944 jgs 501
1945     // value for tag "5"
1946 matt 1325 DataArrayView::ValueType eFiveData(viewData);
1947     DataArrayView eFiveView(eFiveData, viewShape);
1948     for (int i=0;i<eFiveView.getShape()[0];i++) {
1949     eFiveView(i)=i+5.0;
1950 jgs 501 }
1951 matt 1325 values.push_back(eFiveView);
1952 jgs 501
1953     // value for tag "6"
1954 matt 1325 DataArrayView::ValueType eSixData(viewData);
1955     DataArrayView eSixView(eSixData, viewShape);
1956     for (int i=0;i<eSixView.getShape()[0];i++) {
1957     eSixView(i)=i+6.0;
1958 jgs 501 }
1959 matt 1325 values.push_back(eSixView);
1960 jgs 501
1961     myData.addTaggedValues(keys,values);
1962    
1963     assert(myData.isCurrentTag(4));
1964     assert(myData.isCurrentTag(5));
1965     assert(myData.isCurrentTag(6));
1966    
1967     assert(myData.getTagLookup().size()==6);
1968    
1969     assert(myData.getLength()==21);
1970    
1971     DataArrayView myDataView = myData.getDataPointByTag(4);
1972 matt 1325 assert(myDataView==eFourView);
1973 jgs 501 assert(!myDataView.isEmpty());
1974     assert(myDataView.getOffset()==12);
1975     assert(myDataView.getRank()==1);
1976     assert(myDataView.noValues()==3);
1977     assert(myDataView.getShape().size()==1);
1978     assert(myDataView(0)==4);
1979     assert(myDataView(1)==5);
1980     assert(myDataView(2)==6);
1981    
1982     myDataView = myData.getDataPointByTag(5);
1983 matt 1325 assert(myDataView==eFiveView);
1984 jgs 501 assert(!myDataView.isEmpty());
1985     assert(myDataView.getOffset()==15);
1986     assert(myDataView.getRank()==1);
1987     assert(myDataView.noValues()==3);
1988     assert(myDataView.getShape().size()==1);
1989     assert(myDataView(0)==5);
1990     assert(myDataView(1)==6);
1991     assert(myDataView(2)==7);
1992    
1993     myDataView = myData.getDataPointByTag(6);
1994 matt 1325 assert(myDataView==eSixView);
1995 jgs 501 assert(!myDataView.isEmpty());
1996     assert(myDataView.getOffset()==18);
1997     assert(myDataView.getRank()==1);
1998     assert(myDataView.noValues()==3);
1999     assert(myDataView.getShape().size()==1);
2000     assert(myDataView(0)==6);
2001     assert(myDataView(1)==7);
2002     assert(myDataView(2)==8);
2003    
2004 jgs 506 // use a non-existent tag so we get a pointer to
2005     // the first element of the data array
2006     double* sampleData=myData.getSampleDataByTag(9);
2007     for (int i=0; i<myData.getLength(); i++) {
2008     if (i<3) {
2009     assert(sampleData[i]==i);
2010 jgs 508 } else if ((i>=3) && (i<6)) {
2011 jgs 506 assert(sampleData[i]==i-2);
2012 jgs 508 } else if ((i>=6) && (i<9)) {
2013 jgs 506 assert(sampleData[i]==i-4);
2014 jgs 508 } else if ((i>=9) && (i<12)) {
2015 jgs 506 assert(sampleData[i]==i-6);
2016 jgs 508 } else if ((i>=12) && (i<15)) {
2017 jgs 506 assert(sampleData[i]==i-8);
2018 jgs 508 } else if ((i>=15) && (i<18)) {
2019 jgs 506 assert(sampleData[i]==i-10);
2020 jgs 508 } else {
2021 jgs 506 assert(sampleData[i]==i-12);
2022     }
2023     }
2024    
2025 jgs 501 }
2026    
2027     }
2028    
2029 jgs 502 void DataTaggedTestCase::testSetTaggedValue() {
2030    
2031     cout << endl;
2032    
2033     {
2034    
2035     cout << "\tTest setting key in DataTagged with three tags." << endl;
2036    
2037     DataTagged::TagListType keys;
2038     keys.push_back(1);
2039     keys.push_back(2);
2040     keys.push_back(3);
2041    
2042     DataTagged::ValueListType values;
2043    
2044     DataArrayView::ShapeType viewShape;
2045     viewShape.push_back(3);
2046    
2047     // default value
2048     DataArrayView::ValueType viewData(3);
2049     for (int i=0;i<viewShape[0];i++) {
2050     viewData[i]=i;
2051     }
2052     DataArrayView myView(viewData,viewShape);
2053    
2054     // value for tag "1"
2055 matt 1325 DataArrayView::ValueType eOneData(viewData);
2056     DataArrayView eOneView(eOneData, viewShape);
2057     for (int i=0;i<eOneView.getShape()[0];i++) {
2058     eOneView(i)=i+1.0;
2059 jgs 502 }
2060 matt 1325 values.push_back(eOneView);
2061 jgs 502
2062     // value for tag "2"
2063 matt 1325 DataArrayView::ValueType eTwoData(viewData);
2064     DataArrayView eTwoView(eTwoData, viewShape);
2065     for (int i=0;i<eTwoView.getShape()[0];i++) {
2066     eTwoView(i)=i+2.0;
2067 jgs 502 }
2068 matt 1325 values.push_back(eTwoView);
2069 jgs 502
2070     // value for tag "3"
2071 matt 1325 DataArrayView::ValueType eThreeData(viewData);
2072     DataArrayView eThreeView(eThreeData, viewShape);
2073     for (int i=0;i<eThreeView.getShape()[0];i++) {
2074     eThreeView(i)=i+3.0;
2075 jgs 502 }
2076 matt 1325 values.push_back(eThreeView);
2077 jgs 502
2078     DataTagged myData(keys,values,myView,FunctionSpace());
2079    
2080     // new value for tag "2"
2081 matt 1325 for (int i=0;i<eTwoView.getShape()[0];i++) {
2082     eTwoView(i)=i+5.0;
2083 jgs 502 }
2084    
2085 matt 1325 myData.setTaggedValue(2,eTwoView);
2086 jgs 502
2087     assert(myData.isCurrentTag(2));
2088    
2089     assert(myData.getTagLookup().size()==3);
2090    
2091     assert(myData.getLength()==12);
2092    
2093     DataArrayView myDataView = myData.getDataPointByTag(2);
2094 matt 1325 assert(myDataView==eTwoView);
2095 jgs 502 assert(!myDataView.isEmpty());
2096     assert(myDataView.getOffset()==6);
2097     assert(myDataView.getRank()==1);
2098     assert(myDataView.noValues()==3);
2099     assert(myDataView.getShape().size()==1);
2100     assert(myDataView(0)==5);
2101     assert(myDataView(1)==6);
2102     assert(myDataView(2)==7);
2103    
2104 jgs 506 // use a non-existent tag so we get a pointer to
2105     // the first element of the data array
2106     double* sampleData=myData.getSampleDataByTag(9);
2107     for (int i=0; i<myData.getLength(); i++) {
2108     if (i<3) {
2109     assert(sampleData[i]==i);
2110 jgs 508 } else if ((i>=3) && (i<6)) {
2111 jgs 506 assert(sampleData[i]==i-2);
2112 jgs 508 } else if ((i>=6) && (i<9)) {
2113 jgs 506 assert(sampleData[i]==i-1);
2114 jgs 508 } else {
2115 jgs 506 assert(sampleData[i]==i-6);
2116     }
2117     }
2118    
2119 jgs 502 }
2120    
2121     }
2122    
2123 jgs 82 void DataTaggedTestCase::testAll() {
2124 jgs 121
2125 jgs 82 cout << endl;
2126 jgs 121
2127 jgs 82 {
2128 jgs 497
2129     cout << "\tTest default DataTagged." << endl;
2130 jgs 82 DataTagged myData;
2131 jgs 497
2132 jgs 499 //cout << myData.toString() << endl;
2133    
2134 jgs 497 assert(myData.getNumSamples()==1);
2135 jgs 82 assert(myData.getNumDPPSample()==1);
2136 jgs 497
2137     assert(myData.validSamplePointNo(0));
2138     assert(myData.validSampleNo(0));
2139     assert(!myData.validSamplePointNo(1));
2140     assert(!myData.validSampleNo(1));
2141    
2142 jgs 501 // data-point 0 has tag number 1 by default
2143 jgs 497 assert(myData.getTagNumber(0)==1);
2144    
2145     assert(!myData.isCurrentTag(1));
2146    
2147     assert(myData.getTagLookup().size()==0);
2148    
2149     assert(myData.getLength()==1);
2150    
2151     assert(myData.getPointOffset(0,0)==0);
2152    
2153     DataArrayView myDataView = myData.getDataPoint(0,0);
2154     assert(!myDataView.isEmpty());
2155     assert(myDataView.getOffset()==0);
2156     assert(myDataView.getRank()==0);
2157     assert(myDataView.noValues()==1);
2158     assert(myDataView.getShape().size()==0);
2159     assert(myDataView()==0.0);
2160    
2161 jgs 499 // Test non-existent tag returns the default value.
2162 jgs 497 myDataView = myData.getDataPointByTag(1);
2163     assert(!myDataView.isEmpty());
2164     assert(myDataView.getOffset()==0);
2165     assert(myDataView.getRank()==0);
2166     assert(myDataView.noValues()==1);
2167     assert(myDataView.getShape().size()==0);
2168     assert(myDataView()==0.0);
2169    
2170     myDataView = myData.getDefaultValue();
2171     assert(!myDataView.isEmpty());
2172     assert(myDataView.getOffset()==0);
2173     assert(myDataView.getRank()==0);
2174     assert(myDataView.noValues()==1);
2175     assert(myDataView.getShape().size()==0);
2176     assert(myDataView()==0.0);
2177    
2178 jgs 506 // use a non-existent tag so we get a pointer to
2179     // the first element of the data array
2180     double* sampleData=myData.getSampleDataByTag(9);
2181     for (int i=0; i<myData.getLength(); i++) {
2182     assert(sampleData[i]==i);
2183     }
2184 jgs 510 sampleData=myData.getSampleData(0);
2185     for (int i=0; i<myDataView.noValues(); i++) {
2186     assert(sampleData[i]==i);
2187     }
2188 jgs 506
2189 jgs 82 }
2190 jgs 497
2191 jgs 82 {
2192 jgs 497
2193 jgs 499 cout << "\tTest DataTagged with default value only." << endl;
2194    
2195     DataArrayView::ShapeType viewShape;
2196     viewShape.push_back(3);
2197    
2198     DataTagged::TagListType keys;
2199    
2200     DataTagged::ValueListType values;
2201    
2202     DataArrayView::ValueType viewData(3);
2203     for (int i=0;i<viewShape[0];i++) {
2204     viewData[i]=i;
2205     }
2206     DataArrayView myView(viewData,viewShape);
2207    
2208     DataTagged myData(keys,values,myView,FunctionSpace());
2209    
2210     //cout << myData.toString() << endl;
2211    
2212     assert(myData.getNumSamples()==1);
2213     assert(myData.getNumDPPSample()==1);
2214    
2215     assert(myData.validSamplePointNo(0));
2216     assert(myData.validSampleNo(0));
2217     assert(!myData.validSamplePointNo(1));
2218     assert(!myData.validSampleNo(1));
2219    
2220 jgs 501 // data-point 0 has tag number 1 by default
2221 jgs 499 assert(myData.getTagNumber(0)==1);
2222    
2223     assert(!myData.isCurrentTag(1));
2224    
2225     assert(myData.getTagLookup().size()==0);
2226    
2227     assert(myData.getLength()==3);
2228    
2229     assert(myData.getPointOffset(0,0)==0);
2230    
2231     DataArrayView myDataView = myData.getDataPoint(0,0);
2232     assert(myDataView==myView);
2233     assert(!myDataView.isEmpty());
2234     assert(myDataView.getOffset()==0);
2235     assert(myDataView.getRank()==1);
2236     assert(myDataView.noValues()==3);
2237     assert(myDataView.getShape().size()==1);
2238     assert(myDataView(0)==0);
2239     assert(myDataView(1)==1);
2240     assert(myDataView(2)==2);
2241    
2242     // Test non-existent tag returns the default value.
2243     myDataView = myData.getDataPointByTag(1);
2244     assert(myDataView==myView);
2245     assert(!myDataView.isEmpty());
2246     assert(myDataView.getOffset()==0);
2247     assert(myDataView.getRank()==1);
2248     assert(myDataView.noValues()==3);
2249     assert(myDataView.getShape().size()==1);
2250     assert(myDataView(0)==0);
2251     assert(myDataView(1)==1);
2252     assert(myDataView(2)==2);
2253    
2254     myDataView = myData.getDefaultValue();
2255     assert(myDataView==myView);
2256     assert(!myDataView.isEmpty());
2257     assert(myDataView.getOffset()==0);
2258     assert(myDataView.getRank()==1);
2259     assert(myDataView.noValues()==3);
2260     assert(myDataView.getShape().size()==1);
2261     assert(myDataView(0)==0);
2262     assert(myDataView(1)==1);
2263     assert(myDataView(2)==2);
2264    
2265 jgs 506 // use a non-existent tag so we get a pointer to
2266     // the first element of the data array
2267     double* sampleData=myData.getSampleDataByTag(9);
2268     for (int i=0; i<myData.getLength(); i++) {
2269     assert(sampleData[i]==i);
2270     }
2271 jgs 510 sampleData=myData.getSampleDataByTag(0);
2272     for (int i=0; i<myDataView.noValues(); i++) {
2273     assert(sampleData[i]==i);
2274     }
2275 jgs 506
2276 jgs 82 }
2277 jgs 497
2278 jgs 82 {
2279 jgs