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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1312 - (hide annotations)
Mon Sep 24 06:18:44 2007 UTC (12 years, 2 months ago) by ksteube
File size: 149208 byte(s)
The MPI branch is hereby closed. All future work should be in trunk.

Previously in revision 1295 I merged the latest changes to trunk into trunk-mpi-branch.
In this revision I copied all files from trunk-mpi-branch over the corresponding
trunk files. I did not use 'svn merge', it was a copy.

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