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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 502 - (show annotations)
Wed Feb 8 03:57:20 2006 UTC (13 years, 10 months ago) by jgs
Original Path: trunk/escript/test/DataTagged/DataTaggedTestCase.cpp
File size: 46433 byte(s)
add test for setTaggedValue

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
20 #include "DataTaggedTestCase.h"
21
22 #include "BinaryOp.h"
23 #include "UnaryOp.h"
24 #include "FunctionSpaceFactory.h"
25 #include "DataFactory.h"
26
27 #include <iostream>
28 #include <functional>
29 #include <algorithm>
30
31 using namespace CppUnitTest;
32 using namespace escript;
33 using namespace esysUtils;
34 using namespace std;
35
36 void DataTaggedTestCase::setUp() {
37 //
38 // This is called before each test is run
39
40 }
41
42 void DataTaggedTestCase::tearDown() {
43 //
44 // This is called after each test has been run
45
46 }
47
48 void DataTaggedTestCase::testReshape() {
49
50 cout << endl;
51
52 {
53 cout << "\tTest reshape of default constructed DataTagged to rank 1." << endl;
54 DataTagged value;
55 value.getPointDataView()()=1.0;
56 DataArrayView::ShapeType shape;
57 shape.push_back(2);
58 value.reshapeDataPoint(shape);
59 for (int i=0;i<shape[0];++i) {
60 assert(value.getDefaultValue()(i)==1);
61 }
62 }
63 {
64 cout << "\tTest reshape of default constructed DataTagged to rank 2." << endl;
65 DataTagged value;
66 value.getPointDataView()()=0.0;
67 DataArray vOne(1.0);
68 DataArray vTwo(2.0);
69 value.addTaggedValue(1,vOne.getView());
70 value.addTaggedValue(2,vTwo.getView());
71 DataArrayView::ShapeType shape;
72 shape.push_back(2);
73 shape.push_back(5);
74 value.reshapeDataPoint(shape);
75 for (int j=0;j<shape[1];++j) {
76 for (int i=0;i<shape[0];++i) {
77 assert(value.getDefaultValue()(i,j)==0.0);
78 assert(value.getDataPointByTag(1)(i,j)==vOne.getView()());
79 assert(value.getDataPointByTag(2)(i,j)==vTwo.getView()());
80 }
81 }
82 }
83 }
84
85 void DataTaggedTestCase::testOperations() {
86
87 cout << endl;
88
89 {
90 DataTagged left;
91 DataTagged right;
92
93 cout << "\tTest default DataTagged contains only a default value." << endl;
94 binaryOp(left,right,plus<double>());
95 assert(left.getPointDataView()()==0);
96 assert(right.getPointDataView()()==0);
97
98 cout << "\tTest binaryOp(plus)." << endl;
99 DataArray vOne(1.0);
100 DataArray vTwo(2.0);
101 right.addTaggedValue(1,vOne.getView());
102 right.addTaggedValue(2,vTwo.getView());
103 binaryOp(left,right,plus<double>());
104 assert(left.getPointDataView()()==0);
105 assert(left.getDataPointByTag(1)==vOne.getView());
106 assert(left.getDataPointByTag(2)==vTwo.getView());
107
108 cout << "\tTest binaryOp(multiplies)." << endl;
109 DataArray vZero(0.0);
110 right.setTaggedValue(1,vZero.getView());
111 right.setTaggedValue(2,vZero.getView());
112 binaryOp(left,right,multiplies<double>());
113 assert(left.getPointDataView()()==0);
114 assert(left.getDataPointByTag(1)==vZero.getView());
115 assert(left.getDataPointByTag(2)==vZero.getView());
116 }
117
118 {
119 DataArrayView::ShapeType viewShape;
120 viewShape.push_back(3);
121 DataArrayView::ValueType viewData(3);
122 DataTagged::TagListType keys;
123 DataTagged::ValueListType values;
124 for (int i=0;i<viewShape[0];++i) {
125 viewData[i]=i;
126 }
127 DataArrayView myView(viewData,viewShape);
128 cout << "\tCreate tagged data with no tag values just a default." << endl;
129 DataTagged left(keys,values,myView,FunctionSpace());
130 DataTagged right(keys,values,myView,FunctionSpace());
131 binaryOp(left,right,minus<double>());
132 for (int i=0;i<viewShape[0];++i) {
133 assert(left.getDefaultValue()(i)==0);
134 }
135 double mVal=10.0;
136 for (int i=0;i<viewShape[0];++i) {
137 viewData[i]=i*mVal;
138 }
139 cout << "\tTest binaryOp(minus) with the right hand side as a view." << endl;
140 binaryOp(left,myView,minus<double>());
141 for (int i=0;i<viewShape[0];++i) {
142 assert(left.getDefaultValue()(i)==-(i*mVal));
143 }
144 }
145
146 {
147 cout << "\tTest unaryOp(negate) on default DataTagged." << endl;
148 DataTagged data;
149 unaryOp(data,negate<double>());
150 assert(data.getDefaultValue()()==0);
151 DataArray vOne(1);
152 binaryOp(data,vOne.getView(),plus<double>());
153 assert(data.getDefaultValue()()==1);
154 unaryOp(data,negate<double>());
155 assert(data.getDefaultValue()()==-1);
156 }
157
158 {
159 cout << "\tTest unaryOp(negate) on DataTagged with 3 tags." << endl;
160 DataArrayView::ShapeType vShape;
161 vShape.push_back(3);
162 vShape.push_back(2);
163 vShape.push_back(1);
164 DataArray defData(vShape,0.0);
165 DataArrayView& defView=defData.getView();
166 DataArray tOneData(vShape,1.0);
167 DataArrayView& tOneView=tOneData.getView();
168 DataArray tTwoData(vShape,2.0);
169 DataArrayView& tTwoView=tTwoData.getView();
170 DataArray tThreeData(vShape,3.0);
171 DataArrayView& tThreeView=tThreeData.getView();
172 DataTagged::TagListType keys;
173 DataTagged::ValueListType values;
174 keys.push_back(1);
175 keys.push_back(2);
176 keys.push_back(3);
177 values.push_back(tOneView);
178 values.push_back(tTwoView);
179 values.push_back(tThreeView);
180 DataTagged tData(keys,values,defView,FunctionSpace());
181 unaryOp(tData,negate<double>());
182 unaryOp(tData,negate<double>());
183 assert(tData.getDataPointByTag(1)==tOneView);
184 assert(tData.getDataPointByTag(2)==tTwoView);
185 assert(tData.getDataPointByTag(3)==tThreeView);
186 }
187
188 }
189
190 void DataTaggedTestCase::testAddTaggedValues() {
191
192 cout << endl;
193
194 {
195
196 cout << "\tTest adding one key with empty value list to default DataTagged." << endl;
197 DataTagged myData;
198
199 DataTagged::TagListType keys;
200 keys.push_back(1);
201
202 DataTagged::ValueListType values;
203
204 myData.addTaggedValues(keys,values);
205
206 assert(myData.isCurrentTag(1));
207
208 assert(myData.getTagLookup().size()==1);
209
210 assert(myData.getLength()==2);
211
212 // data-point 0 has tag number 1 by default
213 assert(myData.getTagNumber(0)==1);
214
215 assert(myData.getPointOffset(0,0)==1);
216
217 DataArrayView myDataView = myData.getDataPoint(0,0);
218 assert(!myDataView.isEmpty());
219 assert(myDataView.getOffset()==1);
220 assert(myDataView.getRank()==0);
221 assert(myDataView.noValues()==1);
222 assert(myDataView.getShape().size()==0);
223 assert(myDataView()==0.0);
224
225 myDataView = myData.getDataPointByTag(1);
226 assert(!myDataView.isEmpty());
227 assert(myDataView.getOffset()==1);
228 assert(myDataView.getRank()==0);
229 assert(myDataView.noValues()==1);
230 assert(myDataView.getShape().size()==0);
231 assert(myDataView()==0.0);
232
233 myDataView = myData.getDefaultValue();
234 assert(!myDataView.isEmpty());
235 assert(myDataView.getOffset()==0);
236 assert(myDataView.getRank()==0);
237 assert(myDataView.noValues()==1);
238 assert(myDataView.getShape().size()==0);
239 assert(myDataView()==0.0);
240
241 }
242
243 {
244
245 cout << "\tTest adding one key with one value to default DataTagged." << endl;
246 DataTagged myData;
247
248 DataTagged::TagListType keys;
249 keys.push_back(1);
250
251 DataTagged::ValueListType values;
252
253 DataArrayView::ShapeType viewShape;
254 DataArrayView::ValueType viewData(1);
255 viewData[0]=1.0;
256 DataArrayView myView(viewData,viewShape);
257 values.push_back(myView);
258
259 myData.addTaggedValues(keys,values);
260
261 assert(myData.isCurrentTag(1));
262
263 assert(myData.getTagLookup().size()==1);
264
265 assert(myData.getLength()==2);
266
267 // data-point 0 has tag number 1 by default
268 assert(myData.getTagNumber(0)==1);
269
270 assert(myData.getPointOffset(0,0)==1);
271
272 DataArrayView myDataView = myData.getDataPoint(0,0);
273 assert(!myDataView.isEmpty());
274 assert(myDataView.getOffset()==1);
275 assert(myDataView.getRank()==0);
276 assert(myDataView.noValues()==1);
277 assert(myDataView.getShape().size()==0);
278 assert(myDataView()==1.0);
279
280 myDataView = myData.getDataPointByTag(1);
281 assert(!myDataView.isEmpty());
282 assert(myDataView.getOffset()==1);
283 assert(myDataView.getRank()==0);
284 assert(myDataView.noValues()==1);
285 assert(myDataView.getShape().size()==0);
286 assert(myDataView()==1.0);
287
288 myDataView = myData.getDefaultValue();
289 assert(!myDataView.isEmpty());
290 assert(myDataView.getOffset()==0);
291 assert(myDataView.getRank()==0);
292 assert(myDataView.noValues()==1);
293 assert(myDataView.getShape().size()==0);
294 assert(myDataView()==0.0);
295
296 }
297
298 {
299
300 cout << "\tTest adding three keys with one value to default DataTagged." << endl;
301 DataTagged myData;
302
303 DataTagged::TagListType keys;
304 keys.push_back(1);
305 keys.push_back(2);
306 keys.push_back(3);
307
308 DataTagged::ValueListType values;
309
310 DataArrayView::ShapeType viewShape;
311 DataArrayView::ValueType viewData(1);
312 viewData[0]=1.0;
313 DataArrayView myView(viewData,viewShape);
314 values.push_back(myView);
315
316 myData.addTaggedValues(keys,values);
317
318 assert(myData.isCurrentTag(1));
319 assert(myData.isCurrentTag(2));
320 assert(myData.isCurrentTag(3));
321
322 assert(myData.getTagLookup().size()==3);
323
324 assert(myData.getLength()==4);
325
326 // data-point 0 has tag number 1 by default
327 assert(myData.getTagNumber(0)==1);
328
329 assert(myData.getPointOffset(0,0)==1);
330
331 DataArrayView myDataView = myData.getDataPoint(0,0);
332 assert(!myDataView.isEmpty());
333 assert(myDataView.getOffset()==1);
334 assert(myDataView.getRank()==0);
335 assert(myDataView.noValues()==1);
336 assert(myDataView.getShape().size()==0);
337 assert(myDataView()==1.0);
338
339 myDataView = myData.getDataPointByTag(1);
340 assert(!myDataView.isEmpty());
341 assert(myDataView.getOffset()==1);
342 assert(myDataView.getRank()==0);
343 assert(myDataView.noValues()==1);
344 assert(myDataView.getShape().size()==0);
345 assert(myDataView()==1.0);
346
347 myDataView = myData.getDataPointByTag(2);
348 assert(!myDataView.isEmpty());
349 assert(myDataView.getOffset()==2);
350 assert(myDataView.getRank()==0);
351 assert(myDataView.noValues()==1);
352 assert(myDataView.getShape().size()==0);
353 assert(myDataView()==1.0);
354
355 myDataView = myData.getDataPointByTag(3);
356 assert(!myDataView.isEmpty());
357 assert(myDataView.getOffset()==3);
358 assert(myDataView.getRank()==0);
359 assert(myDataView.noValues()==1);
360 assert(myDataView.getShape().size()==0);
361 assert(myDataView()==1.0);
362
363 myDataView = myData.getDefaultValue();
364 assert(!myDataView.isEmpty());
365 assert(myDataView.getOffset()==0);
366 assert(myDataView.getRank()==0);
367 assert(myDataView.noValues()==1);
368 assert(myDataView.getShape().size()==0);
369 assert(myDataView()==0.0);
370
371 }
372
373 {
374
375 cout << "\tTest adding three keys with three values to default DataTagged." << endl;
376 DataTagged myData;
377
378 DataTagged::TagListType keys;
379 keys.push_back(1);
380 keys.push_back(2);
381 keys.push_back(3);
382
383 DataTagged::ValueListType values;
384
385 DataArrayView::ShapeType viewShape;
386 DataArrayView::ValueType viewData1(1);
387 viewData1[0]=1.0;
388 DataArrayView::ValueType viewData2(1);
389 viewData2[0]=2.0;
390 DataArrayView::ValueType viewData3(1);
391 viewData3[0]=3.0;
392 DataArrayView myView1(viewData1,viewShape);
393 DataArrayView myView2(viewData2,viewShape);
394 DataArrayView myView3(viewData3,viewShape);
395 values.push_back(myView1);
396 values.push_back(myView2);
397 values.push_back(myView3);
398
399 myData.addTaggedValues(keys,values);
400
401 assert(myData.isCurrentTag(1));
402 assert(myData.isCurrentTag(2));
403 assert(myData.isCurrentTag(3));
404
405 assert(myData.getTagLookup().size()==3);
406
407 assert(myData.getLength()==4);
408
409 // data-point 0 has tag number 1 by default
410 assert(myData.getTagNumber(0)==1);
411
412 assert(myData.getPointOffset(0,0)==1);
413
414 DataArrayView myDataView = myData.getDataPoint(0,0);
415 assert(!myDataView.isEmpty());
416 assert(myDataView.getOffset()==1);
417 assert(myDataView.getRank()==0);
418 assert(myDataView.noValues()==1);
419 assert(myDataView.getShape().size()==0);
420 assert(myDataView()==1.0);
421
422 myDataView = myData.getDataPointByTag(1);
423 assert(!myDataView.isEmpty());
424 assert(myDataView.getOffset()==1);
425 assert(myDataView.getRank()==0);
426 assert(myDataView.noValues()==1);
427 assert(myDataView.getShape().size()==0);
428 assert(myDataView()==1.0);
429
430 myDataView = myData.getDataPointByTag(2);
431 assert(!myDataView.isEmpty());
432 assert(myDataView.getOffset()==2);
433 assert(myDataView.getRank()==0);
434 assert(myDataView.noValues()==1);
435 assert(myDataView.getShape().size()==0);
436 assert(myDataView()==2.0);
437
438 myDataView = myData.getDataPointByTag(3);
439 assert(!myDataView.isEmpty());
440 assert(myDataView.getOffset()==3);
441 assert(myDataView.getRank()==0);
442 assert(myDataView.noValues()==1);
443 assert(myDataView.getShape().size()==0);
444 assert(myDataView()==3.0);
445
446 myDataView = myData.getDefaultValue();
447 assert(!myDataView.isEmpty());
448 assert(myDataView.getOffset()==0);
449 assert(myDataView.getRank()==0);
450 assert(myDataView.noValues()==1);
451 assert(myDataView.getShape().size()==0);
452 assert(myDataView()==0.0);
453
454 }
455
456 {
457
458 cout << "\tTest adding one key with empty value list to DataTagged with default value only." << endl;
459
460 DataArrayView::ShapeType viewShape;
461 viewShape.push_back(3);
462
463 DataTagged::TagListType keys;
464
465 DataTagged::ValueListType values;
466
467 DataArrayView::ValueType viewData(3);
468 for (int i=0;i<viewShape[0];i++) {
469 viewData[i]=i;
470 }
471 DataArrayView myView(viewData,viewShape);
472
473 DataTagged myData(keys,values,myView,FunctionSpace());
474
475 keys.push_back(1);
476 values.clear();
477
478 myData.addTaggedValues(keys,values);
479
480 assert(myData.isCurrentTag(1));
481
482 assert(myData.getTagLookup().size()==1);
483
484 assert(myData.getLength()==6);
485
486 // data-point 0 has tag number 1 by default
487 assert(myData.getTagNumber(0)==1);
488
489 assert(myData.getPointOffset(0,0)==3);
490
491 DataArrayView myDataView = myData.getDataPoint(0,0);
492 assert(myDataView==myView);
493 assert(!myDataView.isEmpty());
494 assert(myDataView.getOffset()==3);
495 assert(myDataView.getRank()==1);
496 assert(myDataView.noValues()==3);
497 assert(myDataView.getShape().size()==1);
498 assert(myDataView(0)==0);
499 assert(myDataView(1)==1);
500 assert(myDataView(2)==2);
501
502 myDataView = myData.getDataPointByTag(1);
503 assert(myDataView==myView);
504 assert(!myDataView.isEmpty());
505 assert(myDataView.getOffset()==3);
506 assert(myDataView.getRank()==1);
507 assert(myDataView.noValues()==3);
508 assert(myDataView.getShape().size()==1);
509 assert(myDataView(0)==0);
510 assert(myDataView(1)==1);
511 assert(myDataView(2)==2);
512
513 myDataView = myData.getDefaultValue();
514 assert(myDataView==myView);
515 assert(!myDataView.isEmpty());
516 assert(myDataView.getOffset()==0);
517 assert(myDataView.getRank()==1);
518 assert(myDataView.noValues()==3);
519 assert(myDataView.getShape().size()==1);
520 assert(myDataView(0)==0);
521 assert(myDataView(1)==1);
522 assert(myDataView(2)==2);
523
524 }
525
526 {
527
528 cout << "\tTest adding one key with one value to DataTagged with default value only." << endl;
529
530 DataArrayView::ShapeType viewShape;
531 viewShape.push_back(3);
532
533 DataTagged::TagListType keys;
534
535 DataTagged::ValueListType values;
536
537 DataArrayView::ValueType viewData(3);
538 for (int i=0;i<viewShape[0];i++) {
539 viewData[i]=i;
540 }
541 DataArrayView myView(viewData,viewShape);
542
543 DataTagged myData(keys,values,myView,FunctionSpace());
544
545 keys.push_back(1);
546
547 DataArrayView::ValueType viewData1(3);
548 for (int i=0;i<viewShape[0];i++) {
549 viewData1[i]=i+1;
550 }
551 DataArrayView myView1(viewData1,viewShape);
552 values.push_back(myView1);
553
554 myData.addTaggedValues(keys,values);
555
556 assert(myData.isCurrentTag(1));
557
558 assert(myData.getTagLookup().size()==1);
559
560 assert(myData.getLength()==6);
561
562 // data-point 0 has tag number 1 by default
563 assert(myData.getTagNumber(0)==1);
564
565 assert(myData.getPointOffset(0,0)==3);
566
567 DataArrayView myDataView = myData.getDataPoint(0,0);
568 assert(myDataView==myView1);
569 assert(!myDataView.isEmpty());
570 assert(myDataView.getOffset()==3);
571 assert(myDataView.getRank()==1);
572 assert(myDataView.noValues()==3);
573 assert(myDataView.getShape().size()==1);
574 assert(myDataView(0)==1);
575 assert(myDataView(1)==2);
576 assert(myDataView(2)==3);
577
578 myDataView = myData.getDataPointByTag(1);
579 assert(myDataView==myView1);
580 assert(!myDataView.isEmpty());
581 assert(myDataView.getOffset()==3);
582 assert(myDataView.getRank()==1);
583 assert(myDataView.noValues()==3);
584 assert(myDataView.getShape().size()==1);
585 assert(myDataView(0)==1);
586 assert(myDataView(1)==2);
587 assert(myDataView(2)==3);
588
589 myDataView = myData.getDefaultValue();
590 assert(myDataView==myView);
591 assert(!myDataView.isEmpty());
592 assert(myDataView.getOffset()==0);
593 assert(myDataView.getRank()==1);
594 assert(myDataView.noValues()==3);
595 assert(myDataView.getShape().size()==1);
596 assert(myDataView(0)==0);
597 assert(myDataView(1)==1);
598 assert(myDataView(2)==2);
599
600 }
601
602 {
603
604 cout << "\tTest adding three keys with one value to DataTagged with default value only." << endl;
605
606 DataArrayView::ShapeType viewShape;
607 viewShape.push_back(3);
608
609 DataTagged::TagListType keys;
610
611 DataTagged::ValueListType values;
612
613 DataArrayView::ValueType viewData(3);
614 for (int i=0;i<viewShape[0];i++) {
615 viewData[i]=i;
616 }
617 DataArrayView myView(viewData,viewShape);
618
619 DataTagged myData(keys,values,myView,FunctionSpace());
620
621 keys.push_back(1);
622 keys.push_back(2);
623 keys.push_back(3);
624
625 DataArrayView::ValueType viewData1(3);
626 for (int i=0;i<viewShape[0];i++) {
627 viewData1[i]=i+1;
628 }
629 DataArrayView myView1(viewData1,viewShape);
630 values.push_back(myView1);
631
632 myData.addTaggedValues(keys,values);
633
634 assert(myData.isCurrentTag(1));
635 assert(myData.isCurrentTag(2));
636 assert(myData.isCurrentTag(3));
637
638 assert(myData.getTagLookup().size()==3);
639
640 assert(myData.getLength()==12);
641
642 // data-point 0 has tag number 1 by default
643 assert(myData.getTagNumber(0)==1);
644
645 assert(myData.getPointOffset(0,0)==3);
646
647 DataArrayView myDataView = myData.getDataPoint(0,0);
648 assert(myDataView==myView1);
649 assert(!myDataView.isEmpty());
650 assert(myDataView.getOffset()==3);
651 assert(myDataView.getRank()==1);
652 assert(myDataView.noValues()==3);
653 assert(myDataView.getShape().size()==1);
654 assert(myDataView(0)==1);
655 assert(myDataView(1)==2);
656 assert(myDataView(2)==3);
657
658 myDataView = myData.getDataPointByTag(1);
659 assert(myDataView==myView1);
660 assert(!myDataView.isEmpty());
661 assert(myDataView.getOffset()==3);
662 assert(myDataView.getRank()==1);
663 assert(myDataView.noValues()==3);
664 assert(myDataView.getShape().size()==1);
665 assert(myDataView(0)==1);
666 assert(myDataView(1)==2);
667 assert(myDataView(2)==3);
668
669 myDataView = myData.getDataPointByTag(2);
670 assert(myDataView==myView1);
671 assert(!myDataView.isEmpty());
672 assert(myDataView.getOffset()==6);
673 assert(myDataView.getRank()==1);
674 assert(myDataView.noValues()==3);
675 assert(myDataView.getShape().size()==1);
676 assert(myDataView(0)==1);
677 assert(myDataView(1)==2);
678 assert(myDataView(2)==3);
679
680 myDataView = myData.getDataPointByTag(3);
681 assert(myDataView==myView1);
682 assert(!myDataView.isEmpty());
683 assert(myDataView.getOffset()==9);
684 assert(myDataView.getRank()==1);
685 assert(myDataView.noValues()==3);
686 assert(myDataView.getShape().size()==1);
687 assert(myDataView(0)==1);
688 assert(myDataView(1)==2);
689 assert(myDataView(2)==3);
690
691 myDataView = myData.getDefaultValue();
692 assert(myDataView==myView);
693 assert(!myDataView.isEmpty());
694 assert(myDataView.getOffset()==0);
695 assert(myDataView.getRank()==1);
696 assert(myDataView.noValues()==3);
697 assert(myDataView.getShape().size()==1);
698 assert(myDataView(0)==0);
699 assert(myDataView(1)==1);
700 assert(myDataView(2)==2);
701
702 }
703
704 {
705
706 cout << "\tTest adding three keys with three values to DataTagged with default value only." << endl;
707
708 DataArrayView::ShapeType viewShape;
709 viewShape.push_back(3);
710
711 DataTagged::TagListType keys;
712
713 DataTagged::ValueListType values;
714
715 DataArrayView::ValueType viewData(3);
716 for (int i=0;i<viewShape[0];i++) {
717 viewData[i]=i;
718 }
719 DataArrayView myView(viewData,viewShape);
720
721 DataTagged myData(keys,values,myView,FunctionSpace());
722
723 keys.push_back(1);
724 keys.push_back(2);
725 keys.push_back(3);
726
727 DataArrayView::ValueType viewData1(3);
728 for (int i=0;i<viewShape[0];i++) {
729 viewData1[i]=i+1;
730 }
731 DataArrayView myView1(viewData1,viewShape);
732 values.push_back(myView1);
733
734 DataArrayView::ValueType viewData2(3);
735 for (int i=0;i<viewShape[0];i++) {
736 viewData2[i]=i+2;
737 }
738 DataArrayView myView2(viewData2,viewShape);
739 values.push_back(myView2);
740
741 DataArrayView::ValueType viewData3(3);
742 for (int i=0;i<viewShape[0];i++) {
743 viewData3[i]=i+3;
744 }
745 DataArrayView myView3(viewData3,viewShape);
746 values.push_back(myView3);
747
748 myData.addTaggedValues(keys,values);
749
750 assert(myData.isCurrentTag(1));
751 assert(myData.isCurrentTag(2));
752 assert(myData.isCurrentTag(3));
753
754 assert(myData.getTagLookup().size()==3);
755
756 assert(myData.getLength()==12);
757
758 // data-point 0 has tag number 1 by default
759 assert(myData.getTagNumber(0)==1);
760
761 assert(myData.getPointOffset(0,0)==3);
762
763 DataArrayView myDataView = myData.getDataPoint(0,0);
764 assert(myDataView==myView1);
765 assert(!myDataView.isEmpty());
766 assert(myDataView.getOffset()==3);
767 assert(myDataView.getRank()==1);
768 assert(myDataView.noValues()==3);
769 assert(myDataView.getShape().size()==1);
770 assert(myDataView(0)==1);
771 assert(myDataView(1)==2);
772 assert(myDataView(2)==3);
773
774 myDataView = myData.getDataPointByTag(1);
775 assert(myDataView==myView1);
776 assert(!myDataView.isEmpty());
777 assert(myDataView.getOffset()==3);
778 assert(myDataView.getRank()==1);
779 assert(myDataView.noValues()==3);
780 assert(myDataView.getShape().size()==1);
781 assert(myDataView(0)==1);
782 assert(myDataView(1)==2);
783 assert(myDataView(2)==3);
784
785 myDataView = myData.getDataPointByTag(2);
786 assert(myDataView==myView2);
787 assert(!myDataView.isEmpty());
788 assert(myDataView.getOffset()==6);
789 assert(myDataView.getRank()==1);
790 assert(myDataView.noValues()==3);
791 assert(myDataView.getShape().size()==1);
792 assert(myDataView(0)==2);
793 assert(myDataView(1)==3);
794 assert(myDataView(2)==4);
795
796 myDataView = myData.getDataPointByTag(3);
797 assert(myDataView==myView3);
798 assert(!myDataView.isEmpty());
799 assert(myDataView.getOffset()==9);
800 assert(myDataView.getRank()==1);
801 assert(myDataView.noValues()==3);
802 assert(myDataView.getShape().size()==1);
803 assert(myDataView(0)==3);
804 assert(myDataView(1)==4);
805 assert(myDataView(2)==5);
806
807 myDataView = myData.getDefaultValue();
808 assert(myDataView==myView);
809 assert(!myDataView.isEmpty());
810 assert(myDataView.getOffset()==0);
811 assert(myDataView.getRank()==1);
812 assert(myDataView.noValues()==3);
813 assert(myDataView.getShape().size()==1);
814 assert(myDataView(0)==0);
815 assert(myDataView(1)==1);
816 assert(myDataView(2)==2);
817
818 }
819
820 {
821
822 cout << "\tTest adding one key with empty value list to DataTagged with three tags." << endl;
823
824 DataTagged::TagListType keys;
825 keys.push_back(1);
826 keys.push_back(2);
827 keys.push_back(3);
828
829 DataTagged::ValueListType values;
830
831 DataArrayView::ShapeType viewShape;
832 viewShape.push_back(3);
833
834 // default value
835 DataArrayView::ValueType viewData(3);
836 for (int i=0;i<viewShape[0];i++) {
837 viewData[i]=i;
838 }
839 DataArrayView myView(viewData,viewShape);
840
841 // value for tag "1"
842 DataArray eOne(myView);
843 for (int i=0;i<eOne.getView().getShape()[0];i++) {
844 eOne.getView()(i)=i+1.0;
845 }
846 values.push_back(eOne.getView());
847
848 // value for tag "2"
849 DataArray eTwo(myView);
850 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
851 eTwo.getView()(i)=i+2.0;
852 }
853 values.push_back(eTwo.getView());
854
855 // value for tag "3"
856 DataArray eThree(myView);
857 for (int i=0;i<eThree.getView().getShape()[0];i++) {
858 eThree.getView()(i)=i+3.0;
859 }
860 values.push_back(eThree.getView());
861
862 DataTagged myData(keys,values,myView,FunctionSpace());
863
864 keys.clear();
865 keys.push_back(4);
866 values.clear();
867
868 myData.addTaggedValues(keys,values);
869
870 assert(myData.isCurrentTag(4));
871
872 assert(myData.getTagLookup().size()==4);
873
874 assert(myData.getLength()==15);
875
876 DataArrayView myDataView = myData.getDataPointByTag(4);
877 assert(myDataView==myView);
878 assert(!myDataView.isEmpty());
879 assert(myDataView.getOffset()==12);
880 assert(myDataView.getRank()==1);
881 assert(myDataView.noValues()==3);
882 assert(myDataView.getShape().size()==1);
883 assert(myDataView(0)==0);
884 assert(myDataView(1)==1);
885 assert(myDataView(2)==2);
886
887 }
888
889 {
890
891 cout << "\tTest adding one key with one value to DataTagged with three tags." << endl;
892
893 DataTagged::TagListType keys;
894 keys.push_back(1);
895 keys.push_back(2);
896 keys.push_back(3);
897
898 DataTagged::ValueListType values;
899
900 DataArrayView::ShapeType viewShape;
901 viewShape.push_back(3);
902
903 // default value
904 DataArrayView::ValueType viewData(3);
905 for (int i=0;i<viewShape[0];i++) {
906 viewData[i]=i;
907 }
908 DataArrayView myView(viewData,viewShape);
909
910 // value for tag "1"
911 DataArray eOne(myView);
912 for (int i=0;i<eOne.getView().getShape()[0];i++) {
913 eOne.getView()(i)=i+1.0;
914 }
915 values.push_back(eOne.getView());
916
917 // value for tag "2"
918 DataArray eTwo(myView);
919 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
920 eTwo.getView()(i)=i+2.0;
921 }
922 values.push_back(eTwo.getView());
923
924 // value for tag "3"
925 DataArray eThree(myView);
926 for (int i=0;i<eThree.getView().getShape()[0];i++) {
927 eThree.getView()(i)=i+3.0;
928 }
929 values.push_back(eThree.getView());
930
931 DataTagged myData(keys,values,myView,FunctionSpace());
932
933 keys.clear();
934 keys.push_back(4);
935
936 values.clear();
937 // value for tag "4"
938 DataArray eFour(myView);
939 for (int i=0;i<eFour.getView().getShape()[0];i++) {
940 eFour.getView()(i)=i+4.0;
941 }
942 values.push_back(eFour.getView());
943
944 myData.addTaggedValues(keys,values);
945
946 assert(myData.isCurrentTag(4));
947
948 assert(myData.getTagLookup().size()==4);
949
950 assert(myData.getLength()==15);
951
952 DataArrayView myDataView = myData.getDataPointByTag(4);
953 assert(myDataView==eFour.getView());
954 assert(!myDataView.isEmpty());
955 assert(myDataView.getOffset()==12);
956 assert(myDataView.getRank()==1);
957 assert(myDataView.noValues()==3);
958 assert(myDataView.getShape().size()==1);
959 assert(myDataView(0)==4);
960 assert(myDataView(1)==5);
961 assert(myDataView(2)==6);
962
963 }
964
965 {
966
967 cout << "\tTest adding three keys with one value to DataTagged with three tags." << endl;
968
969 DataTagged::TagListType keys;
970 keys.push_back(1);
971 keys.push_back(2);
972 keys.push_back(3);
973
974 DataTagged::ValueListType values;
975
976 DataArrayView::ShapeType viewShape;
977 viewShape.push_back(3);
978
979 // default value
980 DataArrayView::ValueType viewData(3);
981 for (int i=0;i<viewShape[0];i++) {
982 viewData[i]=i;
983 }
984 DataArrayView myView(viewData,viewShape);
985
986 // value for tag "1"
987 DataArray eOne(myView);
988 for (int i=0;i<eOne.getView().getShape()[0];i++) {
989 eOne.getView()(i)=i+1.0;
990 }
991 values.push_back(eOne.getView());
992
993 // value for tag "2"
994 DataArray eTwo(myView);
995 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
996 eTwo.getView()(i)=i+2.0;
997 }
998 values.push_back(eTwo.getView());
999
1000 // value for tag "3"
1001 DataArray eThree(myView);
1002 for (int i=0;i<eThree.getView().getShape()[0];i++) {
1003 eThree.getView()(i)=i+3.0;
1004 }
1005 values.push_back(eThree.getView());
1006
1007 DataTagged myData(keys,values,myView,FunctionSpace());
1008
1009 keys.clear();
1010 keys.push_back(4);
1011 keys.push_back(5);
1012 keys.push_back(6);
1013
1014 values.clear();
1015 // value for tags "4", "5" and "6"
1016 DataArray eFour(myView);
1017 for (int i=0;i<eFour.getView().getShape()[0];i++) {
1018 eFour.getView()(i)=i+4.0;
1019 }
1020 values.push_back(eFour.getView());
1021
1022 myData.addTaggedValues(keys,values);
1023
1024 assert(myData.isCurrentTag(4));
1025 assert(myData.isCurrentTag(5));
1026 assert(myData.isCurrentTag(6));
1027
1028 assert(myData.getTagLookup().size()==6);
1029
1030 assert(myData.getLength()==21);
1031
1032 DataArrayView myDataView = myData.getDataPointByTag(4);
1033 assert(myDataView==eFour.getView());
1034 assert(!myDataView.isEmpty());
1035 assert(myDataView.getOffset()==12);
1036 assert(myDataView.getRank()==1);
1037 assert(myDataView.noValues()==3);
1038 assert(myDataView.getShape().size()==1);
1039 assert(myDataView(0)==4);
1040 assert(myDataView(1)==5);
1041 assert(myDataView(2)==6);
1042
1043 myDataView = myData.getDataPointByTag(5);
1044 assert(myDataView==eFour.getView());
1045 assert(!myDataView.isEmpty());
1046 assert(myDataView.getOffset()==15);
1047 assert(myDataView.getRank()==1);
1048 assert(myDataView.noValues()==3);
1049 assert(myDataView.getShape().size()==1);
1050 assert(myDataView(0)==4);
1051 assert(myDataView(1)==5);
1052 assert(myDataView(2)==6);
1053
1054 myDataView = myData.getDataPointByTag(6);
1055 assert(myDataView==eFour.getView());
1056 assert(!myDataView.isEmpty());
1057 assert(myDataView.getOffset()==18);
1058 assert(myDataView.getRank()==1);
1059 assert(myDataView.noValues()==3);
1060 assert(myDataView.getShape().size()==1);
1061 assert(myDataView(0)==4);
1062 assert(myDataView(1)==5);
1063 assert(myDataView(2)==6);
1064
1065 }
1066
1067 {
1068
1069 cout << "\tTest adding three keys with three values to DataTagged with three tags." << endl;
1070
1071 DataTagged::TagListType keys;
1072 keys.push_back(1);
1073 keys.push_back(2);
1074 keys.push_back(3);
1075
1076 DataTagged::ValueListType values;
1077
1078 DataArrayView::ShapeType viewShape;
1079 viewShape.push_back(3);
1080
1081 // default value
1082 DataArrayView::ValueType viewData(3);
1083 for (int i=0;i<viewShape[0];i++) {
1084 viewData[i]=i;
1085 }
1086 DataArrayView myView(viewData,viewShape);
1087
1088 // value for tag "1"
1089 DataArray eOne(myView);
1090 for (int i=0;i<eOne.getView().getShape()[0];i++) {
1091 eOne.getView()(i)=i+1.0;
1092 }
1093 values.push_back(eOne.getView());
1094
1095 // value for tag "2"
1096 DataArray eTwo(myView);
1097 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1098 eTwo.getView()(i)=i+2.0;
1099 }
1100 values.push_back(eTwo.getView());
1101
1102 // value for tag "3"
1103 DataArray eThree(myView);
1104 for (int i=0;i<eThree.getView().getShape()[0];i++) {
1105 eThree.getView()(i)=i+3.0;
1106 }
1107 values.push_back(eThree.getView());
1108
1109 DataTagged myData(keys,values,myView,FunctionSpace());
1110
1111 keys.clear();
1112 keys.push_back(4);
1113 keys.push_back(5);
1114 keys.push_back(6);
1115
1116 values.clear();
1117
1118 // value for tag "4"
1119 DataArray eFour(myView);
1120 for (int i=0;i<eFour.getView().getShape()[0];i++) {
1121 eFour.getView()(i)=i+4.0;
1122 }
1123 values.push_back(eFour.getView());
1124
1125 // value for tag "5"
1126 DataArray eFive(myView);
1127 for (int i=0;i<eFive.getView().getShape()[0];i++) {
1128 eFive.getView()(i)=i+5.0;
1129 }
1130 values.push_back(eFive.getView());
1131
1132 // value for tag "6"
1133 DataArray eSix(myView);
1134 for (int i=0;i<eSix.getView().getShape()[0];i++) {
1135 eSix.getView()(i)=i+6.0;
1136 }
1137 values.push_back(eSix.getView());
1138
1139 myData.addTaggedValues(keys,values);
1140
1141 assert(myData.isCurrentTag(4));
1142 assert(myData.isCurrentTag(5));
1143 assert(myData.isCurrentTag(6));
1144
1145 assert(myData.getTagLookup().size()==6);
1146
1147 assert(myData.getLength()==21);
1148
1149 DataArrayView myDataView = myData.getDataPointByTag(4);
1150 assert(myDataView==eFour.getView());
1151 assert(!myDataView.isEmpty());
1152 assert(myDataView.getOffset()==12);
1153 assert(myDataView.getRank()==1);
1154 assert(myDataView.noValues()==3);
1155 assert(myDataView.getShape().size()==1);
1156 assert(myDataView(0)==4);
1157 assert(myDataView(1)==5);
1158 assert(myDataView(2)==6);
1159
1160 myDataView = myData.getDataPointByTag(5);
1161 assert(myDataView==eFive.getView());
1162 assert(!myDataView.isEmpty());
1163 assert(myDataView.getOffset()==15);
1164 assert(myDataView.getRank()==1);
1165 assert(myDataView.noValues()==3);
1166 assert(myDataView.getShape().size()==1);
1167 assert(myDataView(0)==5);
1168 assert(myDataView(1)==6);
1169 assert(myDataView(2)==7);
1170
1171 myDataView = myData.getDataPointByTag(6);
1172 assert(myDataView==eSix.getView());
1173 assert(!myDataView.isEmpty());
1174 assert(myDataView.getOffset()==18);
1175 assert(myDataView.getRank()==1);
1176 assert(myDataView.noValues()==3);
1177 assert(myDataView.getShape().size()==1);
1178 assert(myDataView(0)==6);
1179 assert(myDataView(1)==7);
1180 assert(myDataView(2)==8);
1181
1182 }
1183
1184 }
1185
1186 void DataTaggedTestCase::testSetTaggedValue() {
1187
1188 cout << endl;
1189
1190 {
1191
1192 cout << "\tTest setting key in DataTagged with three tags." << endl;
1193
1194 DataTagged::TagListType keys;
1195 keys.push_back(1);
1196 keys.push_back(2);
1197 keys.push_back(3);
1198
1199 DataTagged::ValueListType values;
1200
1201 DataArrayView::ShapeType viewShape;
1202 viewShape.push_back(3);
1203
1204 // default value
1205 DataArrayView::ValueType viewData(3);
1206 for (int i=0;i<viewShape[0];i++) {
1207 viewData[i]=i;
1208 }
1209 DataArrayView myView(viewData,viewShape);
1210
1211 // value for tag "1"
1212 DataArray eOne(myView);
1213 for (int i=0;i<eOne.getView().getShape()[0];i++) {
1214 eOne.getView()(i)=i+1.0;
1215 }
1216 values.push_back(eOne.getView());
1217
1218 // value for tag "2"
1219 DataArray eTwo(myView);
1220 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1221 eTwo.getView()(i)=i+2.0;
1222 }
1223 values.push_back(eTwo.getView());
1224
1225 // value for tag "3"
1226 DataArray eThree(myView);
1227 for (int i=0;i<eThree.getView().getShape()[0];i++) {
1228 eThree.getView()(i)=i+3.0;
1229 }
1230 values.push_back(eThree.getView());
1231
1232 DataTagged myData(keys,values,myView,FunctionSpace());
1233
1234 // new value for tag "2"
1235 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1236 eTwo.getView()(i)=i+5.0;
1237 }
1238
1239 myData.setTaggedValue(2,eTwo.getView());
1240
1241 assert(myData.isCurrentTag(2));
1242
1243 assert(myData.getTagLookup().size()==3);
1244
1245 assert(myData.getLength()==12);
1246
1247 DataArrayView myDataView = myData.getDataPointByTag(2);
1248 assert(myDataView==eTwo.getView());
1249 assert(!myDataView.isEmpty());
1250 assert(myDataView.getOffset()==6);
1251 assert(myDataView.getRank()==1);
1252 assert(myDataView.noValues()==3);
1253 assert(myDataView.getShape().size()==1);
1254 assert(myDataView(0)==5);
1255 assert(myDataView(1)==6);
1256 assert(myDataView(2)==7);
1257
1258 }
1259
1260 }
1261
1262 void DataTaggedTestCase::testAll() {
1263
1264 cout << endl;
1265
1266 {
1267
1268 cout << "\tTest default DataTagged." << endl;
1269 DataTagged myData;
1270
1271 //cout << myData.toString() << endl;
1272
1273 assert(myData.getNumSamples()==1);
1274 assert(myData.getNumDPPSample()==1);
1275
1276 assert(myData.validSamplePointNo(0));
1277 assert(myData.validSampleNo(0));
1278 assert(!myData.validSamplePointNo(1));
1279 assert(!myData.validSampleNo(1));
1280
1281 // data-point 0 has tag number 1 by default
1282 assert(myData.getTagNumber(0)==1);
1283
1284 assert(!myData.isCurrentTag(1));
1285
1286 assert(myData.getTagLookup().size()==0);
1287
1288 assert(myData.getLength()==1);
1289
1290 assert(myData.getPointOffset(0,0)==0);
1291
1292 DataArrayView myDataView = myData.getDataPoint(0,0);
1293 assert(!myDataView.isEmpty());
1294 assert(myDataView.getOffset()==0);
1295 assert(myDataView.getRank()==0);
1296 assert(myDataView.noValues()==1);
1297 assert(myDataView.getShape().size()==0);
1298 assert(myDataView()==0.0);
1299
1300 // Test non-existent tag returns the default value.
1301 myDataView = myData.getDataPointByTag(1);
1302 assert(!myDataView.isEmpty());
1303 assert(myDataView.getOffset()==0);
1304 assert(myDataView.getRank()==0);
1305 assert(myDataView.noValues()==1);
1306 assert(myDataView.getShape().size()==0);
1307 assert(myDataView()==0.0);
1308
1309 myDataView = myData.getDefaultValue();
1310 assert(!myDataView.isEmpty());
1311 assert(myDataView.getOffset()==0);
1312 assert(myDataView.getRank()==0);
1313 assert(myDataView.noValues()==1);
1314 assert(myDataView.getShape().size()==0);
1315 assert(myDataView()==0.0);
1316
1317 }
1318
1319 {
1320
1321 cout << "\tTest DataTagged with default value only." << endl;
1322
1323 DataArrayView::ShapeType viewShape;
1324 viewShape.push_back(3);
1325
1326 DataTagged::TagListType keys;
1327
1328 DataTagged::ValueListType values;
1329
1330 DataArrayView::ValueType viewData(3);
1331 for (int i=0;i<viewShape[0];i++) {
1332 viewData[i]=i;
1333 }
1334 DataArrayView myView(viewData,viewShape);
1335
1336 DataTagged myData(keys,values,myView,FunctionSpace());
1337
1338 //cout << myData.toString() << endl;
1339
1340 assert(myData.getNumSamples()==1);
1341 assert(myData.getNumDPPSample()==1);
1342
1343 assert(myData.validSamplePointNo(0));
1344 assert(myData.validSampleNo(0));
1345 assert(!myData.validSamplePointNo(1));
1346 assert(!myData.validSampleNo(1));
1347
1348 // data-point 0 has tag number 1 by default
1349 assert(myData.getTagNumber(0)==1);
1350
1351 assert(!myData.isCurrentTag(1));
1352
1353 assert(myData.getTagLookup().size()==0);
1354
1355 assert(myData.getLength()==3);
1356
1357 assert(myData.getPointOffset(0,0)==0);
1358
1359 DataArrayView myDataView = myData.getDataPoint(0,0);
1360 assert(myDataView==myView);
1361 assert(!myDataView.isEmpty());
1362 assert(myDataView.getOffset()==0);
1363 assert(myDataView.getRank()==1);
1364 assert(myDataView.noValues()==3);
1365 assert(myDataView.getShape().size()==1);
1366 assert(myDataView(0)==0);
1367 assert(myDataView(1)==1);
1368 assert(myDataView(2)==2);
1369
1370 // Test non-existent tag returns the default value.
1371 myDataView = myData.getDataPointByTag(1);
1372 assert(myDataView==myView);
1373 assert(!myDataView.isEmpty());
1374 assert(myDataView.getOffset()==0);
1375 assert(myDataView.getRank()==1);
1376 assert(myDataView.noValues()==3);
1377 assert(myDataView.getShape().size()==1);
1378 assert(myDataView(0)==0);
1379 assert(myDataView(1)==1);
1380 assert(myDataView(2)==2);
1381
1382 myDataView = myData.getDefaultValue();
1383 assert(myDataView==myView);
1384 assert(!myDataView.isEmpty());
1385 assert(myDataView.getOffset()==0);
1386 assert(myDataView.getRank()==1);
1387 assert(myDataView.noValues()==3);
1388 assert(myDataView.getShape().size()==1);
1389 assert(myDataView(0)==0);
1390 assert(myDataView(1)==1);
1391 assert(myDataView(2)==2);
1392
1393 }
1394
1395 {
1396
1397 cout << "\tTest DataTagged with one tag." << endl;
1398
1399 // the one data-point has tag value "1"
1400
1401 DataTagged::TagListType keys;
1402 keys.push_back(1);
1403
1404 DataTagged::ValueListType values;
1405
1406 DataArrayView::ShapeType viewShape;
1407 viewShape.push_back(3);
1408
1409 // default value
1410 DataArrayView::ValueType viewData(3);
1411 for (int i=0;i<viewShape[0];i++) {
1412 viewData[i]=i;
1413 }
1414 DataArrayView myView(viewData,viewShape);
1415
1416 // value for tag "1"
1417 DataArray eOne(myView);
1418 for (int i=0;i<eOne.getView().getShape()[0];i++) {
1419 eOne.getView()(i)=i+1.0;
1420 }
1421 values.push_back(eOne.getView());
1422
1423 DataTagged myData(keys,values,myView,FunctionSpace());
1424
1425 //cout << myData.toString() << endl;
1426
1427 assert(myData.getNumSamples()==1);
1428 assert(myData.getNumDPPSample()==1);
1429
1430 assert(myData.validSamplePointNo(0));
1431 assert(myData.validSampleNo(0));
1432 assert(!myData.validSamplePointNo(1));
1433 assert(!myData.validSampleNo(1));
1434
1435 // data-point 0 has tag number 1 by default
1436 assert(myData.getTagNumber(0)==1);
1437
1438 assert(!myData.isCurrentTag(0));
1439 assert(myData.isCurrentTag(1));
1440
1441 assert(myData.getTagLookup().size()==1);
1442
1443 assert(myData.getLength()==6);
1444
1445 assert(myData.getPointOffset(0,0)==3);
1446
1447 DataArrayView myDataView = myData.getDataPoint(0,0);
1448 assert(myDataView==eOne.getView());
1449 assert(!myDataView.isEmpty());
1450 assert(myDataView.getOffset()==3);
1451 assert(myDataView.getRank()==1);
1452 assert(myDataView.noValues()==3);
1453 assert(myDataView.getShape().size()==1);
1454 assert(myDataView(0)==1);
1455 assert(myDataView(1)==2);
1456 assert(myDataView(2)==3);
1457
1458 myDataView = myData.getDataPointByTag(1);
1459 assert(myDataView==eOne.getView());
1460 assert(!myDataView.isEmpty());
1461 assert(myDataView.getOffset()==3);
1462 assert(myDataView.getRank()==1);
1463 assert(myDataView.noValues()==3);
1464 assert(myDataView.getShape().size()==1);
1465 assert(myDataView(0)==1);
1466 assert(myDataView(1)==2);
1467 assert(myDataView(2)==3);
1468
1469 // Test non-existent tag returns the default value.
1470 myDataView = myData.getDataPointByTag(0);
1471 assert(myDataView==myView);
1472 assert(!myDataView.isEmpty());
1473 assert(myDataView.getOffset()==0);
1474 assert(myDataView.getRank()==1);
1475 assert(myDataView.noValues()==3);
1476 assert(myDataView.getShape().size()==1);
1477 assert(myDataView(0)==0);
1478 assert(myDataView(1)==1);
1479 assert(myDataView(2)==2);
1480
1481 myDataView = myData.getDefaultValue();
1482 assert(myDataView==myView);
1483 assert(!myDataView.isEmpty());
1484 assert(myDataView.getOffset()==0);
1485 assert(myDataView.getRank()==1);
1486 assert(myDataView.noValues()==3);
1487 assert(myDataView.getShape().size()==1);
1488 assert(myDataView(0)==0);
1489 assert(myDataView(1)==1);
1490 assert(myDataView(2)==2);
1491
1492 }
1493
1494 {
1495
1496 cout << "\tTest DataTagged with multiple tags." << endl;
1497
1498 // the one data-point has tag value "1"
1499
1500 DataTagged::TagListType keys;
1501 keys.push_back(1);
1502 keys.push_back(2);
1503 keys.push_back(3);
1504
1505 DataTagged::ValueListType values;
1506
1507 DataArrayView::ShapeType viewShape;
1508 viewShape.push_back(3);
1509
1510 // default value
1511 DataArrayView::ValueType viewData(3);
1512 for (int i=0;i<viewShape[0];i++) {
1513 viewData[i]=i;
1514 }
1515 DataArrayView myView(viewData,viewShape);
1516
1517 // value for tag "1"
1518 DataArray eOne(myView);
1519 for (int i=0;i<eOne.getView().getShape()[0];i++) {
1520 eOne.getView()(i)=i+1.0;
1521 }
1522 values.push_back(eOne.getView());
1523
1524 // value for tag "2"
1525 DataArray eTwo(myView);
1526 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1527 eTwo.getView()(i)=i+2.0;
1528 }
1529 values.push_back(eTwo.getView());
1530
1531 // value for tag "3"
1532 DataArray eThree(myView);
1533 for (int i=0;i<eThree.getView().getShape()[0];i++) {
1534 eThree.getView()(i)=i+3.0;
1535 }
1536 values.push_back(eThree.getView());
1537
1538 DataTagged myData(keys,values,myView,FunctionSpace());
1539
1540 //cout << myData.toString() << endl;
1541
1542 assert(myData.getNumSamples()==1);
1543 assert(myData.getNumDPPSample()==1);
1544
1545 assert(myData.validSamplePointNo(0));
1546 assert(myData.validSampleNo(0));
1547 assert(!myData.validSamplePointNo(1));
1548 assert(!myData.validSampleNo(1));
1549
1550 // data-point 0 has tag number 1 by default
1551 assert(myData.getTagNumber(0)==1);
1552
1553 assert(!myData.isCurrentTag(0));
1554 assert(myData.isCurrentTag(1));
1555 assert(myData.isCurrentTag(2));
1556 assert(myData.isCurrentTag(3));
1557
1558 assert(myData.getTagLookup().size()==3);
1559
1560 assert(myData.getLength()==12);
1561
1562 assert(myData.getPointOffset(0,0)==3);
1563
1564 DataArrayView myDataView = myData.getDataPoint(0,0);
1565 assert(myDataView==eOne.getView());
1566 assert(!myDataView.isEmpty());
1567 assert(myDataView.getOffset()==3);
1568 assert(myDataView.getRank()==1);
1569 assert(myDataView.noValues()==3);
1570 assert(myDataView.getShape().size()==1);
1571 assert(myDataView(0)==1);
1572 assert(myDataView(1)==2);
1573 assert(myDataView(2)==3);
1574
1575 myDataView = myData.getDataPointByTag(1);
1576 assert(myDataView==eOne.getView());
1577 assert(!myDataView.isEmpty());
1578 assert(myDataView.getOffset()==3);
1579 assert(myDataView.getRank()==1);
1580 assert(myDataView.noValues()==3);
1581 assert(myDataView.getShape().size()==1);
1582 assert(myDataView(0)==1);
1583 assert(myDataView(1)==2);
1584 assert(myDataView(2)==3);
1585
1586 // Test non-existent tag returns the default value.
1587 myDataView = myData.getDataPointByTag(0);
1588 assert(myDataView==myView);
1589 assert(!myDataView.isEmpty());
1590 assert(myDataView.getOffset()==0);
1591 assert(myDataView.getRank()==1);
1592 assert(myDataView.noValues()==3);
1593 assert(myDataView.getShape().size()==1);
1594 assert(myDataView(0)==0);
1595 assert(myDataView(1)==1);
1596 assert(myDataView(2)==2);
1597
1598 myDataView = myData.getDefaultValue();
1599 assert(myDataView==myView);
1600 assert(!myDataView.isEmpty());
1601 assert(myDataView.getOffset()==0);
1602 assert(myDataView.getRank()==1);
1603 assert(myDataView.noValues()==3);
1604 assert(myDataView.getShape().size()==1);
1605 assert(myDataView(0)==0);
1606 assert(myDataView(1)==1);
1607 assert(myDataView(2)==2);
1608
1609 // Test data-points held for remaining tags
1610 myDataView = myData.getDataPointByTag(2);
1611 assert(myDataView==eTwo.getView());
1612 assert(!myDataView.isEmpty());
1613 assert(myDataView.getOffset()==6);
1614 assert(myDataView.getRank()==1);
1615 assert(myDataView.noValues()==3);
1616 assert(myDataView.getShape().size()==1);
1617 assert(myDataView(0)==2);
1618 assert(myDataView(1)==3);
1619 assert(myDataView(2)==4);
1620
1621 myDataView = myData.getDataPointByTag(3);
1622 assert(myDataView==eThree.getView());
1623 assert(!myDataView.isEmpty());
1624 assert(myDataView.getOffset()==9);
1625 assert(myDataView.getRank()==1);
1626 assert(myDataView.noValues()==3);
1627 assert(myDataView.getShape().size()==1);
1628 assert(myDataView(0)==3);
1629 assert(myDataView(1)==4);
1630 assert(myDataView(2)==5);
1631
1632 }
1633
1634 }
1635
1636 TestSuite* DataTaggedTestCase::suite ()
1637 {
1638 //
1639 // create the suite of tests to perform.
1640 TestSuite *testSuite = new TestSuite ("DataTaggedTestCase");
1641 testSuite->addTest (new TestCaller< DataTaggedTestCase>("testAll",&DataTaggedTestCase::testAll));
1642 testSuite->addTest (new TestCaller< DataTaggedTestCase>("testAddTaggedValues",&DataTaggedTestCase::testAddTaggedValues));
1643 testSuite->addTest (new TestCaller< DataTaggedTestCase>("testSetTaggedValue",&DataTaggedTestCase::testSetTaggedValue));
1644 // testSuite->addTest (new TestCaller< DataTaggedTestCase>("testOperations",&DataTaggedTestCase::testOperations));
1645 // testSuite->addTest (new TestCaller< DataTaggedTestCase>("testReshape",&DataTaggedTestCase::testReshape));
1646 return testSuite;
1647 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26