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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 533 - (show annotations)
Thu Feb 16 06:49:59 2006 UTC (13 years, 9 months ago) by jgs
Original Path: trunk/escript/test/DataTagged/DataTaggedTestCase.cpp
File size: 133582 byte(s)
testing setSlice with rank1 and rank 3 values and multiple tags

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