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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 682 - (show annotations)
Mon Mar 27 02:43:09 2006 UTC (13 years, 8 months ago) by robwdcock
File size: 158653 byte(s)
+ NEW BUILD SYSTEM

This commit contains the new build system with cross-platform support.
Most things work are before though you can have more control.

ENVIRONMENT settings have changed:
+ You no longer require LD_LIBRARY_PATH or PYTHONPATH to point to the
esysroot for building and testing performed via scons
+ ACcESS altix users: It is recommended you change your modules to load
the latest intel compiler and other libraries required by boost to match
the setup in svn (you can override). The correct modules are as follows

module load intel_cc.9.0.026
export
MODULEPATH=${MODULEPATH}:/data/raid2/toolspp4/modulefiles/gcc-3.3.6
module load boost/1.33.0/python-2.4.1
module load python/2.4.1
module load numarray/1.3.3


1 // $Id$
2
3 /*
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
17 #include "esysUtils/EsysException.h"
18
19 #include "escript/DataTagged.h"
20 #include "escript/DataConstant.h"
21
22 #include "DataTaggedTestCase.h"
23
24 #include "escript/BinaryOp.h"
25 #include "escript/UnaryOp.h"
26 #include "escript/FunctionSpaceFactory.h"
27 #include "escript/DataFactory.h"
28
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 void DataTaggedTestCase::testReshape() {
51
52 cout << endl;
53
54 {
55
56 cout << "\tTest rank 1 reshape of default DataTagged." << endl;
57
58 DataTagged myData;
59 myData.getPointDataView()()=1.0;
60
61 DataArrayView::ShapeType shape;
62 shape.push_back(2);
63
64 myData.reshapeDataPoint(shape);
65
66 for (int i=0;i<shape[0];i++) {
67 assert(myData.getDefaultValue()(i)==1);
68 }
69
70 //cout << myData.toString() << endl;
71
72 assert(myData.getNumSamples()==1);
73 assert(myData.getNumDPPSample()==1);
74
75 assert(myData.validSamplePointNo(0));
76 assert(myData.validSampleNo(0));
77 assert(!myData.validSamplePointNo(1));
78 assert(!myData.validSampleNo(1));
79
80 // data-point 0 has tag number 1 by default
81 assert(myData.getTagNumber(0)==1);
82
83 assert(!myData.isCurrentTag(1));
84
85 assert(myData.getTagLookup().size()==0);
86
87 assert(myData.getLength()==2);
88
89 assert(myData.getPointOffset(0,0)==0);
90
91 DataArrayView myDataView = myData.getDataPoint(0,0);
92 assert(!myDataView.isEmpty());
93 assert(myDataView.getOffset()==0);
94 assert(myDataView.getRank()==1);
95 assert(myDataView.noValues()==2);
96 assert(myDataView.getShape().size()==1);
97 assert(myDataView(0)==1.0);
98 assert(myDataView(1)==1.0);
99
100 // Test non-existent tag returns the default value.
101 myDataView = myData.getDataPointByTag(1);
102 assert(!myDataView.isEmpty());
103 assert(myDataView.getOffset()==0);
104 assert(myDataView.getRank()==1);
105 assert(myDataView.noValues()==2);
106 assert(myDataView.getShape().size()==1);
107 assert(myDataView(0)==1.0);
108 assert(myDataView(1)==1.0);
109
110 myDataView = myData.getDefaultValue();
111 assert(!myDataView.isEmpty());
112 assert(myDataView.getOffset()==0);
113 assert(myDataView.getRank()==1);
114 assert(myDataView.noValues()==2);
115 assert(myDataView.getShape().size()==1);
116 assert(myDataView(0)==1.0);
117 assert(myDataView(1)==1.0);
118
119 // use a non-existent tag so we get a pointer to
120 // the first element of the data array
121 double* sampleData=myData.getSampleDataByTag(9);
122 for (int i=0; i<myData.getLength(); i++) {
123 assert(sampleData[i]==1.0);
124 }
125
126 }
127
128 {
129
130 cout << "\tTest rank 2 reshape of DataTagged with one tag." << endl;
131
132 DataTagged::TagListType keys;
133 keys.push_back(1);
134
135 DataTagged::ValueListType values;
136
137 DataArrayView::ShapeType viewShape;
138
139 // default value
140 DataArrayView::ValueType viewData(1);
141 viewData[0]=1.0;
142 DataArrayView myView(viewData,viewShape);
143
144 // value for tag "1"
145 DataArray eOne(myView);
146 eOne.getView()()=2.0;
147 values.push_back(eOne.getView());
148
149 DataTagged myData(keys,values,myView,FunctionSpace());
150
151 DataArrayView::ShapeType shape;
152 shape.push_back(2);
153 shape.push_back(5);
154
155 myData.reshapeDataPoint(shape);
156
157 //cout << myData.toString() << endl;
158
159 assert(myData.getNumSamples()==1);
160 assert(myData.getNumDPPSample()==1);
161
162 assert(myData.validSamplePointNo(0));
163 assert(myData.validSampleNo(0));
164 assert(!myData.validSamplePointNo(1));
165 assert(!myData.validSampleNo(1));
166
167 // data-point 0 has tag number 1 by default
168 assert(myData.getTagNumber(0)==1);
169
170 assert(myData.isCurrentTag(1));
171
172 assert(myData.getTagLookup().size()==1);
173
174 assert(myData.getLength()==20);
175
176 assert(myData.getPointOffset(0,0)==10);
177
178 DataArrayView myDataView = myData.getDataPoint(0,0);
179 assert(!myDataView.isEmpty());
180 assert(myDataView.getOffset()==10);
181 assert(myDataView.getRank()==2);
182 assert(myDataView.noValues()==10);
183 assert(myDataView.getShape().size()==2);
184 for (int j=0;j<shape[1];j++) {
185 for (int i=0;i<shape[0];i++) {
186 assert(myDataView(i,j)==2.0);
187 }
188 }
189
190 myDataView = myData.getDataPointByTag(1);
191 assert(!myDataView.isEmpty());
192 assert(myDataView.getOffset()==10);
193 assert(myDataView.getRank()==2);
194 assert(myDataView.noValues()==10);
195 assert(myDataView.getShape().size()==2);
196 for (int j=0;j<shape[1];j++) {
197 for (int i=0;i<shape[0];i++) {
198 assert(myDataView(i,j)==2.0);
199 }
200 }
201
202 myDataView = myData.getDefaultValue();
203 assert(!myDataView.isEmpty());
204 assert(myDataView.getOffset()==0);
205 assert(myDataView.getRank()==2);
206 assert(myDataView.noValues()==10);
207 assert(myDataView.getShape().size()==2);
208 for (int j=0;j<shape[1];j++) {
209 for (int i=0;i<shape[0];i++) {
210 assert(myDataView(i,j)==1.0);
211 }
212 }
213
214 // use a non-existent tag so we get a pointer to
215 // the first element of the data array
216 double* sampleData=myData.getSampleDataByTag(9);
217 for (int i=0; i<myData.getLength(); i++) {
218 if (i<10) {
219 assert(sampleData[i]==1.0);
220 } else {
221 assert(sampleData[i]==2.0);
222 }
223 }
224
225 }
226
227 {
228
229 cout << "\tTest rank 3 reshape of DataTagged with three tags." << endl;
230
231 DataTagged::TagListType keys;
232 keys.push_back(1);
233 keys.push_back(2);
234 keys.push_back(3);
235
236 DataTagged::ValueListType values;
237
238 DataArrayView::ShapeType viewShape;
239
240 // default value
241 DataArrayView::ValueType viewData(1);
242 viewData[0]=0.0;
243 DataArrayView myView(viewData,viewShape);
244
245 // value for tag "1"
246 DataArray eOne(myView);
247 eOne.getView()()=1.0;
248 values.push_back(eOne.getView());
249
250 // value for tag "2"
251 DataArray eTwo(myView);
252 eTwo.getView()()=2.0;
253 values.push_back(eTwo.getView());
254
255 // value for tag "3"
256 DataArray eThree(myView);
257 eThree.getView()()=3.0;
258 values.push_back(eThree.getView());
259
260 DataTagged myData(keys,values,myView,FunctionSpace());
261
262 DataArrayView::ShapeType shape;
263 shape.push_back(2);
264 shape.push_back(2);
265 shape.push_back(2);
266
267 myData.reshapeDataPoint(shape);
268
269 //cout << myData.toString() << endl;
270
271 assert(myData.getNumSamples()==1);
272 assert(myData.getNumDPPSample()==1);
273
274 assert(myData.validSamplePointNo(0));
275 assert(myData.validSampleNo(0));
276 assert(!myData.validSamplePointNo(1));
277 assert(!myData.validSampleNo(1));
278
279 // data-point 0 has tag number 1 by default
280 assert(myData.getTagNumber(0)==1);
281
282 assert(myData.isCurrentTag(1));
283 assert(myData.isCurrentTag(2));
284 assert(myData.isCurrentTag(3));
285
286 assert(myData.getTagLookup().size()==3);
287
288 assert(myData.getLength()==32);
289
290 assert(myData.getPointOffset(0,0)==8);
291
292 DataArrayView myDataView = myData.getDataPoint(0,0);
293 assert(!myDataView.isEmpty());
294 assert(myDataView.getOffset()==8);
295 assert(myDataView.getRank()==3);
296 assert(myDataView.noValues()==8);
297 assert(myDataView.getShape().size()==3);
298 for (int k=0;k<shape[2];k++) {
299 for (int j=0;j<shape[1];j++) {
300 for (int i=0;i<shape[0];i++) {
301 assert(myDataView(i,j,k)==1.0);
302 }
303 }
304 }
305
306 myDataView = myData.getDataPointByTag(1);
307 assert(!myDataView.isEmpty());
308 assert(myDataView.getOffset()==8);
309 assert(myDataView.getRank()==3);
310 assert(myDataView.noValues()==8);
311 assert(myDataView.getShape().size()==3);
312 for (int k=0;k<shape[2];k++) {
313 for (int j=0;j<shape[1];j++) {
314 for (int i=0;i<shape[0];i++) {
315 assert(myDataView(i,j,k)==1.0);
316 }
317 }
318 }
319
320 myDataView = myData.getDataPointByTag(2);
321 assert(!myDataView.isEmpty());
322 assert(myDataView.getOffset()==16);
323 assert(myDataView.getRank()==3);
324 assert(myDataView.noValues()==8);
325 assert(myDataView.getShape().size()==3);
326 for (int k=0;k<shape[2];k++) {
327 for (int j=0;j<shape[1];j++) {
328 for (int i=0;i<shape[0];i++) {
329 assert(myDataView(i,j,k)==2.0);
330 }
331 }
332 }
333
334 myDataView = myData.getDataPointByTag(3);
335 assert(!myDataView.isEmpty());
336 assert(myDataView.getOffset()==24);
337 assert(myDataView.getRank()==3);
338 assert(myDataView.noValues()==8);
339 assert(myDataView.getShape().size()==3);
340 for (int k=0;k<shape[2];k++) {
341 for (int j=0;j<shape[1];j++) {
342 for (int i=0;i<shape[0];i++) {
343 assert(myDataView(i,j,k)==3.0);
344 }
345 }
346 }
347
348 myDataView = myData.getDefaultValue();
349 assert(!myDataView.isEmpty());
350 assert(myDataView.getOffset()==0);
351 assert(myDataView.getRank()==3);
352 assert(myDataView.noValues()==8);
353 assert(myDataView.getShape().size()==3);
354 for (int k=0;k<shape[2];k++) {
355 for (int j=0;j<shape[1];j++) {
356 for (int i=0;i<shape[0];i++) {
357 assert(myDataView(i,j,k)==0.0);
358 }
359 }
360 }
361
362 // use a non-existent tag so we get a pointer to
363 // the first element of the data array
364 double* sampleData=myData.getSampleDataByTag(9);
365 for (int i=0; i<myData.getLength(); i++) {
366 if (i<8) {
367 assert(sampleData[i]==0.0);
368 } else if ((i>=8) && (i<16)) {
369 assert(sampleData[i]==1.0);
370 } else if ((i>=16) && (i<24)) {
371 assert(sampleData[i]==2.0);
372 } else {
373 assert(sampleData[i]==3.0);
374 }
375 }
376
377 }
378
379 }
380
381 void DataTaggedTestCase::testOperations() {
382
383 cout << endl;
384
385 {
386 cout << "\tTest binaryOp addition of two default DataTagged objects." << endl;
387
388 DataTagged myData;
389 DataTagged right;
390
391 binaryOp(myData,right,plus<double>());
392
393 //cout << myData.toString() << endl;
394
395 assert(myData.getNumSamples()==1);
396 assert(myData.getNumDPPSample()==1);
397
398 assert(myData.validSamplePointNo(0));
399 assert(myData.validSampleNo(0));
400 assert(!myData.validSamplePointNo(1));
401 assert(!myData.validSampleNo(1));
402
403 // data-point 0 has tag number 1 by default
404 assert(myData.getTagNumber(0)==1);
405
406 assert(!myData.isCurrentTag(1));
407
408 assert(myData.getTagLookup().size()==0);
409
410 assert(myData.getLength()==1);
411
412 assert(myData.getPointOffset(0,0)==0);
413
414 DataArrayView myDataView = myData.getDataPoint(0,0);
415 assert(!myDataView.isEmpty());
416 assert(myDataView.getOffset()==0);
417 assert(myDataView.getRank()==0);
418 assert(myDataView.noValues()==1);
419 assert(myDataView.getShape().size()==0);
420 assert(myDataView()==0.0);
421
422 // Test non-existent tag returns the default value.
423 myDataView = myData.getDataPointByTag(1);
424 assert(!myDataView.isEmpty());
425 assert(myDataView.getOffset()==0);
426 assert(myDataView.getRank()==0);
427 assert(myDataView.noValues()==1);
428 assert(myDataView.getShape().size()==0);
429 assert(myDataView()==0.0);
430
431 myDataView = myData.getDefaultValue();
432 assert(!myDataView.isEmpty());
433 assert(myDataView.getOffset()==0);
434 assert(myDataView.getRank()==0);
435 assert(myDataView.noValues()==1);
436 assert(myDataView.getShape().size()==0);
437 assert(myDataView()==0.0);
438
439 // use a non-existent tag so we get a pointer to
440 // the first element of the data array
441 double* sampleData=myData.getSampleDataByTag(9);
442 for (int i=0; i<myData.getLength(); i++) {
443 assert(sampleData[i]==i);
444 }
445
446 }
447
448 {
449 cout << "\tTest binaryOp addition of two DataTagged objects with default values only." << endl;
450
451 DataArrayView::ShapeType viewShape;
452 viewShape.push_back(3);
453
454 DataTagged::TagListType keys;
455
456 DataTagged::ValueListType values;
457
458 DataArrayView::ValueType viewData(3);
459 for (int i=0;i<viewShape[0];i++) {
460 viewData[i]=i;
461 }
462 DataArrayView myView(viewData,viewShape);
463
464 DataTagged myData(keys,values,myView,FunctionSpace());
465 DataTagged right(keys,values,myView,FunctionSpace());
466
467 binaryOp(myData,right,plus<double>());
468
469 //cout << myData.toString() << endl;
470
471 assert(myData.getNumSamples()==1);
472 assert(myData.getNumDPPSample()==1);
473
474 assert(myData.validSamplePointNo(0));
475 assert(myData.validSampleNo(0));
476 assert(!myData.validSamplePointNo(1));
477 assert(!myData.validSampleNo(1));
478
479 // data-point 0 has tag number 1 by default
480 assert(myData.getTagNumber(0)==1);
481
482 assert(!myData.isCurrentTag(1));
483
484 assert(myData.getTagLookup().size()==0);
485
486 assert(myData.getLength()==3);
487
488 assert(myData.getPointOffset(0,0)==0);
489
490 DataArrayView myDataView = myData.getDefaultValue();
491 assert(!myDataView.isEmpty());
492 assert(myDataView.getOffset()==0);
493 assert(myDataView.getRank()==1);
494 assert(myDataView.noValues()==3);
495 assert(myDataView.getShape().size()==1);
496 assert(myDataView(0)==0);
497 assert(myDataView(1)==2);
498 assert(myDataView(2)==4);
499
500 // use a non-existent tag so we get a pointer to
501 // the first element of the data array
502 double* sampleData=myData.getSampleDataByTag(9);
503 for (int i=0; i<myData.getLength(); i++) {
504 assert(sampleData[i]==i*2);
505 }
506
507 }
508
509 {
510 cout << "\tTest binaryOp addition of two DataTagged objects with one identical tag each." << endl;
511
512 DataTagged myData;
513 DataTagged right;
514
515 DataArray vOne(1.0);
516 myData.addTaggedValue(1,vOne.getView());
517 right.addTaggedValue(1,vOne.getView());
518
519 binaryOp(myData,right,plus<double>());
520
521 assert(myData.getNumSamples()==1);
522 assert(myData.getNumDPPSample()==1);
523
524 assert(myData.validSamplePointNo(0));
525 assert(myData.validSampleNo(0));
526 assert(!myData.validSamplePointNo(1));
527 assert(!myData.validSampleNo(1));
528
529 // data-point 0 has tag number 1 by default
530 assert(myData.getTagNumber(0)==1);
531
532 assert(myData.isCurrentTag(1));
533
534 assert(myData.getTagLookup().size()==1);
535
536 assert(myData.getLength()==2);
537
538 assert(myData.getPointOffset(0,0)==1);
539
540 // check result value for tag "1"
541 DataArrayView myDataView = myData.getDataPointByTag(1);
542 assert(!myDataView.isEmpty());
543 assert(myDataView.getOffset()==1);
544 assert(myDataView.getRank()==0);
545 assert(myDataView.noValues()==1);
546 assert(myDataView.getShape().size()==0);
547 assert(myDataView()==2.0);
548
549 // check result for default value
550 myDataView = myData.getDefaultValue();
551 assert(!myDataView.isEmpty());
552 assert(myDataView.getOffset()==0);
553 assert(myDataView.getRank()==0);
554 assert(myDataView.noValues()==1);
555 assert(myDataView.getShape().size()==0);
556 assert(myDataView()==0.0);
557
558 // use a non-existent tag so we get a pointer to
559 // the first element of the data array
560 double* sampleData=myData.getSampleDataByTag(9);
561 for (int i=0; i<myData.getLength(); i++) {
562 assert(sampleData[i]==i*2);
563 }
564
565 }
566
567 {
568 cout << "\tTest binaryOp addition of two DataTagged objects with one different tag each." << endl;
569
570 DataTagged myData;
571 DataTagged right;
572
573 // it's important that default values are different, as we need to be able to
574 // verify that the tag values in each object are being added to the correct
575 // default values - since the tag lists don't match, the default values will
576 // be used for missing tags in each object
577 myData.getDefaultValue()()=1.0;
578 right.getDefaultValue()()=2.0;
579
580 DataArray vOne(3.0);
581 DataArray vTwo(4.0);
582 myData.addTaggedValue(1,vOne.getView());
583 right.addTaggedValue(2,vTwo.getView());
584
585 //cout << myData.toString() << endl;
586 //cout << right.toString() << endl;
587
588 binaryOp(myData,right,plus<double>());
589
590 //cout << myData.toString() << endl;
591
592 assert(myData.getNumSamples()==1);
593 assert(myData.getNumDPPSample()==1);
594
595 assert(myData.validSamplePointNo(0));
596 assert(myData.validSampleNo(0));
597 assert(!myData.validSamplePointNo(1));
598 assert(!myData.validSampleNo(1));
599
600 // data-point 0 has tag number 1 by default
601 assert(myData.getTagNumber(0)==1);
602
603 assert(myData.isCurrentTag(1));
604 assert(myData.isCurrentTag(2));
605
606 assert(myData.getTagLookup().size()==2);
607
608 assert(myData.getLength()==3);
609
610 assert(myData.getPointOffset(0,0)==1);
611
612 // check result value for tag "1"
613 DataArrayView myDataView = myData.getDataPointByTag(1);
614 assert(!myDataView.isEmpty());
615 assert(myDataView.getOffset()==1);
616 assert(myDataView.getRank()==0);
617 assert(myDataView.noValues()==1);
618 assert(myDataView.getShape().size()==0);
619 assert(myDataView()==5.0);
620
621 // check result value for tag "2"
622 myDataView = myData.getDataPointByTag(2);
623 assert(!myDataView.isEmpty());
624 assert(myDataView.getOffset()==2);
625 assert(myDataView.getRank()==0);
626 assert(myDataView.noValues()==1);
627 assert(myDataView.getShape().size()==0);
628 assert(myDataView()==5.0);
629
630 // check result for default value
631 myDataView = myData.getDefaultValue();
632 assert(!myDataView.isEmpty());
633 assert(myDataView.getOffset()==0);
634 assert(myDataView.getRank()==0);
635 assert(myDataView.noValues()==1);
636 assert(myDataView.getShape().size()==0);
637 assert(myDataView()==3.0);
638
639 // use a non-existent tag so we get a pointer to
640 // the first element of the data array
641 double* sampleData=myData.getSampleDataByTag(9);
642 assert(sampleData[0]==3);
643 assert(sampleData[1]==5);
644 assert(sampleData[2]==5);
645
646 }
647
648 {
649 cout << "\tTest binaryOp addition of two DataTagged objects with overlapping tag sets." << endl;
650
651 DataTagged myData;
652 DataTagged right;
653
654 // it's important that default values are different, as we need to be able to
655 // verify that the tag values in each object are being added to the correct
656 // default values - since the tag lists don't match, the default values will
657 // be used for missing tags in each object
658 myData.getDefaultValue()()=2.0;
659 right.getDefaultValue()()=3.0;
660
661 DataArray vOne(1.0);
662 myData.addTaggedValue(1,vOne.getView());
663 myData.addTaggedValue(2,vOne.getView());
664 right.addTaggedValue(2,vOne.getView());
665 right.addTaggedValue(3,vOne.getView());
666
667 //cout << myData.toString() << endl;
668 //cout << right.toString() << endl;
669
670 binaryOp(myData,right,plus<double>());
671
672 //cout << myData.toString() << endl;
673
674 assert(myData.getNumSamples()==1);
675 assert(myData.getNumDPPSample()==1);
676
677 assert(myData.validSamplePointNo(0));
678 assert(myData.validSampleNo(0));
679 assert(!myData.validSamplePointNo(1));
680 assert(!myData.validSampleNo(1));
681
682 // data-point 0 has tag number 1 by default
683 assert(myData.getTagNumber(0)==1);
684
685 assert(myData.isCurrentTag(1));
686 assert(myData.isCurrentTag(2));
687 assert(myData.isCurrentTag(3));
688
689 assert(myData.getTagLookup().size()==3);
690
691 assert(myData.getLength()==4);
692
693 assert(myData.getPointOffset(0,0)==1);
694
695 // check result value for tag "1"
696 DataArrayView myDataView = myData.getDataPointByTag(1);
697 assert(!myDataView.isEmpty());
698 assert(myDataView.getOffset()==1);
699 assert(myDataView.getRank()==0);
700 assert(myDataView.noValues()==1);
701 assert(myDataView.getShape().size()==0);
702 assert(myDataView()==4.0);
703
704 // check result value for tag "2"
705 myDataView = myData.getDataPointByTag(2);
706 assert(!myDataView.isEmpty());
707 assert(myDataView.getOffset()==2);
708 assert(myDataView.getRank()==0);
709 assert(myDataView.noValues()==1);
710 assert(myDataView.getShape().size()==0);
711 assert(myDataView()==2.0);
712
713 // check result value for tag "3"
714 myDataView = myData.getDataPointByTag(3);
715 assert(!myDataView.isEmpty());
716 assert(myDataView.getOffset()==3);
717 assert(myDataView.getRank()==0);
718 assert(myDataView.noValues()==1);
719 assert(myDataView.getShape().size()==0);
720 assert(myDataView()==3.0);
721
722 // check result for default value
723 myDataView = myData.getDefaultValue();
724 assert(!myDataView.isEmpty());
725 assert(myDataView.getOffset()==0);
726 assert(myDataView.getRank()==0);
727 assert(myDataView.noValues()==1);
728 assert(myDataView.getShape().size()==0);
729 assert(myDataView()==5.0);
730
731 // use a non-existent tag so we get a pointer to
732 // the first element of the data array
733 double* sampleData=myData.getSampleDataByTag(9);
734 assert(sampleData[0]==5);
735 assert(sampleData[1]==4);
736 assert(sampleData[2]==2);
737 assert(sampleData[3]==3);
738
739 }
740
741 {
742 cout << "\tTest binaryOp multiplication of two DataTagged objects with default values only." << endl;
743
744 DataArrayView::ShapeType viewShape;
745 viewShape.push_back(3);
746
747 DataTagged::TagListType keys;
748
749 DataTagged::ValueListType values;
750
751 DataArrayView::ValueType viewData(3);
752 for (int i=0;i<viewShape[0];i++) {
753 viewData[i]=i;
754 }
755 DataArrayView myView(viewData,viewShape);
756
757 DataTagged myData(keys,values,myView,FunctionSpace());
758 DataTagged right(keys,values,myView,FunctionSpace());
759
760 binaryOp(myData,right,multiplies<double>());
761
762 //cout << myData.toString() << endl;
763
764 assert(myData.getNumSamples()==1);
765 assert(myData.getNumDPPSample()==1);
766
767 assert(myData.validSamplePointNo(0));
768 assert(myData.validSampleNo(0));
769 assert(!myData.validSamplePointNo(1));
770 assert(!myData.validSampleNo(1));
771
772 // data-point 0 has tag number 1 by default
773 assert(myData.getTagNumber(0)==1);
774
775 assert(!myData.isCurrentTag(1));
776
777 assert(myData.getTagLookup().size()==0);
778
779 assert(myData.getLength()==3);
780
781 assert(myData.getPointOffset(0,0)==0);
782
783 DataArrayView myDataView = myData.getDefaultValue();
784 assert(!myDataView.isEmpty());
785 assert(myDataView.getOffset()==0);
786 assert(myDataView.getRank()==1);
787 assert(myDataView.noValues()==3);
788 assert(myDataView.getShape().size()==1);
789 assert(myDataView(0)==0);
790 assert(myDataView(1)==1);
791 assert(myDataView(2)==4);
792
793 // use a non-existent tag so we get a pointer to
794 // the first element of the data array
795 double* sampleData=myData.getSampleDataByTag(9);
796 for (int i=0; i<myData.getLength(); i++) {
797 assert(sampleData[i]==i*i);
798 }
799
800 }
801
802 {
803
804 cout << "\tTest binaryOp multiplication of DataTagged object with a scalar." << endl;
805
806 DataTagged myData;
807
808 DataArray vOne(1.0);
809 DataArray vTwo(2.0);
810 myData.addTaggedValue(1,vOne.getView());
811 myData.addTaggedValue(2,vTwo.getView());
812
813 DataArray vThree(3.0);
814 DataArrayView right=vThree.getView();
815
816 //cout << myData.toString() << endl;
817 //cout << right.toString() << endl;
818
819 binaryOp(myData,right,multiplies<double>());
820
821 //cout << myData.toString() << endl;
822
823 assert(myData.getNumSamples()==1);
824 assert(myData.getNumDPPSample()==1);
825
826 assert(myData.validSamplePointNo(0));
827 assert(myData.validSampleNo(0));
828 assert(!myData.validSamplePointNo(1));
829 assert(!myData.validSampleNo(1));
830
831 // data-point 0 has tag number 1 by default
832 assert(myData.getTagNumber(0)==1);
833
834 assert(myData.isCurrentTag(1));
835 assert(myData.isCurrentTag(2));
836
837 assert(myData.getTagLookup().size()==2);
838
839 assert(myData.getLength()==3);
840
841 assert(myData.getPointOffset(0,0)==1);
842
843 // check result value for tag "1"
844 DataArrayView myDataView = myData.getDataPointByTag(1);
845 assert(!myDataView.isEmpty());
846 assert(myDataView.getOffset()==1);
847 assert(myDataView.getRank()==0);
848 assert(myDataView.noValues()==1);
849 assert(myDataView.getShape().size()==0);
850 assert(myDataView()==3.0);
851
852 // check result value for tag "2"
853 myDataView = myData.getDataPointByTag(2);
854 assert(!myDataView.isEmpty());
855 assert(myDataView.getOffset()==2);
856 assert(myDataView.getRank()==0);
857 assert(myDataView.noValues()==1);
858 assert(myDataView.getShape().size()==0);
859 assert(myDataView()==6.0);
860
861 // check result for default value
862 myDataView = myData.getDefaultValue();
863 assert(!myDataView.isEmpty());
864 assert(myDataView.getOffset()==0);
865 assert(myDataView.getRank()==0);
866 assert(myDataView.noValues()==1);
867 assert(myDataView.getShape().size()==0);
868 assert(myDataView()==0.0);
869
870 // use a non-existent tag so we get a pointer to
871 // the first element of the data array
872 double* sampleData=myData.getSampleDataByTag(9);
873 assert(sampleData[0]==0);
874 assert(sampleData[1]==3);
875 assert(sampleData[2]==6);
876
877 }
878
879 {
880 cout << "\tTest binaryOp multiplication of two DataTagged objects with overlapping tag sets." << endl;
881
882 DataTagged myData;
883 DataTagged right;
884
885 // it's important that default values are different, as we need to be able to
886 // verify that the tag values in each object are being added to the correct
887 // default values - since the tag lists don't match, the default values will
888 // be used for missing tags in each object
889 myData.getDefaultValue()()=2.0;
890 right.getDefaultValue()()=3.0;
891
892 DataArray vOne(1.0);
893 DataArray vTwo(2.0);
894 myData.addTaggedValue(1,vOne.getView());
895 myData.addTaggedValue(2,vOne.getView());
896 right.addTaggedValue(2,vTwo.getView());
897 right.addTaggedValue(3,vTwo.getView());
898
899 //cout << myData.toString() << endl;
900 //cout << right.toString() << endl;
901
902 binaryOp(myData,right,multiplies<double>());
903
904 //cout << myData.toString() << endl;
905
906 assert(myData.getNumSamples()==1);
907 assert(myData.getNumDPPSample()==1);
908
909 assert(myData.validSamplePointNo(0));
910 assert(myData.validSampleNo(0));
911 assert(!myData.validSamplePointNo(1));
912 assert(!myData.validSampleNo(1));
913
914 // data-point 0 has tag number 1 by default
915 assert(myData.getTagNumber(0)==1);
916
917 assert(myData.isCurrentTag(1));
918 assert(myData.isCurrentTag(2));
919 assert(myData.isCurrentTag(3));
920
921 assert(myData.getTagLookup().size()==3);
922
923 assert(myData.getLength()==4);
924
925 assert(myData.getPointOffset(0,0)==1);
926
927 // check result value for tag "1"
928 DataArrayView myDataView = myData.getDataPointByTag(1);
929 assert(!myDataView.isEmpty());
930 assert(myDataView.getOffset()==1);
931 assert(myDataView.getRank()==0);
932 assert(myDataView.noValues()==1);
933 assert(myDataView.getShape().size()==0);
934 assert(myDataView()==3.0);
935
936 // check result value for tag "2"
937 myDataView = myData.getDataPointByTag(2);
938 assert(!myDataView.isEmpty());
939 assert(myDataView.getOffset()==2);
940 assert(myDataView.getRank()==0);
941 assert(myDataView.noValues()==1);
942 assert(myDataView.getShape().size()==0);
943 assert(myDataView()==2.0);
944
945 // check result value for tag "3"
946 myDataView = myData.getDataPointByTag(3);
947 assert(!myDataView.isEmpty());
948 assert(myDataView.getOffset()==3);
949 assert(myDataView.getRank()==0);
950 assert(myDataView.noValues()==1);
951 assert(myDataView.getShape().size()==0);
952 assert(myDataView()==4.0);
953
954 // check result for default value
955 myDataView = myData.getDefaultValue();
956 assert(!myDataView.isEmpty());
957 assert(myDataView.getOffset()==0);
958 assert(myDataView.getRank()==0);
959 assert(myDataView.noValues()==1);
960 assert(myDataView.getShape().size()==0);
961 assert(myDataView()==6.0);
962
963 // use a non-existent tag so we get a pointer to
964 // the first element of the data array
965 double* sampleData=myData.getSampleDataByTag(9);
966 assert(sampleData[0]==6);
967 assert(sampleData[1]==3);
968 assert(sampleData[2]==2);
969 assert(sampleData[3]==4);
970
971 }
972
973 {
974 cout << "\tTest unaryOp negate on default DataTagged object." << endl;
975
976 DataTagged myData;
977
978 unaryOp(myData,negate<double>());
979
980 //cout << myData.toString() << endl;
981
982 assert(myData.getNumSamples()==1);
983 assert(myData.getNumDPPSample()==1);
984
985 assert(myData.validSamplePointNo(0));
986 assert(myData.validSampleNo(0));
987 assert(!myData.validSamplePointNo(1));
988 assert(!myData.validSampleNo(1));
989
990 // data-point 0 has tag number 1 by default
991 assert(myData.getTagNumber(0)==1);
992
993 assert(!myData.isCurrentTag(1));
994
995 assert(myData.getTagLookup().size()==0);
996
997 assert(myData.getLength()==1);
998
999 assert(myData.getPointOffset(0,0)==0);
1000
1001 DataArrayView myDataView = myData.getDataPoint(0,0);
1002 assert(!myDataView.isEmpty());
1003 assert(myDataView.getOffset()==0);
1004 assert(myDataView.getRank()==0);
1005 assert(myDataView.noValues()==1);
1006 assert(myDataView.getShape().size()==0);
1007 assert(myDataView()==0.0);
1008
1009 // Test non-existent tag returns the default value.
1010 myDataView = myData.getDataPointByTag(1);
1011 assert(!myDataView.isEmpty());
1012 assert(myDataView.getOffset()==0);
1013 assert(myDataView.getRank()==0);
1014 assert(myDataView.noValues()==1);
1015 assert(myDataView.getShape().size()==0);
1016 assert(myDataView()==0.0);
1017
1018 myDataView = myData.getDefaultValue();
1019 assert(!myDataView.isEmpty());
1020 assert(myDataView.getOffset()==0);
1021 assert(myDataView.getRank()==0);
1022 assert(myDataView.noValues()==1);
1023 assert(myDataView.getShape().size()==0);
1024 assert(myDataView()==0.0);
1025
1026 // use a non-existent tag so we get a pointer to
1027 // the first element of the data array
1028 double* sampleData=myData.getSampleDataByTag(9);
1029 for (int i=0; i<myData.getLength(); i++) {
1030 assert(sampleData[i]==i);
1031 }
1032
1033 }
1034
1035 {
1036 cout << "\tTest unaryOp negate on DataTagged object with default value only." << endl;
1037
1038 DataArrayView::ShapeType viewShape;
1039 viewShape.push_back(3);
1040
1041 DataTagged::TagListType keys;
1042
1043 DataTagged::ValueListType values;
1044
1045 DataArrayView::ValueType viewData(3);
1046 for (int i=0;i<viewShape[0];i++) {
1047 viewData[i]=i;
1048 }
1049 DataArrayView myView(viewData,viewShape);
1050
1051 DataTagged myData(keys,values,myView,FunctionSpace());
1052
1053 unaryOp(myData,negate<double>());
1054
1055 //cout << myData.toString() << endl;
1056
1057 assert(myData.getNumSamples()==1);
1058 assert(myData.getNumDPPSample()==1);
1059
1060 assert(myData.validSamplePointNo(0));
1061 assert(myData.validSampleNo(0));
1062 assert(!myData.validSamplePointNo(1));
1063 assert(!myData.validSampleNo(1));
1064
1065 // data-point 0 has tag number 1 by default
1066 assert(myData.getTagNumber(0)==1);
1067
1068 assert(!myData.isCurrentTag(1));
1069
1070 assert(myData.getTagLookup().size()==0);
1071
1072 assert(myData.getLength()==3);
1073
1074 assert(myData.getPointOffset(0,0)==0);
1075
1076 DataArrayView myDataView = myData.getDefaultValue();
1077 assert(!myDataView.isEmpty());
1078 assert(myDataView.getOffset()==0);
1079 assert(myDataView.getRank()==1);
1080 assert(myDataView.noValues()==3);
1081 assert(myDataView.getShape().size()==1);
1082 assert(myDataView(0)==0);
1083 assert(myDataView(1)==-1);
1084 assert(myDataView(2)==-2);
1085
1086 // use a non-existent tag so we get a pointer to
1087 // the first element of the data array
1088 double* sampleData=myData.getSampleDataByTag(9);
1089 for (int i=0; i<myData.getLength(); i++) {
1090 assert(sampleData[i]==0-i);
1091 }
1092
1093 }
1094
1095 {
1096 cout << "\tTest unaryOp negate on DataTagged object with two tags." << endl;
1097
1098 DataTagged myData;
1099
1100 DataArray vOne(1.0);
1101 DataArray vTwo(2.0);
1102 myData.addTaggedValue(1,vOne.getView());
1103 myData.addTaggedValue(2,vTwo.getView());
1104
1105 unaryOp(myData,negate<double>());
1106
1107 assert(myData.getNumSamples()==1);
1108 assert(myData.getNumDPPSample()==1);
1109
1110 assert(myData.validSamplePointNo(0));
1111 assert(myData.validSampleNo(0));
1112 assert(!myData.validSamplePointNo(1));
1113 assert(!myData.validSampleNo(1));
1114
1115 // data-point 0 has tag number 1 by default
1116 assert(myData.getTagNumber(0)==1);
1117
1118 assert(myData.isCurrentTag(1));
1119 assert(myData.isCurrentTag(2));
1120
1121 assert(myData.getTagLookup().size()==2);
1122
1123 assert(myData.getLength()==3);
1124
1125 assert(myData.getPointOffset(0,0)==1);
1126
1127 // check result value for tag "1"
1128 DataArrayView myDataView = myData.getDataPointByTag(1);
1129 assert(!myDataView.isEmpty());
1130 assert(myDataView.getOffset()==1);
1131 assert(myDataView.getRank()==0);
1132 assert(myDataView.noValues()==1);
1133 assert(myDataView.getShape().size()==0);
1134 assert(myDataView()==-1.0);
1135
1136 // check result value for tag "2"
1137 myDataView = myData.getDataPointByTag(2);
1138 assert(!myDataView.isEmpty());
1139 assert(myDataView.getOffset()==2);
1140 assert(myDataView.getRank()==0);
1141 assert(myDataView.noValues()==1);
1142 assert(myDataView.getShape().size()==0);
1143 assert(myDataView()==-2.0);
1144
1145 // check result for default value
1146 myDataView = myData.getDefaultValue();
1147 assert(!myDataView.isEmpty());
1148 assert(myDataView.getOffset()==0);
1149 assert(myDataView.getRank()==0);
1150 assert(myDataView.noValues()==1);
1151 assert(myDataView.getShape().size()==0);
1152 assert(myDataView()==0.0);
1153
1154 // use a non-existent tag so we get a pointer to
1155 // the first element of the data array
1156 double* sampleData=myData.getSampleDataByTag(9);
1157 for (int i=0; i<myData.getLength(); i++) {
1158 assert(sampleData[i]==0-i);
1159 }
1160
1161 }
1162
1163 }
1164
1165 void DataTaggedTestCase::testAddTaggedValues() {
1166
1167 cout << endl;
1168
1169 {
1170
1171 cout << "\tTest adding one key with empty value list to default DataTagged." << endl;
1172 DataTagged myData;
1173
1174 DataTagged::TagListType keys;
1175 keys.push_back(1);
1176
1177 DataTagged::ValueListType values;
1178
1179 myData.addTaggedValues(keys,values);
1180
1181 assert(myData.isCurrentTag(1));
1182
1183 assert(myData.getTagLookup().size()==1);
1184
1185 assert(myData.getLength()==2);
1186
1187 // data-point 0 has tag number 1 by default
1188 assert(myData.getTagNumber(0)==1);
1189
1190 assert(myData.getPointOffset(0,0)==1);
1191
1192 DataArrayView myDataView = myData.getDataPoint(0,0);
1193 assert(!myDataView.isEmpty());
1194 assert(myDataView.getOffset()==1);
1195 assert(myDataView.getRank()==0);
1196 assert(myDataView.noValues()==1);
1197 assert(myDataView.getShape().size()==0);
1198 assert(myDataView()==0.0);
1199
1200 myDataView = myData.getDataPointByTag(1);
1201 assert(!myDataView.isEmpty());
1202 assert(myDataView.getOffset()==1);
1203 assert(myDataView.getRank()==0);
1204 assert(myDataView.noValues()==1);
1205 assert(myDataView.getShape().size()==0);
1206 assert(myDataView()==0.0);
1207
1208 myDataView = myData.getDefaultValue();
1209 assert(!myDataView.isEmpty());
1210 assert(myDataView.getOffset()==0);
1211 assert(myDataView.getRank()==0);
1212 assert(myDataView.noValues()==1);
1213 assert(myDataView.getShape().size()==0);
1214 assert(myDataView()==0.0);
1215
1216 // use a non-existent tag so we get a pointer to
1217 // the first element of the data array
1218 double* sampleData=myData.getSampleDataByTag(9);
1219 for (int i=0; i<myData.getLength(); i++) {
1220 assert(sampleData[i]==0);
1221 }
1222
1223 }
1224
1225 {
1226
1227 cout << "\tTest adding one key with one value to default DataTagged." << endl;
1228 DataTagged myData;
1229
1230 DataTagged::TagListType keys;
1231 keys.push_back(1);
1232
1233 DataTagged::ValueListType values;
1234
1235 DataArrayView::ShapeType viewShape;
1236 DataArrayView::ValueType viewData(1);
1237 viewData[0]=1.0;
1238 DataArrayView myView(viewData,viewShape);
1239 values.push_back(myView);
1240
1241 myData.addTaggedValues(keys,values);
1242
1243 assert(myData.isCurrentTag(1));
1244
1245 assert(myData.getTagLookup().size()==1);
1246
1247 assert(myData.getLength()==2);
1248
1249 // data-point 0 has tag number 1 by default
1250 assert(myData.getTagNumber(0)==1);
1251
1252 assert(myData.getPointOffset(0,0)==1);
1253
1254 DataArrayView myDataView = myData.getDataPoint(0,0);
1255 assert(!myDataView.isEmpty());
1256 assert(myDataView.getOffset()==1);
1257 assert(myDataView.getRank()==0);
1258 assert(myDataView.noValues()==1);
1259 assert(myDataView.getShape().size()==0);
1260 assert(myDataView()==1.0);
1261
1262 myDataView = myData.getDataPointByTag(1);
1263 assert(!myDataView.isEmpty());
1264 assert(myDataView.getOffset()==1);
1265 assert(myDataView.getRank()==0);
1266 assert(myDataView.noValues()==1);
1267 assert(myDataView.getShape().size()==0);
1268 assert(myDataView()==1.0);
1269
1270 myDataView = myData.getDefaultValue();
1271 assert(!myDataView.isEmpty());
1272 assert(myDataView.getOffset()==0);
1273 assert(myDataView.getRank()==0);
1274 assert(myDataView.noValues()==1);
1275 assert(myDataView.getShape().size()==0);
1276 assert(myDataView()==0.0);
1277
1278 // use a non-existent tag so we get a pointer to
1279 // the first element of the data array
1280 double* sampleData=myData.getSampleDataByTag(9);
1281 for (int i=0; i<myData.getLength(); i++) {
1282 assert(sampleData[i]==i);
1283 }
1284
1285 }
1286
1287 {
1288
1289 cout << "\tTest adding three keys with one value to default DataTagged." << endl;
1290 DataTagged myData;
1291
1292 DataTagged::TagListType keys;
1293 keys.push_back(1);
1294 keys.push_back(2);
1295 keys.push_back(3);
1296
1297 DataTagged::ValueListType values;
1298
1299 DataArrayView::ShapeType viewShape;
1300 DataArrayView::ValueType viewData(1);
1301 viewData[0]=1.0;
1302 DataArrayView myView(viewData,viewShape);
1303 values.push_back(myView);
1304
1305 myData.addTaggedValues(keys,values);
1306
1307 assert(myData.isCurrentTag(1));
1308 assert(myData.isCurrentTag(2));
1309 assert(myData.isCurrentTag(3));
1310
1311 assert(myData.getTagLookup().size()==3);
1312
1313 assert(myData.getLength()==4);
1314
1315 // data-point 0 has tag number 1 by default
1316 assert(myData.getTagNumber(0)==1);
1317
1318 assert(myData.getPointOffset(0,0)==1);
1319
1320 DataArrayView myDataView = myData.getDataPoint(0,0);
1321 assert(!myDataView.isEmpty());
1322 assert(myDataView.getOffset()==1);
1323 assert(myDataView.getRank()==0);
1324 assert(myDataView.noValues()==1);
1325 assert(myDataView.getShape().size()==0);
1326 assert(myDataView()==1.0);
1327
1328 myDataView = myData.getDataPointByTag(1);
1329 assert(!myDataView.isEmpty());
1330 assert(myDataView.getOffset()==1);
1331 assert(myDataView.getRank()==0);
1332 assert(myDataView.noValues()==1);
1333 assert(myDataView.getShape().size()==0);
1334 assert(myDataView()==1.0);
1335
1336 myDataView = myData.getDataPointByTag(2);
1337 assert(!myDataView.isEmpty());
1338 assert(myDataView.getOffset()==2);
1339 assert(myDataView.getRank()==0);
1340 assert(myDataView.noValues()==1);
1341 assert(myDataView.getShape().size()==0);
1342 assert(myDataView()==1.0);
1343
1344 myDataView = myData.getDataPointByTag(3);
1345 assert(!myDataView.isEmpty());
1346 assert(myDataView.getOffset()==3);
1347 assert(myDataView.getRank()==0);
1348 assert(myDataView.noValues()==1);
1349 assert(myDataView.getShape().size()==0);
1350 assert(myDataView()==1.0);
1351
1352 myDataView = myData.getDefaultValue();
1353 assert(!myDataView.isEmpty());
1354 assert(myDataView.getOffset()==0);
1355 assert(myDataView.getRank()==0);
1356 assert(myDataView.noValues()==1);
1357 assert(myDataView.getShape().size()==0);
1358 assert(myDataView()==0.0);
1359
1360 // use a non-existent tag so we get a pointer to
1361 // the first element of the data array
1362 double* sampleData=myData.getSampleDataByTag(9);
1363 for (int i=0; i<myData.getLength(); i++) {
1364 if (i==0) {
1365 assert(sampleData[i]==0);
1366 } else {
1367 assert(sampleData[i]==1);
1368 }
1369 }
1370
1371 }
1372
1373 {
1374
1375 cout << "\tTest adding three keys with three values to default DataTagged." << endl;
1376 DataTagged myData;
1377
1378 DataTagged::TagListType keys;
1379 keys.push_back(1);
1380 keys.push_back(2);
1381 keys.push_back(3);
1382
1383 DataTagged::ValueListType values;
1384
1385 DataArrayView::ShapeType viewShape;
1386 DataArrayView::ValueType viewData1(1);
1387 viewData1[0]=1.0;
1388 DataArrayView::ValueType viewData2(1);
1389 viewData2[0]=2.0;
1390 DataArrayView::ValueType viewData3(1);
1391 viewData3[0]=3.0;
1392 DataArrayView myView1(viewData1,viewShape);
1393 DataArrayView myView2(viewData2,viewShape);
1394 DataArrayView myView3(viewData3,viewShape);
1395 values.push_back(myView1);
1396 values.push_back(myView2);
1397 values.push_back(myView3);
1398
1399 myData.addTaggedValues(keys,values);
1400
1401 assert(myData.isCurrentTag(1));
1402 assert(myData.isCurrentTag(2));
1403 assert(myData.isCurrentTag(3));
1404
1405 assert(myData.getTagLookup().size()==3);
1406
1407 assert(myData.getLength()==4);
1408
1409 // data-point 0 has tag number 1 by default
1410 assert(myData.getTagNumber(0)==1);
1411
1412 assert(myData.getPointOffset(0,0)==1);
1413
1414 DataArrayView myDataView = myData.getDataPoint(0,0);
1415 assert(!myDataView.isEmpty());
1416 assert(myDataView.getOffset()==1);
1417 assert(myDataView.getRank()==0);
1418 assert(myDataView.noValues()==1);
1419 assert(myDataView.getShape().size()==0);
1420 assert(myDataView()==1.0);
1421
1422 myDataView = myData.getDataPointByTag(1);
1423 assert(!myDataView.isEmpty());
1424 assert(myDataView.getOffset()==1);
1425 assert(myDataView.getRank()==0);
1426 assert(myDataView.noValues()==1);
1427 assert(myDataView.getShape().size()==0);
1428 assert(myDataView()==1.0);
1429
1430 myDataView = myData.getDataPointByTag(2);
1431 assert(!myDataView.isEmpty());
1432 assert(myDataView.getOffset()==2);
1433 assert(myDataView.getRank()==0);
1434 assert(myDataView.noValues()==1);
1435 assert(myDataView.getShape().size()==0);
1436 assert(myDataView()==2.0);
1437
1438 myDataView = myData.getDataPointByTag(3);
1439 assert(!myDataView.isEmpty());
1440 assert(myDataView.getOffset()==3);
1441 assert(myDataView.getRank()==0);
1442 assert(myDataView.noValues()==1);
1443 assert(myDataView.getShape().size()==0);
1444 assert(myDataView()==3.0);
1445
1446 myDataView = myData.getDefaultValue();
1447 assert(!myDataView.isEmpty());
1448 assert(myDataView.getOffset()==0);
1449 assert(myDataView.getRank()==0);
1450 assert(myDataView.noValues()==1);
1451 assert(myDataView.getShape().size()==0);
1452 assert(myDataView()==0.0);
1453
1454 // use a non-existent tag so we get a pointer to
1455 // the first element of the data array
1456 double* sampleData=myData.getSampleDataByTag(9);
1457 for (int i=0; i<myData.getLength(); i++) {
1458 assert(sampleData[i]==i);
1459 }
1460
1461 }
1462
1463 {
1464
1465 cout << "\tTest adding one key with empty value list to DataTagged with default value only." << endl;
1466
1467 DataArrayView::ShapeType viewShape;
1468 viewShape.push_back(3);
1469
1470 DataTagged::TagListType keys;
1471
1472 DataTagged::ValueListType values;
1473
1474 DataArrayView::ValueType viewData(3);
1475 for (int i=0;i<viewShape[0];i++) {
1476 viewData[i]=i;
1477 }
1478 DataArrayView myView(viewData,viewShape);
1479
1480 DataTagged myData(keys,values,myView,FunctionSpace());
1481
1482 keys.push_back(1);
1483 values.clear();
1484
1485 myData.addTaggedValues(keys,values);
1486
1487 assert(myData.isCurrentTag(1));
1488
1489 assert(myData.getTagLookup().size()==1);
1490
1491 assert(myData.getLength()==6);
1492
1493 // data-point 0 has tag number 1 by default
1494 assert(myData.getTagNumber(0)==1);
1495
1496 assert(myData.getPointOffset(0,0)==3);
1497
1498 DataArrayView myDataView = myData.getDataPoint(0,0);
1499 assert(myDataView==myView);
1500 assert(!myDataView.isEmpty());
1501 assert(myDataView.getOffset()==3);
1502 assert(myDataView.getRank()==1);
1503 assert(myDataView.noValues()==3);
1504 assert(myDataView.getShape().size()==1);
1505 assert(myDataView(0)==0);
1506 assert(myDataView(1)==1);
1507 assert(myDataView(2)==2);
1508
1509 myDataView = myData.getDataPointByTag(1);
1510 assert(myDataView==myView);
1511 assert(!myDataView.isEmpty());
1512 assert(myDataView.getOffset()==3);
1513 assert(myDataView.getRank()==1);
1514 assert(myDataView.noValues()==3);
1515 assert(myDataView.getShape().size()==1);
1516 assert(myDataView(0)==0);
1517 assert(myDataView(1)==1);
1518 assert(myDataView(2)==2);
1519
1520 myDataView = myData.getDefaultValue();
1521 assert(myDataView==myView);
1522 assert(!myDataView.isEmpty());
1523 assert(myDataView.getOffset()==0);
1524 assert(myDataView.getRank()==1);
1525 assert(myDataView.noValues()==3);
1526 assert(myDataView.getShape().size()==1);
1527 assert(myDataView(0)==0);
1528 assert(myDataView(1)==1);
1529 assert(myDataView(2)==2);
1530
1531 // use a non-existent tag so we get a pointer to
1532 // the first element of the data array
1533 double* sampleData=myData.getSampleDataByTag(9);
1534 for (int i=0; i<myData.getLength(); i++) {
1535 assert(sampleData[i]==i%3);
1536 }
1537
1538 }
1539
1540 {
1541
1542 cout << "\tTest adding one key with one value to DataTagged with default value only." << endl;
1543
1544 DataArrayView::ShapeType viewShape;
1545 viewShape.push_back(3);
1546
1547 DataTagged::TagListType keys;
1548
1549 DataTagged::ValueListType values;
1550
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 DataTagged myData(keys,values,myView,FunctionSpace());
1558
1559 keys.push_back(1);
1560
1561 DataArrayView::ValueType viewData1(3);
1562 for (int i=0;i<viewShape[0];i++) {
1563 viewData1[i]=i+3;
1564 }
1565 DataArrayView myView1(viewData1,viewShape);
1566 values.push_back(myView1);
1567
1568 myData.addTaggedValues(keys,values);
1569
1570 assert(myData.isCurrentTag(1));
1571
1572 assert(myData.getTagLookup().size()==1);
1573
1574 assert(myData.getLength()==6);
1575
1576 // data-point 0 has tag number 1 by default
1577 assert(myData.getTagNumber(0)==1);
1578
1579 assert(myData.getPointOffset(0,0)==3);
1580
1581 DataArrayView myDataView = myData.getDataPoint(0,0);
1582 assert(myDataView==myView1);
1583 assert(!myDataView.isEmpty());
1584 assert(myDataView.getOffset()==3);
1585 assert(myDataView.getRank()==1);
1586 assert(myDataView.noValues()==3);
1587 assert(myDataView.getShape().size()==1);
1588 assert(myDataView(0)==3);
1589 assert(myDataView(1)==4);
1590 assert(myDataView(2)==5);
1591
1592 myDataView = myData.getDataPointByTag(1);
1593 assert(myDataView==myView1);
1594 assert(!myDataView.isEmpty());
1595 assert(myDataView.getOffset()==3);
1596 assert(myDataView.getRank()==1);
1597 assert(myDataView.noValues()==3);
1598 assert(myDataView.getShape().size()==1);
1599 assert(myDataView(0)==3);
1600 assert(myDataView(1)==4);
1601 assert(myDataView(2)==5);
1602
1603 myDataView = myData.getDefaultValue();
1604 assert(myDataView==myView);
1605 assert(!myDataView.isEmpty());
1606 assert(myDataView.getOffset()==0);
1607 assert(myDataView.getRank()==1);
1608 assert(myDataView.noValues()==3);
1609 assert(myDataView.getShape().size()==1);
1610 assert(myDataView(0)==0);
1611 assert(myDataView(1)==1);
1612 assert(myDataView(2)==2);
1613
1614 // use a non-existent tag so we get a pointer to
1615 // the first element of the data array
1616 double* sampleData=myData.getSampleDataByTag(9);
1617 for (int i=0; i<myData.getLength(); i++) {
1618 assert(sampleData[i]==i);
1619 }
1620
1621 }
1622
1623 {
1624
1625 cout << "\tTest adding three keys with one value to DataTagged with default value only." << endl;
1626
1627 DataArrayView::ShapeType viewShape;
1628 viewShape.push_back(3);
1629
1630 DataTagged::TagListType keys;
1631
1632 DataTagged::ValueListType values;
1633
1634 DataArrayView::ValueType viewData(3);
1635 for (int i=0;i<viewShape[0];i++) {
1636 viewData[i]=i;
1637 }
1638 DataArrayView myView(viewData,viewShape);
1639
1640 DataTagged myData(keys,values,myView,FunctionSpace());
1641
1642 keys.push_back(1);
1643 keys.push_back(2);
1644 keys.push_back(3);
1645
1646 DataArrayView::ValueType viewData1(3);
1647 for (int i=0;i<viewShape[0];i++) {
1648 viewData1[i]=3;
1649 }
1650 DataArrayView myView1(viewData1,viewShape);
1651 values.push_back(myView1);
1652
1653 myData.addTaggedValues(keys,values);
1654
1655 assert(myData.isCurrentTag(1));
1656 assert(myData.isCurrentTag(2));
1657 assert(myData.isCurrentTag(3));
1658
1659 assert(myData.getTagLookup().size()==3);
1660
1661 assert(myData.getLength()==12);
1662
1663 // data-point 0 has tag number 1 by default
1664 assert(myData.getTagNumber(0)==1);
1665
1666 assert(myData.getPointOffset(0,0)==3);
1667
1668 DataArrayView myDataView = myData.getDataPoint(0,0);
1669 assert(myDataView==myView1);
1670 assert(!myDataView.isEmpty());
1671 assert(myDataView.getOffset()==3);
1672 assert(myDataView.getRank()==1);
1673 assert(myDataView.noValues()==3);
1674 assert(myDataView.getShape().size()==1);
1675 assert(myDataView(0)==3);
1676 assert(myDataView(1)==3);
1677 assert(myDataView(2)==3);
1678
1679 myDataView = myData.getDataPointByTag(1);
1680 assert(myDataView==myView1);
1681 assert(!myDataView.isEmpty());
1682 assert(myDataView.getOffset()==3);
1683 assert(myDataView.getRank()==1);
1684 assert(myDataView.noValues()==3);
1685 assert(myDataView.getShape().size()==1);
1686 assert(myDataView(0)==3);
1687 assert(myDataView(1)==3);
1688 assert(myDataView(2)==3);
1689
1690 myDataView = myData.getDataPointByTag(2);
1691 assert(myDataView==myView1);
1692 assert(!myDataView.isEmpty());
1693 assert(myDataView.getOffset()==6);
1694 assert(myDataView.getRank()==1);
1695 assert(myDataView.noValues()==3);
1696 assert(myDataView.getShape().size()==1);
1697 assert(myDataView(0)==3);
1698 assert(myDataView(1)==3);
1699 assert(myDataView(2)==3);
1700
1701 myDataView = myData.getDataPointByTag(3);
1702 assert(myDataView==myView1);
1703 assert(!myDataView.isEmpty());
1704 assert(myDataView.getOffset()==9);
1705 assert(myDataView.getRank()==1);
1706 assert(myDataView.noValues()==3);
1707 assert(myDataView.getShape().size()==1);
1708 assert(myDataView(0)==3);
1709 assert(myDataView(1)==3);
1710 assert(myDataView(2)==3);
1711
1712 myDataView = myData.getDefaultValue();
1713 assert(myDataView==myView);
1714 assert(!myDataView.isEmpty());
1715 assert(myDataView.getOffset()==0);
1716 assert(myDataView.getRank()==1);
1717 assert(myDataView.noValues()==3);
1718 assert(myDataView.getShape().size()==1);
1719 assert(myDataView(0)==0);
1720 assert(myDataView(1)==1);
1721 assert(myDataView(2)==2);
1722
1723 // use a non-existent tag so we get a pointer to
1724 // the first element of the data array
1725 double* sampleData=myData.getSampleDataByTag(9);
1726 for (int i=0; i<myData.getLength(); i++) {
1727 if (i<3) {
1728 assert(sampleData[i]==i);
1729 } else {
1730 assert(sampleData[i]==3);
1731 }
1732 }
1733
1734 }
1735
1736 {
1737
1738 cout << "\tTest adding three keys with three values to DataTagged with default value only." << endl;
1739
1740 DataArrayView::ShapeType viewShape;
1741 viewShape.push_back(3);
1742
1743 DataTagged::TagListType keys;
1744
1745 DataTagged::ValueListType values;
1746
1747 DataArrayView::ValueType viewData(3);
1748 for (int i=0;i<viewShape[0];i++) {
1749 viewData[i]=i;
1750 }
1751 DataArrayView myView(viewData,viewShape);
1752
1753 DataTagged myData(keys,values,myView,FunctionSpace());
1754
1755 keys.push_back(1);
1756 keys.push_back(2);
1757 keys.push_back(3);
1758
1759 DataArrayView::ValueType viewData1(3);
1760 for (int i=0;i<viewShape[0];i++) {
1761 viewData1[i]=i+1;
1762 }
1763 DataArrayView myView1(viewData1,viewShape);
1764 values.push_back(myView1);
1765
1766 DataArrayView::ValueType viewData2(3);
1767 for (int i=0;i<viewShape[0];i++) {
1768 viewData2[i]=i+2;
1769 }
1770 DataArrayView myView2(viewData2,viewShape);
1771 values.push_back(myView2);
1772
1773 DataArrayView::ValueType viewData3(3);
1774 for (int i=0;i<viewShape[0];i++) {
1775 viewData3[i]=i+3;
1776 }
1777 DataArrayView myView3(viewData3,viewShape);
1778 values.push_back(myView3);
1779
1780 myData.addTaggedValues(keys,values);
1781
1782 assert(myData.isCurrentTag(1));
1783 assert(myData.isCurrentTag(2));
1784 assert(myData.isCurrentTag(3));
1785
1786 assert(myData.getTagLookup().size()==3);
1787
1788 assert(myData.getLength()==12);
1789
1790 // data-point 0 has tag number 1 by default
1791 assert(myData.getTagNumber(0)==1);
1792
1793 assert(myData.getPointOffset(0,0)==3);
1794
1795 DataArrayView myDataView = myData.getDataPoint(0,0);
1796 assert(myDataView==myView1);
1797 assert(!myDataView.isEmpty());
1798 assert(myDataView.getOffset()==3);
1799 assert(myDataView.getRank()==1);
1800 assert(myDataView.noValues()==3);
1801 assert(myDataView.getShape().size()==1);
1802 assert(myDataView(0)==1);
1803 assert(myDataView(1)==2);
1804 assert(myDataView(2)==3);
1805
1806 myDataView = myData.getDataPointByTag(1);
1807 assert(myDataView==myView1);
1808 assert(!myDataView.isEmpty());
1809 assert(myDataView.getOffset()==3);
1810 assert(myDataView.getRank()==1);
1811 assert(myDataView.noValues()==3);
1812 assert(myDataView.getShape().size()==1);
1813 assert(myDataView(0)==1);
1814 assert(myDataView(1)==2);
1815 assert(myDataView(2)==3);
1816
1817 myDataView = myData.getDataPointByTag(2);
1818 assert(myDataView==myView2);
1819 assert(!myDataView.isEmpty());
1820 assert(myDataView.getOffset()==6);
1821 assert(myDataView.getRank()==1);
1822 assert(myDataView.noValues()==3);
1823 assert(myDataView.getShape().size()==1);
1824 assert(myDataView(0)==2);
1825 assert(myDataView(1)==3);
1826 assert(myDataView(2)==4);
1827
1828 myDataView = myData.getDataPointByTag(3);
1829 assert(myDataView==myView3);
1830 assert(!myDataView.isEmpty());
1831 assert(myDataView.getOffset()==9);
1832 assert(myDataView.getRank()==1);
1833 assert(myDataView.noValues()==3);
1834 assert(myDataView.getShape().size()==1);
1835 assert(myDataView(0)==3);
1836 assert(myDataView(1)==4);
1837 assert(myDataView(2)==5);
1838
1839 myDataView = myData.getDefaultValue();
1840 assert(myDataView==myView);
1841 assert(!myDataView.isEmpty());
1842 assert(myDataView.getOffset()==0);
1843 assert(myDataView.getRank()==1);
1844 assert(myDataView.noValues()==3);
1845 assert(myDataView.getShape().size()==1);
1846 assert(myDataView(0)==0);
1847 assert(myDataView(1)==1);
1848 assert(myDataView(2)==2);
1849
1850 // use a non-existent tag so we get a pointer to
1851 // the first element of the data array
1852 double* sampleData=myData.getSampleDataByTag(9);
1853 for (int i=0; i<myData.getLength(); i++) {
1854 if (i<3) {
1855 assert(sampleData[i]==i);
1856 } else if ((i>=3) && (i<6)) {
1857 assert(sampleData[i]==i-2);
1858 } else if ((i>=6) && (i<9)) {
1859 assert(sampleData[i]==i-4);
1860 } else {
1861 assert(sampleData[i]==i-6);
1862 }
1863 }
1864
1865 }
1866
1867 {
1868
1869 cout << "\tTest adding one key with empty value list to DataTagged with three tags." << endl;
1870
1871 DataTagged::TagListType keys;
1872 keys.push_back(1);
1873 keys.push_back(2);
1874 keys.push_back(3);
1875
1876 DataTagged::ValueListType values;
1877
1878 DataArrayView::ShapeType viewShape;
1879 viewShape.push_back(3);
1880
1881 // default value
1882 DataArrayView::ValueType viewData(3);
1883 for (int i=0;i<viewShape[0];i++) {
1884 viewData[i]=i;
1885 }
1886 DataArrayView myView(viewData,viewShape);
1887
1888 // value for tag "1"
1889 DataArray eOne(myView);
1890 for (int i=0;i<eOne.getView().getShape()[0];i++) {
1891 eOne.getView()(i)=i+1.0;
1892 }
1893 values.push_back(eOne.getView());
1894
1895 // value for tag "2"
1896 DataArray eTwo(myView);
1897 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1898 eTwo.getView()(i)=i+2.0;
1899 }
1900 values.push_back(eTwo.getView());
1901
1902 // value for tag "3"
1903 DataArray eThree(myView);
1904 for (int i=0;i<eThree.getView().getShape()[0];i++) {
1905 eThree.getView()(i)=i+3.0;
1906 }
1907 values.push_back(eThree.getView());
1908
1909 DataTagged myData(keys,values,myView,FunctionSpace());
1910
1911 keys.clear();
1912 keys.push_back(4);
1913 values.clear();
1914
1915 myData.addTaggedValues(keys,values);
1916
1917 assert(myData.isCurrentTag(4));
1918
1919 assert(myData.getTagLookup().size()==4);
1920
1921 assert(myData.getLength()==15);
1922
1923 DataArrayView myDataView = myData.getDataPointByTag(4);
1924 assert(myDataView==myView);
1925 assert(!myDataView.isEmpty());
1926 assert(myDataView.getOffset()==12);
1927 assert(myDataView.getRank()==1);
1928 assert(myDataView.noValues()==3);
1929 assert(myDataView.getShape().size()==1);
1930 assert(myDataView(0)==0);
1931 assert(myDataView(1)==1);
1932 assert(myDataView(2)==2);
1933
1934 // use a non-existent tag so we get a pointer to
1935 // the first element of the data array
1936 double* sampleData=myData.getSampleDataByTag(9);
1937 for (int i=0; i<myData.getLength(); i++) {
1938 if (i<3) {
1939 assert(sampleData[i]==i);
1940 } else if ((i>=3) && (i<6)) {
1941 assert(sampleData[i]==i-2);
1942 } else if ((i>=6) && (i<9)) {
1943 assert(sampleData[i]==i-4);
1944 } else if ((i>=9) && (i<12)) {
1945 assert(sampleData[i]==i-6);
1946 } else {
1947 assert(sampleData[i]==i-12);
1948 }
1949 }
1950
1951 }
1952
1953 {
1954
1955 cout << "\tTest adding one key with one value to DataTagged with three tags." << endl;
1956
1957 DataTagged::TagListType keys;
1958 keys.push_back(1);
1959 keys.push_back(2);
1960 keys.push_back(3);
1961
1962 DataTagged::ValueListType values;
1963
1964 DataArrayView::ShapeType viewShape;
1965 viewShape.push_back(3);
1966
1967 // default value
1968 DataArrayView::ValueType viewData(3);
1969 for (int i=0;i<viewShape[0];i++) {
1970 viewData[i]=i;
1971 }
1972 DataArrayView myView(viewData,viewShape);
1973
1974 // value for tag "1"
1975 DataArray eOne(myView);
1976 for (int i=0;i<eOne.getView().getShape()[0];i++) {
1977 eOne.getView()(i)=i+1.0;
1978 }
1979 values.push_back(eOne.getView());
1980
1981 // value for tag "2"
1982 DataArray eTwo(myView);
1983 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1984 eTwo.getView()(i)=i+2.0;
1985 }
1986 values.push_back(eTwo.getView());
1987
1988 // value for tag "3"
1989 DataArray eThree(myView);
1990 for (int i=0;i<eThree.getView().getShape()[0];i++) {
1991 eThree.getView()(i)=i+3.0;
1992 }
1993 values.push_back(eThree.getView());
1994
1995 DataTagged myData(keys,values,myView,FunctionSpace());
1996
1997 keys.clear();
1998 keys.push_back(4);
1999
2000 values.clear();
2001 // value for tag "4"
2002 DataArray eFour(myView);
2003 for (int i=0;i<eFour.getView().getShape()[0];i++) {
2004 eFour.getView()(i)=i+4.0;
2005 }
2006 values.push_back(eFour.getView());
2007
2008 myData.addTaggedValues(keys,values);
2009
2010 assert(myData.isCurrentTag(4));
2011
2012 assert(myData.getTagLookup().size()==4);
2013
2014 assert(myData.getLength()==15);
2015
2016 DataArrayView myDataView = myData.getDataPointByTag(4);
2017 assert(myDataView==eFour.getView());
2018 assert(!myDataView.isEmpty());
2019 assert(myDataView.getOffset()==12);
2020 assert(myDataView.getRank()==1);
2021 assert(myDataView.noValues()==3);
2022 assert(myDataView.getShape().size()==1);
2023 assert(myDataView(0)==4);
2024 assert(myDataView(1)==5);
2025 assert(myDataView(2)==6);
2026
2027 // use a non-existent tag so we get a pointer to
2028 // the first element of the data array
2029 double* sampleData=myData.getSampleDataByTag(9);
2030 for (int i=0; i<myData.getLength(); i++) {
2031 if (i<3) {
2032 assert(sampleData[i]==i);
2033 } else if ((i>=3) && (i<6)) {
2034 assert(sampleData[i]==i-2);
2035 } else if ((i>=6) && (i<9)) {
2036 assert(sampleData[i]==i-4);
2037 } else if ((i>=9) && (i<12)) {
2038 assert(sampleData[i]==i-6);
2039 } else {
2040 assert(sampleData[i]==i-8);
2041 }
2042 }
2043
2044 }
2045
2046 {
2047
2048 cout << "\tTest adding three keys with one value to DataTagged with three tags." << endl;
2049
2050 DataTagged::TagListType keys;
2051 keys.push_back(1);
2052 keys.push_back(2);
2053 keys.push_back(3);
2054
2055 DataTagged::ValueListType values;
2056
2057 DataArrayView::ShapeType viewShape;
2058 viewShape.push_back(3);
2059
2060 // default value
2061 DataArrayView::ValueType viewData(3);
2062 for (int i=0;i<viewShape[0];i++) {
2063 viewData[i]=i;
2064 }
2065 DataArrayView myView(viewData,viewShape);
2066
2067 // value for tag "1"
2068 DataArray eOne(myView);
2069 for (int i=0;i<eOne.getView().getShape()[0];i++) {
2070 eOne.getView()(i)=i+1.0;
2071 }
2072 values.push_back(eOne.getView());
2073
2074 // value for tag "2"
2075 DataArray eTwo(myView);
2076 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
2077 eTwo.getView()(i)=i+2.0;
2078 }
2079 values.push_back(eTwo.getView());
2080
2081 // value for tag "3"
2082 DataArray eThree(myView);
2083 for (int i=0;i<eThree.getView().getShape()[0];i++) {
2084 eThree.getView()(i)=i+3.0;
2085 }
2086 values.push_back(eThree.getView());
2087
2088 DataTagged myData(keys,values,myView,FunctionSpace());
2089
2090 keys.clear();
2091 keys.push_back(4);
2092 keys.push_back(5);
2093 keys.push_back(6);
2094
2095 values.clear();
2096 // value for tags "4", "5" and "6"
2097 DataArray eFour(myView);
2098 for (int i=0;i<eFour.getView().getShape()[0];i++) {
2099 eFour.getView()(i)=i+4.0;
2100 }
2101 values.push_back(eFour.getView());
2102
2103 myData.addTaggedValues(keys,values);
2104
2105 assert(myData.isCurrentTag(4));
2106 assert(myData.isCurrentTag(5));
2107 assert(myData.isCurrentTag(6));
2108
2109 assert(myData.getTagLookup().size()==6);
2110
2111 assert(myData.getLength()==21);
2112
2113 DataArrayView myDataView = myData.getDataPointByTag(4);
2114 assert(myDataView==eFour.getView());
2115 assert(!myDataView.isEmpty());
2116 assert(myDataView.getOffset()==12);
2117 assert(myDataView.getRank()==1);
2118 assert(myDataView.noValues()==3);
2119 assert(myDataView.getShape().size()==1);
2120 assert(myDataView(0)==4);
2121 assert(myDataView(1)==5);
2122 assert(myDataView(2)==6);
2123
2124 myDataView = myData.getDataPointByTag(5);
2125 assert(myDataView==eFour.getView());
2126 assert(!myDataView.isEmpty());
2127 assert(myDataView.getOffset()==15);
2128 assert(myDataView.getRank()==1);
2129 assert(myDataView.noValues()==3);
2130 assert(myDataView.getShape().size()==1);
2131 assert(myDataView(0)==4);
2132 assert(myDataView(1)==5);
2133 assert(myDataView(2)==6);
2134
2135 myDataView = myData.getDataPointByTag(6);
2136 assert(myDataView==eFour.getView());
2137 assert(!myDataView.isEmpty());
2138 assert(myDataView.getOffset()==18);
2139 assert(myDataView.getRank()==1);
2140 assert(myDataView.noValues()==3);
2141 assert(myDataView.getShape().size()==1);
2142 assert(myDataView(0)==4);
2143 assert(myDataView(1)==5);
2144 assert(myDataView(2)==6);
2145
2146 // use a non-existent tag so we get a pointer to
2147 // the first element of the data array
2148 double* sampleData=myData.getSampleDataByTag(9);
2149 for (int i=0; i<myData.getLength(); i++) {
2150 if (i<3) {
2151 assert(sampleData[i]==i);
2152 } else if ((i>=3) && (i<6)) {
2153 assert(sampleData[i]==i-2);
2154 } else if ((i>=6) && (i<9)) {
2155 assert(sampleData[i]==i-4);
2156 } else if ((i>=9) && (i<12)) {
2157 assert(sampleData[i]==i-6);
2158 } else if ((i>=12) && (i<15)) {
2159 assert(sampleData[i]==i-8);
2160 } else if ((i>=15) && (i<18)) {
2161 assert(sampleData[i]==i-11);
2162 } else {
2163 assert(sampleData[i]==i-14);
2164 }
2165 }
2166
2167 }
2168
2169 {
2170
2171 cout << "\tTest adding three keys with three values to DataTagged with three tags." << endl;
2172
2173 DataTagged::TagListType keys;
2174 keys.push_back(1);
2175 keys.push_back(2);
2176 keys.push_back(3);
2177
2178 DataTagged::ValueListType values;
2179
2180 DataArrayView::ShapeType viewShape;
2181 viewShape.push_back(3);
2182
2183 // default value
2184 DataArrayView::ValueType viewData(3);
2185 for (int i=0;i<viewShape[0];i++) {
2186 viewData[i]=i;
2187 }
2188 DataArrayView myView(viewData,viewShape);
2189
2190 // value for tag "1"
2191 DataArray eOne(myView);
2192 for (int i=0;i<eOne.getView().getShape()[0];i++) {
2193 eOne.getView()(i)=i+1.0;
2194 }
2195 values.push_back(eOne.getView());
2196
2197 // value for tag "2"
2198 DataArray eTwo(myView);
2199 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
2200 eTwo.getView()(i)=i+2.0;
2201 }
2202 values.push_back(eTwo.getView());
2203
2204 // value for tag "3"
2205 DataArray eThree(myView);
2206 for (int i=0;i<eThree.getView().getShape()[0];i++) {
2207 eThree.getView()(i)=i+3.0;
2208 }
2209 values.push_back(eThree.getView());
2210
2211 DataTagged myData(keys,values,myView,FunctionSpace());
2212
2213 keys.clear();
2214 keys.push_back(4);
2215 keys.push_back(5);
2216 keys.push_back(6);
2217
2218 values.clear();
2219
2220 // value for tag "4"
2221 DataArray eFour(myView);
2222 for (int i=0;i<eFour.getView().getShape()[0];i++) {
2223 eFour.getView()(i)=i+4.0;
2224 }
2225 values.push_back(eFour.getView());
2226
2227 // value for tag "5"
2228 DataArray eFive(myView);
2229 for (int i=0;i<eFive.getView().getShape()[0];i++) {
2230 eFive.getView()(i)=i+5.0;
2231 }
2232 values.push_back(eFive.getView());
2233
2234 // value for tag "6"
2235 DataArray eSix(myView);
2236 for (int i=0;i<eSix.getView().getShape()[0];i++) {
2237 eSix.getView()(i)=i+6.0;
2238 }
2239 values.push_back(eSix.getView());
2240
2241 myData.addTaggedValues(keys,values);
2242
2243 assert(myData.isCurrentTag(4));
2244 assert(myData.isCurrentTag(5));
2245 assert(myData.isCurrentTag(6));
2246
2247 assert(myData.getTagLookup().size()==6);
2248
2249 assert(myData.getLength()==21);
2250
2251 DataArrayView myDataView = myData.getDataPointByTag(4);
2252 assert(myDataView==eFour.getView());
2253 assert(!myDataView.isEmpty());
2254 assert(myDataView.getOffset()==12);
2255 assert(myDataView.getRank()==1);
2256 assert(myDataView.noValues()==3);
2257 assert(myDataView.getShape().size()==1);
2258 assert(myDataView(0)==4);
2259 assert(myDataView(1)==5);
2260 assert(myDataView(2)==6);
2261
2262 myDataView = myData.getDataPointByTag(5);
2263 assert(myDataView==eFive.getView());
2264 assert(!myDataView.isEmpty());
2265 assert(myDataView.getOffset()==15);
2266 assert(myDataView.getRank()==1);
2267 assert(myDataView.noValues()==3);
2268 assert(myDataView.getShape().size()==1);
2269 assert(myDataView(0)==5);
2270 assert(myDataView(1)==6);
2271 assert(myDataView(2)==7);
2272
2273 myDataView = myData.getDataPointByTag(6);
2274 assert(myDataView==eSix.getView());
2275 assert(!myDataView.isEmpty());
2276 assert(myDataView.getOffset()==18);
2277 assert(myDataView.getRank()==1);
2278 assert(myDataView.noValues()==3);
2279 assert(myDataView.getShape().size()==1);
2280 assert(myDataView(0)==6);
2281 assert(myDataView(1)==7);
2282 assert(myDataView(2)==8);
2283
2284 // use a non-existent tag so we get a pointer to
2285 // the first element of the data array
2286 double* sampleData=myData.getSampleDataByTag(9);
2287 for (int i=0; i<myData.getLength(); i++) {
2288 if (i<3) {
2289 assert(sampleData[i]==i);
2290 } else if ((i>=3) && (i<6)) {
2291 assert(sampleData[i]==i-2);
2292 } else if ((i>=6) && (i<9)) {
2293 assert(sampleData[i]==i-4);
2294 } else if ((i>=9) && (i<12)) {
2295 assert(sampleData[i]==i-6);
2296 } else if ((i>=12) && (i<15)) {
2297 assert(sampleData[i]==i-8);
2298 } else if ((i>=15) && (i<18)) {
2299 assert(sampleData[i]==i-10);
2300 } else {
2301 assert(sampleData[i]==i-12);
2302 }
2303 }
2304
2305 }
2306
2307 }
2308
2309 void DataTaggedTestCase::testSetTaggedValue() {
2310
2311 cout << endl;
2312
2313 {
2314
2315 cout << "\tTest setting key in DataTagged with three tags." << endl;
2316
2317 DataTagged::TagListType keys;
2318 keys.push_back(1);
2319 keys.push_back(2);
2320 keys.push_back(3);
2321
2322 DataTagged::ValueListType values;
2323
2324 DataArrayView::ShapeType viewShape;
2325 viewShape.push_back(3);
2326
2327 // default value
2328 DataArrayView::ValueType viewData(3);
2329 for (int i=0;i<viewShape[0];i++) {
2330 viewData[i]=i;
2331 }
2332 DataArrayView myView(viewData,viewShape);
2333
2334 // value for tag "1"
2335 DataArray eOne(myView);
2336 for (int i=0;i<eOne.getView().getShape()[0];i++) {
2337 eOne.getView()(i)=i+1.0;
2338 }
2339 values.push_back(eOne.getView());
2340
2341 // value for tag "2"
2342 DataArray eTwo(myView);
2343 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
2344 eTwo.getView()(i)=i+2.0;
2345 }
2346 values.push_back(eTwo.getView());
2347
2348 // value for tag "3"
2349 DataArray eThree(myView);
2350 for (int i=0;i<eThree.getView().getShape()[0];i++) {
2351 eThree.getView()(i)=i+3.0;
2352 }
2353 values.push_back(eThree.getView());
2354
2355 DataTagged myData(keys,values,myView,FunctionSpace());
2356
2357 // new value for tag "2"
2358 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
2359 eTwo.getView()(i)=i+5.0;
2360 }
2361
2362 myData.setTaggedValue(2,eTwo.getView());
2363
2364 assert(myData.isCurrentTag(2));
2365
2366 assert(myData.getTagLookup().size()==3);
2367
2368 assert(myData.getLength()==12);
2369
2370 DataArrayView myDataView = myData.getDataPointByTag(2);
2371 assert(myDataView==eTwo.getView());
2372 assert(!myDataView.isEmpty());
2373 assert(myDataView.getOffset()==6);
2374 assert(myDataView.getRank()==1);
2375 assert(myDataView.noValues()==3);
2376 assert(myDataView.getShape().size()==1);
2377 assert(myDataView(0)==5);
2378 assert(myDataView(1)==6);
2379 assert(myDataView(2)==7);
2380
2381 // use a non-existent tag so we get a pointer to
2382 // the first element of the data array
2383 double* sampleData=myData.getSampleDataByTag(9);
2384 for (int i=0; i<myData.getLength(); i++) {
2385 if (i<3) {
2386 assert(sampleData[i]==i);
2387 } else if ((i>=3) && (i<6)) {
2388 assert(sampleData[i]==i-2);
2389 } else if ((i>=6) && (i<9)) {
2390 assert(sampleData[i]==i-1);
2391 } else {
2392 assert(sampleData[i]==i-6);
2393 }
2394 }
2395
2396 }
2397
2398 }
2399
2400 void DataTaggedTestCase::testAll() {
2401
2402 cout << endl;
2403
2404 {
2405
2406 cout << "\tTest default DataTagged." << endl;
2407 DataTagged myData;
2408
2409 //cout << myData.toString() << endl;
2410
2411 assert(myData.getNumSamples()==1);
2412 assert(myData.getNumDPPSample()==1);
2413
2414 assert(myData.validSamplePointNo(0));
2415 assert(myData.validSampleNo(0));
2416 assert(!myData.validSamplePointNo(1));
2417 assert(!myData.validSampleNo(1));
2418
2419 // data-point 0 has tag number 1 by default
2420 assert(myData.getTagNumber(0)==1);
2421
2422 assert(!myData.isCurrentTag(1));
2423
2424 assert(myData.getTagLookup().size()==0);
2425
2426 assert(myData.getLength()==1);
2427
2428 assert(myData.getPointOffset(0,0)==0);
2429
2430 DataArrayView myDataView = myData.getDataPoint(0,0);
2431 assert(!myDataView.isEmpty());
2432 assert(myDataView.getOffset()==0);
2433 assert(myDataView.getRank()==0);
2434 assert(myDataView.noValues()==1);
2435 assert(myDataView.getShape().size()==0);
2436 assert(myDataView()==0.0);
2437
2438 // Test non-existent tag returns the default value.
2439 myDataView = myData.getDataPointByTag(1);
2440 assert(!myDataView.isEmpty());
2441 assert(myDataView.getOffset()==0);
2442 assert(myDataView.getRank()==0);
2443 assert(myDataView.noValues()==1);
2444 assert(myDataView.getShape().size()==0);
2445 assert(myDataView()==0.0);
2446
2447 myDataView = myData.getDefaultValue();
2448 assert(!myDataView.isEmpty());
2449 assert(myDataView.getOffset()==0);
2450 assert(myDataView.getRank()==0);
2451 assert(myDataView.noValues()==1);
2452 assert(myDataView.getShape().size()==0);
2453 assert(myDataView()==0.0);
2454
2455 // use a non-existent tag so we get a pointer to
2456 // the first element of the data array
2457 double* sampleData=myData.getSampleDataByTag(9);
2458 for (int i=0; i<myData.getLength(); i++) {
2459 assert(sampleData[i]==i);
2460 }
2461 sampleData=myData.getSampleData(0);
2462 for (int i=0; i<myDataView.noValues(); i++) {
2463 assert(sampleData[i]==i);
2464 }
2465
2466 }
2467
2468 {
2469
2470 cout << "\tTest DataTagged with default value only." << endl;
2471
2472 DataArrayView::ShapeType viewShape;
2473 viewShape.push_back(3);
2474
2475 DataTagged::TagListType keys;
2476
2477 DataTagged::ValueListType values;
2478
2479 DataArrayView::ValueType viewData(3);
2480 for (int i=0;i<viewShape[0];i++) {
2481 viewData[i]=i;
2482 }
2483 DataArrayView myView(viewData,viewShape);
2484
2485 DataTagged myData(keys,values,myView,FunctionSpace());
2486
2487 //cout << myData.toString() << endl;
2488
2489 assert(myData.getNumSamples()==1);
2490 assert(myData.getNumDPPSample()==1);
2491
2492 assert(myData.validSamplePointNo(0));
2493 assert(myData.validSampleNo(0));
2494 assert(!myData.validSamplePointNo(1));
2495 assert(!myData.validSampleNo(1));
2496
2497 // data-point 0 has tag number 1 by default
2498 assert(myData.getTagNumber(0)==1);
2499
2500 assert(!myData.isCurrentTag(1));
2501
2502 assert(myData.getTagLookup().size()==0);
2503
2504 assert(myData.getLength()==3);
2505
2506 assert(myData.getPointOffset(0,0)==0);
2507
2508 DataArrayView myDataView = myData.getDataPoint(0,0);
2509 assert(myDataView==myView);
2510 assert(!myDataView.isEmpty());
2511 assert(myDataView.getOffset()==0);
2512 assert(myDataView.getRank()==1);
2513 assert(myDataView.noValues()==3);
2514 assert(myDataView.getShape().size()==1);
2515 assert(myDataView(0)==0);
2516 assert(myDataView(1)==1);
2517 assert(myDataView(2)==2);
2518
2519 // Test non-existent tag returns the default value.
2520 myDataView = myData.getDataPointByTag(1);
2521 assert(myDataView==myView);
2522 assert(!myDataView.isEmpty());
2523 assert(myDataView.getOffset()==0);
2524 assert(myDataView.getRank()==1);
2525 assert(myDataView.noValues()==3);
2526 assert(myDataView.getShape().size()==1);
2527 assert(myDataView(0)==0);
2528 assert(myDataView(1)==1);
2529 assert(myDataView(2)==2);
2530
2531 myDataView = myData.getDefaultValue();
2532 assert(myDataView==myView);
2533 assert(!myDataView.isEmpty());
2534 assert(myDataView.getOffset()==0);
2535 assert(myDataView.getRank()==1);
2536 assert(myDataView.noValues()==3);
2537 assert(myDataView.getShape().size()==1);
2538 assert(myDataView(0)==0);
2539 assert(myDataView(1)==1);
2540 assert(myDataView(2)==2);
2541
2542 // use a non-existent tag so we get a pointer to
2543 // the first element of the data array
2544 double* sampleData=myData.getSampleDataByTag(9);
2545 for (int i=0; i<myData.getLength(); i++) {
2546 assert(sampleData[i]==i);
2547 }
2548 sampleData=myData.getSampleDataByTag(0);
2549 for (int i=0; i<myDataView.noValues(); i++) {
2550 assert(sampleData[i]==i);
2551 }
2552
2553 }
2554
2555 {
2556
2557 cout << "\tTest DataTagged with one tag." << endl;
2558
2559 // the one data-point has tag value "1"
2560
2561 DataTagged::TagListType keys;
2562 keys.push_back(1);
2563
2564 DataTagged::ValueListType values;
2565
2566 DataArrayView::ShapeType viewShape;
2567 viewShape.push_back(3);
2568
2569 // default value
2570 DataArrayView::ValueType viewData(3);
2571 for (int i=0;i<viewShape[0];i++) {
2572 viewData[i]=i;
2573 }
2574 DataArrayView myView(viewData,viewShape);
2575
2576 // value for tag "1"
2577 DataArray eOne(myView);
2578 for (int i=0;i<eOne.getView().getShape()[0];i++) {
2579 eOne.getView()(i)=i+1.0;
2580 }
2581 values.push_back(eOne.getView());
2582
2583 DataTagged myData(keys,values,myView,FunctionSpace());
2584
2585 //cout << myData.toString() << endl;
2586
2587 assert(myData.getNumSamples()==1);
2588 assert(myData.getNumDPPSample()==1);
2589
2590 assert(myData.validSamplePointNo(0));
2591 assert(myData.validSampleNo(0));
2592 assert(!myData.validSamplePointNo(1));
2593 assert(!myData.validSampleNo(1));
2594
2595 // data-point 0 has tag number 1 by default
2596 assert(myData.getTagNumber(0)==1);
2597
2598 assert(!myData.isCurrentTag(0));
2599 assert(myData.isCurrentTag(1));
2600
2601 assert(myData.getTagLookup().size()==1);
2602
2603 assert(myData.getLength()==6);
2604
2605 assert(myData.getPointOffset(0,0)==3);
2606
2607 DataArrayView myDataView = myData.getDataPoint(0,0);
2608 assert(myDataView==eOne.getView());
2609 assert(!myDataView.isEmpty());
2610 assert(myDataView.getOffset()==3);
2611 assert(myDataView.getRank()==1);
2612 assert(myDataView.noValues()==3);
2613 assert(myDataView.getShape().size()==1);
2614 assert(myDataView(0)==1);
2615 assert(myDataView(1)==2);
2616 assert(myDataView(2)==3);
2617
2618 myDataView = myData.getDataPointByTag(1);
2619 assert(myDataView==eOne.getView());
2620 assert(!myDataView.isEmpty());
2621 assert(myDataView.getOffset()==3);
2622 assert(myDataView.getRank()==1);
2623 assert(myDataView.noValues()==3);
2624 assert(myDataView.getShape().size()==1);
2625 assert(myDataView(0)==1);
2626 assert(myDataView(1)==2);
2627 assert(myDataView(2)==3);
2628
2629 // Test non-existent tag returns the default value.
2630 myDataView = myData.getDataPointByTag(9);
2631 assert(myDataView==myView);
2632 assert(!myDataView.isEmpty());
2633 assert(myDataView.getOffset()==0);
2634 assert(myDataView.getRank()==1);
2635 assert(myDataView.noValues()==3);
2636 assert(myDataView.getShape().size()==1);
2637 assert(myDataView(0)==0);
2638 assert(myDataView(1)==1);
2639 assert(myDataView(2)==2);
2640
2641 myDataView = myData.getDefaultValue();
2642 assert(myDataView==myView);
2643 assert(!myDataView.isEmpty());
2644 assert(myDataView.getOffset()==0);
2645 assert(myDataView.getRank()==1);
2646 assert(myDataView.noValues()==3);
2647 assert(myDataView.getShape().size()==1);
2648 assert(myDataView(0)==0);
2649 assert(myDataView(1)==1);
2650 assert(myDataView(2)==2);
2651
2652 // use a non-existent tag so we get a pointer to
2653 // the first element of the data array
2654 double* sampleData=myData.getSampleDataByTag(9);
2655 for (int i=0; i<myData.getLength(); i++) {
2656 if (i<3) {
2657 assert(sampleData[i]==i);
2658 } else {
2659 assert(sampleData[i]==i-2);
2660 }
2661 }
2662 sampleData=myData.getSampleData(0);
2663 for (int i=0; i<myDataView.noValues(); i++) {
2664 assert(sampleData[i]==i+1);
2665 }
2666
2667 }
2668
2669 {
2670
2671 cout << "\tTest DataTagged with multiple tags." << endl;
2672
2673 // the one data-point has tag value "1"
2674
2675 DataTagged::TagListType keys;
2676 keys.push_back(1);
2677 keys.push_back(2);
2678 keys.push_back(3);
2679
2680 DataTagged::ValueListType values;
2681
2682 DataArrayView::ShapeType viewShape;
2683 viewShape.push_back(3);
2684
2685 // default value
2686 DataArrayView::ValueType viewData(3);
2687 for (int i=0;i<viewShape[0];i++) {
2688 viewData[i]=i;
2689 }
2690 DataArrayView myView(viewData,viewShape);
2691
2692 // value for tag "1"
2693 DataArray eOne(myView);
2694 for (int i=0;i<eOne.getView().getShape()[0];i++) {
2695 eOne.getView()(i)=i+1.0;
2696 }
2697 values.push_back(eOne.getView());
2698
2699 // value for tag "2"
2700 DataArray eTwo(myView);
2701 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
2702 eTwo.getView()(i)=i+2.0;
2703 }
2704 values.push_back(eTwo.getView());
2705
2706 // value for tag "3"
2707 DataArray eThree(myView);
2708 for (int i=0;i<eThree.getView().getShape()[0];i++) {
2709 eThree.getView()(i)=i+3.0;
2710 }
2711 values.push_back(eThree.getView());
2712
2713 DataTagged myData(keys,values,myView,FunctionSpace());
2714
2715 //cout << myData.toString() << endl;
2716
2717 assert(myData.getNumSamples()==1);
2718 assert(myData.getNumDPPSample()==1);
2719
2720 assert(myData.validSamplePointNo(0));
2721 assert(myData.validSampleNo(0));
2722 assert(!myData.validSamplePointNo(1));
2723 assert(!myData.validSampleNo(1));
2724
2725 // data-point 0 has tag number 1 by default
2726 assert(myData.getTagNumber(0)==1);
2727
2728 assert(!myData.isCurrentTag(0));
2729 assert(myData.isCurrentTag(1));
2730 assert(myData.isCurrentTag(2));
2731 assert(myData.isCurrentTag(3));
2732
2733 assert(myData.getTagLookup().size()==3);
2734
2735 assert(myData.getLength()==12);
2736
2737 assert(myData.getPointOffset(0,0)==3);
2738
2739 DataArrayView myDataView = myData.getDataPoint(0,0);
2740 assert(myDataView==eOne.getView());
2741 assert(!myDataView.isEmpty());
2742 assert(myDataView.getOffset()==3);
2743 assert(myDataView.getRank()==1);
2744 assert(myDataView.noValues()==3);
2745 assert(myDataView.getShape().size()==1);
2746 assert(myDataView(0)==1);
2747 assert(myDataView(1)==2);
2748 assert(myDataView(2)==3);
2749
2750 myDataView = myData.getDataPointByTag(1);
2751 assert(myDataView==eOne.getView());
2752 assert(!myDataView.isEmpty());
2753 assert(myDataView.getOffset()==3);
2754 assert(myDataView.getRank()==1);
2755 assert(myDataView.noValues()==3);
2756 assert(myDataView.getShape().size()==1);
2757 assert(myDataView(0)==1);
2758 assert(myDataView(1)==2);
2759 assert(myDataView(2)==3);
2760
2761 // Test non-existent tag returns the default value.
2762 myDataView = myData.getDataPointByTag(0);
2763 assert(myDataView==myView);
2764 assert(!myDataView.isEmpty());
2765 assert(myDataView.getOffset()==0);
2766 assert(myDataView.getRank()==1);
2767 assert(myDataView.noValues()==3);
2768 assert(myDataView.getShape().size()==1);
2769 assert(myDataView(0)==0);
2770 assert(myDataView(1)==1);
2771 assert(myDataView(2)==2);
2772
2773 myDataView = myData.getDefaultValue();
2774 assert(myDataView==myView);
2775 assert(!myDataView.isEmpty());
2776 assert(myDataView.getOffset()==0);
2777 assert(myDataView.getRank()==1);
2778 assert(myDataView.noValues()==3);
2779 assert(myDataView.getShape().size()==1);
2780 assert(myDataView(0)==0);
2781 assert(myDataView(1)==1);
2782 assert(myDataView(2)==2);
2783
2784 // Test data-points held for remaining tags
2785 myDataView = myData.getDataPointByTag(2);
2786 assert(myDataView==eTwo.getView());
2787 assert(!myDataView.isEmpty());
2788 assert(myDataView.getOffset()==6);
2789 assert(myDataView.getRank()==1);
2790 assert(myDataView.noValues()==3);
2791 assert(myDataView.getShape().size()==1);
2792 assert(myDataView(0)==2);
2793 assert(myDataView(1)==3);
2794 assert(myDataView(2)==4);
2795
2796 myDataView = myData.getDataPointByTag(3);
2797 assert(myDataView==eThree.getView());
2798 assert(!myDataView.isEmpty());
2799 assert(myDataView.getOffset()==9);
2800 assert(myDataView.getRank()==1);
2801 assert(myDataView.noValues()==3);
2802 assert(myDataView.getShape().size()==1);
2803 assert(myDataView(0)==3);
2804 assert(myDataView(1)==4);
2805 assert(myDataView(2)==5);
2806
2807 // use a non-existent tag so we get a pointer to
2808 // the first element of the data array
2809 double* sampleData=myData.getSampleDataByTag(9);
2810 for (int i=0; i<myData.getLength(); i++) {
2811 if (i<3) {
2812 assert(sampleData[i]==i);
2813 } else if ((i>=3) && (i<6)) {
2814 assert(sampleData[i]==i-2);
2815 } else if ((i>=6) && (i<9)) {
2816 assert(sampleData[i]==i-4);
2817 } else {
2818 assert(sampleData[i]==i-6);
2819 }
2820 }
2821 sampleData=myData.getSampleData(0);
2822 for (int i=0; i<myDataView.noValues(); i++) {
2823 assert(sampleData[i]==i+1);
2824 }
2825
2826 }
2827
2828 }
2829
2830 void DataTaggedTestCase::testCopyConstructors() {
2831
2832 cout << endl;
2833
2834 {
2835
2836 cout << "\tTest DataTagged copy constructor for DataTagged with multiple tags." << endl;
2837
2838 // the one data-point has tag value "1"
2839
2840 DataTagged::TagListType keys;
2841 keys.push_back(1);
2842 keys.push_back(2);
2843 keys.push_back(3);
2844
2845 DataTagged::ValueListType values;
2846
2847 DataArrayView::ShapeType viewShape;
2848 viewShape.push_back(3);
2849
2850 // default value
2851 DataArrayView::ValueType viewData(3);
2852 for (int i=0;i<viewShape[0];i++) {
2853 viewData[i]=i;
2854 }
2855 DataArrayView myView(viewData,viewShape);
2856
2857 // value for tag "1"
2858 DataArray eOne(myView);
2859 for (int i=0;i<eOne.getView().getShape()[0];i++) {
2860 eOne.getView()(i)=i+1.0;
2861 }
2862 values.push_back(eOne.getView());
2863
2864 // value for tag "2"
2865 DataArray eTwo(myView);
2866 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
2867 eTwo.getView()(i)=i+2.0;
2868 }
2869 values.push_back(eTwo.getView());
2870
2871 // value for tag "3"
2872 DataArray eThree(myView);
2873 for (int i=0;i<eThree.getView().getShape()[0];i++) {
2874 eThree.getView()(i)=i+3.0;
2875 }
2876 values.push_back(eThree.getView());
2877
2878 DataTagged myData(keys,values,myView,FunctionSpace());
2879
2880 DataTagged myDataCopy(myData);
2881
2882 //cout << myDataCopy.toString() << endl;
2883
2884 assert(myDataCopy.getNumSamples()==1);
2885 assert(myDataCopy.getNumDPPSample()==1);
2886
2887 assert(myDataCopy.validSamplePointNo(0));
2888 assert(myDataCopy.validSampleNo(0));
2889 assert(!myDataCopy.validSamplePointNo(1));
2890 assert(!myDataCopy.validSampleNo(1));
2891
2892 // data-point 0 has tag number 1 by default
2893 assert(myDataCopy.getTagNumber(0)==1);
2894
2895 assert(!myDataCopy.isCurrentTag(0));
2896 assert(myDataCopy.isCurrentTag(1));
2897 assert(myDataCopy.isCurrentTag(2));
2898 assert(myDataCopy.isCurrentTag(3));
2899
2900 assert(myDataCopy.getTagLookup().size()==3);
2901
2902 assert(myDataCopy.getLength()==12);
2903
2904 assert(myDataCopy.getPointOffset(0,0)==3);
2905
2906 DataArrayView myDataView = myDataCopy.getDataPoint(0,0);
2907 assert(myDataView==eOne.getView());
2908 assert(!myDataView.isEmpty());