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

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

Parent Directory Parent Directory | Revision Log Revision Log


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


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