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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1312 - (show annotations)
Mon Sep 24 06:18:44 2007 UTC (12 years, 4 months ago) by ksteube
Original Path: trunk/escript/test/DataTaggedTestCase.cpp
File size: 149208 byte(s)
The MPI branch is hereby closed. All future work should be in trunk.

Previously in revision 1295 I merged the latest changes to trunk into trunk-mpi-branch.
In this revision I copied all files from trunk-mpi-branch over the corresponding
trunk files. I did not use 'svn merge', it was a copy.

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