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

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

Parent Directory Parent Directory | Revision Log Revision Log


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


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