/[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 506 - (show annotations)
Thu Feb 9 06:06:02 2006 UTC (14 years ago) by jgs
Original Path: trunk/escript/test/DataTagged/DataTaggedTestCase.cpp
File size: 76068 byte(s)
extend testing for binary and unary operations
and add comprehensive testing for method getSampleDataByTag

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

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26