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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 854 - (hide annotations)
Thu Sep 21 05:29:42 2006 UTC (13 years, 5 months ago) by gross
Original Path: trunk/escript/test/DataTaggedTestCase.cpp
File size: 149654 byte(s)
Some modifications to the binary operations +,-,*/, pow. 
The code is a bit simpler now and more efficient has there is
no reseising required now. the resizing method has been removed as
it is very, very inefficient. Even serial code should be faster now.
It is now forbidden to do an inplace update of scalar data object with an object 
of rank >0 as this is very slow (and does not make much sense). 


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