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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 504 - (show annotations)
Wed Feb 8 05:51:27 2006 UTC (13 years, 11 months ago) by jgs
Original Path: trunk/escript/test/DataTagged/DataTaggedTestCase.cpp
File size: 57690 byte(s)
initial testing of operations involving DataTagged objects

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 DataTagged myData;
92 DataTagged right;
93
94 cout << "\tTest addition of two default DataTagged objects." << endl;
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
145 {
146 DataTagged myData;
147 DataTagged right;
148
149 cout << "\tTest addition of two DataTagged objects with one identical tag each." << endl;
150
151 DataArray vOne(1.0);
152 myData.addTaggedValue(1,vOne.getView());
153 right.addTaggedValue(1,vOne.getView());
154
155 binaryOp(myData,right,plus<double>());
156
157 // check result value for tag "1"
158 DataArrayView myDataView = myData.getDataPointByTag(1);
159 assert(!myDataView.isEmpty());
160 assert(myDataView.getOffset()==1);
161 assert(myDataView.getRank()==0);
162 assert(myDataView.noValues()==1);
163 assert(myDataView.getShape().size()==0);
164 assert(myDataView()==2.0);
165
166 // check result for default value
167 myDataView = myData.getDefaultValue();
168 assert(!myDataView.isEmpty());
169 assert(myDataView.getOffset()==0);
170 assert(myDataView.getRank()==0);
171 assert(myDataView.noValues()==1);
172 assert(myDataView.getShape().size()==0);
173 assert(myDataView()==0.0);
174 }
175
176 {
177 DataTagged myData;
178 DataTagged right;
179
180 cout << "\tTest addition of two DataTagged objects with one different tag each." << endl;
181
182 DataArray vOne(1.0);
183 myData.addTaggedValue(1,vOne.getView());
184 right.addTaggedValue(2,vOne.getView());
185
186 binaryOp(myData,right,plus<double>());
187
188 // check result value for tag "1"
189 DataArrayView myDataView = myData.getDataPointByTag(1);
190 assert(!myDataView.isEmpty());
191 assert(myDataView.getOffset()==1);
192 assert(myDataView.getRank()==0);
193 assert(myDataView.noValues()==1);
194 assert(myDataView.getShape().size()==0);
195 assert(myDataView()==1.0);
196
197 // check result value for tag "2"
198 myDataView = myData.getDataPointByTag(2);
199 assert(!myDataView.isEmpty());
200 assert(myDataView.getOffset()==2);
201 assert(myDataView.getRank()==0);
202 assert(myDataView.noValues()==1);
203 assert(myDataView.getShape().size()==0);
204 assert(myDataView()==1.0);
205
206 // check result for default value
207 myDataView = myData.getDefaultValue();
208 assert(!myDataView.isEmpty());
209 assert(myDataView.getOffset()==0);
210 assert(myDataView.getRank()==0);
211 assert(myDataView.noValues()==1);
212 assert(myDataView.getShape().size()==0);
213 assert(myDataView()==0.0);
214 }
215
216 {
217 DataTagged myData;
218 DataTagged right;
219
220 cout << "\tTest addition of two DataTagged objects with overlapping tag sets." << endl;
221
222 DataArray vOne(1.0);
223 myData.addTaggedValue(1,vOne.getView());
224 myData.addTaggedValue(2,vOne.getView());
225 right.addTaggedValue(2,vOne.getView());
226 right.addTaggedValue(3,vOne.getView());
227
228 binaryOp(myData,right,plus<double>());
229
230 // check result value for tag "1"
231 DataArrayView myDataView = myData.getDataPointByTag(1);
232 assert(!myDataView.isEmpty());
233 assert(myDataView.getOffset()==1);
234 assert(myDataView.getRank()==0);
235 assert(myDataView.noValues()==1);
236 assert(myDataView.getShape().size()==0);
237 assert(myDataView()==1.0);
238
239 // check result value for tag "2"
240 myDataView = myData.getDataPointByTag(2);
241 assert(!myDataView.isEmpty());
242 assert(myDataView.getOffset()==2);
243 assert(myDataView.getRank()==0);
244 assert(myDataView.noValues()==1);
245 assert(myDataView.getShape().size()==0);
246 assert(myDataView()==2.0);
247
248 // check result value for tag "3"
249 myDataView = myData.getDataPointByTag(3);
250 assert(!myDataView.isEmpty());
251 assert(myDataView.getOffset()==3);
252 assert(myDataView.getRank()==0);
253 assert(myDataView.noValues()==1);
254 assert(myDataView.getShape().size()==0);
255 assert(myDataView()==1.0);
256
257 // check result for default value
258 myDataView = myData.getDefaultValue();
259 assert(!myDataView.isEmpty());
260 assert(myDataView.getOffset()==0);
261 assert(myDataView.getRank()==0);
262 assert(myDataView.noValues()==1);
263 assert(myDataView.getShape().size()==0);
264 assert(myDataView()==0.0);
265 }
266
267 {
268 //cout << "\tTest binaryOp(multiplies)." << endl;
269 //DataArray vZero(0.0);
270 //right.setTaggedValue(1,vZero.getView());
271 //right.setTaggedValue(2,vZero.getView());
272 //binaryOp(left,right,multiplies<double>());
273
274 //assert(left.getPointDataView()()==0);
275 //assert(left.getDataPointByTag(1)==vZero.getView());
276 //assert(left.getDataPointByTag(2)==vZero.getView());
277 }
278
279 {
280 //DataArrayView::ShapeType viewShape;
281 //viewShape.push_back(3);
282 //DataArrayView::ValueType viewData(3);
283 //DataTagged::TagListType keys;
284 //DataTagged::ValueListType values;
285 //for (int i=0;i<viewShape[0];++i) {
286 // viewData[i]=i;
287 //}
288 //DataArrayView myView(viewData,viewShape);
289 //cout << "\tCreate tagged data with no tag values just a default." << endl;
290 //DataTagged left(keys,values,myView,FunctionSpace());
291 //DataTagged right(keys,values,myView,FunctionSpace());
292 //binaryOp(left,right,minus<double>());
293 //for (int i=0;i<viewShape[0];++i) {
294 // assert(left.getDefaultValue()(i)==0);
295 //}
296 //double mVal=10.0;
297 //for (int i=0;i<viewShape[0];++i) {
298 // viewData[i]=i*mVal;
299 //}
300 //cout << "\tTest binaryOp(minus) with the right hand side as a view." << endl;
301 //binaryOp(left,myView,minus<double>());
302 //for (int i=0;i<viewShape[0];++i) {
303 // assert(left.getDefaultValue()(i)==-(i*mVal));
304 //}
305 }
306
307 {
308 //cout << "\tTest unaryOp(negate) on default DataTagged." << endl;
309 //DataTagged data;
310 //unaryOp(data,negate<double>());
311 //assert(data.getDefaultValue()()==0);
312 //DataArray vOne(1);
313 //binaryOp(data,vOne.getView(),plus<double>());
314 //assert(data.getDefaultValue()()==1);
315 //unaryOp(data,negate<double>());
316 //assert(data.getDefaultValue()()==-1);
317 }
318
319 {
320 //cout << "\tTest unaryOp(negate) on DataTagged with 3 tags." << endl;
321 //DataArrayView::ShapeType vShape;
322 //vShape.push_back(3);
323 //vShape.push_back(2);
324 //vShape.push_back(1);
325 //DataArray defData(vShape,0.0);
326 //DataArrayView& defView=defData.getView();
327 //DataArray tOneData(vShape,1.0);
328 //DataArrayView& tOneView=tOneData.getView();
329 //DataArray tTwoData(vShape,2.0);
330 //DataArrayView& tTwoView=tTwoData.getView();
331 //DataArray tThreeData(vShape,3.0);
332 //DataArrayView& tThreeView=tThreeData.getView();
333 //DataTagged::TagListType keys;
334 //DataTagged::ValueListType values;
335 //keys.push_back(1);
336 //keys.push_back(2);
337 //keys.push_back(3);
338 //values.push_back(tOneView);
339 //values.push_back(tTwoView);
340 //values.push_back(tThreeView);
341 //DataTagged tData(keys,values,defView,FunctionSpace());
342 //unaryOp(tData,negate<double>());
343 //unaryOp(tData,negate<double>());
344 //assert(tData.getDataPointByTag(1)==tOneView);
345 //assert(tData.getDataPointByTag(2)==tTwoView);
346 //assert(tData.getDataPointByTag(3)==tThreeView);
347 }
348
349 }
350
351 void DataTaggedTestCase::testAddTaggedValues() {
352
353 cout << endl;
354
355 {
356
357 cout << "\tTest adding one key with empty value list to default DataTagged." << endl;
358 DataTagged myData;
359
360 DataTagged::TagListType keys;
361 keys.push_back(1);
362
363 DataTagged::ValueListType values;
364
365 myData.addTaggedValues(keys,values);
366
367 assert(myData.isCurrentTag(1));
368
369 assert(myData.getTagLookup().size()==1);
370
371 assert(myData.getLength()==2);
372
373 // data-point 0 has tag number 1 by default
374 assert(myData.getTagNumber(0)==1);
375
376 assert(myData.getPointOffset(0,0)==1);
377
378 DataArrayView myDataView = myData.getDataPoint(0,0);
379 assert(!myDataView.isEmpty());
380 assert(myDataView.getOffset()==1);
381 assert(myDataView.getRank()==0);
382 assert(myDataView.noValues()==1);
383 assert(myDataView.getShape().size()==0);
384 assert(myDataView()==0.0);
385
386 myDataView = myData.getDataPointByTag(1);
387 assert(!myDataView.isEmpty());
388 assert(myDataView.getOffset()==1);
389 assert(myDataView.getRank()==0);
390 assert(myDataView.noValues()==1);
391 assert(myDataView.getShape().size()==0);
392 assert(myDataView()==0.0);
393
394 myDataView = myData.getDefaultValue();
395 assert(!myDataView.isEmpty());
396 assert(myDataView.getOffset()==0);
397 assert(myDataView.getRank()==0);
398 assert(myDataView.noValues()==1);
399 assert(myDataView.getShape().size()==0);
400 assert(myDataView()==0.0);
401
402 }
403
404 {
405
406 cout << "\tTest adding one key with one value to default DataTagged." << endl;
407 DataTagged myData;
408
409 DataTagged::TagListType keys;
410 keys.push_back(1);
411
412 DataTagged::ValueListType values;
413
414 DataArrayView::ShapeType viewShape;
415 DataArrayView::ValueType viewData(1);
416 viewData[0]=1.0;
417 DataArrayView myView(viewData,viewShape);
418 values.push_back(myView);
419
420 myData.addTaggedValues(keys,values);
421
422 assert(myData.isCurrentTag(1));
423
424 assert(myData.getTagLookup().size()==1);
425
426 assert(myData.getLength()==2);
427
428 // data-point 0 has tag number 1 by default
429 assert(myData.getTagNumber(0)==1);
430
431 assert(myData.getPointOffset(0,0)==1);
432
433 DataArrayView myDataView = myData.getDataPoint(0,0);
434 assert(!myDataView.isEmpty());
435 assert(myDataView.getOffset()==1);
436 assert(myDataView.getRank()==0);
437 assert(myDataView.noValues()==1);
438 assert(myDataView.getShape().size()==0);
439 assert(myDataView()==1.0);
440
441 myDataView = myData.getDataPointByTag(1);
442 assert(!myDataView.isEmpty());
443 assert(myDataView.getOffset()==1);
444 assert(myDataView.getRank()==0);
445 assert(myDataView.noValues()==1);
446 assert(myDataView.getShape().size()==0);
447 assert(myDataView()==1.0);
448
449 myDataView = myData.getDefaultValue();
450 assert(!myDataView.isEmpty());
451 assert(myDataView.getOffset()==0);
452 assert(myDataView.getRank()==0);
453 assert(myDataView.noValues()==1);
454 assert(myDataView.getShape().size()==0);
455 assert(myDataView()==0.0);
456
457 }
458
459 {
460
461 cout << "\tTest adding three keys with one value to default DataTagged." << endl;
462 DataTagged myData;
463
464 DataTagged::TagListType keys;
465 keys.push_back(1);
466 keys.push_back(2);
467 keys.push_back(3);
468
469 DataTagged::ValueListType values;
470
471 DataArrayView::ShapeType viewShape;
472 DataArrayView::ValueType viewData(1);
473 viewData[0]=1.0;
474 DataArrayView myView(viewData,viewShape);
475 values.push_back(myView);
476
477 myData.addTaggedValues(keys,values);
478
479 assert(myData.isCurrentTag(1));
480 assert(myData.isCurrentTag(2));
481 assert(myData.isCurrentTag(3));
482
483 assert(myData.getTagLookup().size()==3);
484
485 assert(myData.getLength()==4);
486
487 // data-point 0 has tag number 1 by default
488 assert(myData.getTagNumber(0)==1);
489
490 assert(myData.getPointOffset(0,0)==1);
491
492 DataArrayView myDataView = myData.getDataPoint(0,0);
493 assert(!myDataView.isEmpty());
494 assert(myDataView.getOffset()==1);
495 assert(myDataView.getRank()==0);
496 assert(myDataView.noValues()==1);
497 assert(myDataView.getShape().size()==0);
498 assert(myDataView()==1.0);
499
500 myDataView = myData.getDataPointByTag(1);
501 assert(!myDataView.isEmpty());
502 assert(myDataView.getOffset()==1);
503 assert(myDataView.getRank()==0);
504 assert(myDataView.noValues()==1);
505 assert(myDataView.getShape().size()==0);
506 assert(myDataView()==1.0);
507
508 myDataView = myData.getDataPointByTag(2);
509 assert(!myDataView.isEmpty());
510 assert(myDataView.getOffset()==2);
511 assert(myDataView.getRank()==0);
512 assert(myDataView.noValues()==1);
513 assert(myDataView.getShape().size()==0);
514 assert(myDataView()==1.0);
515
516 myDataView = myData.getDataPointByTag(3);
517 assert(!myDataView.isEmpty());
518 assert(myDataView.getOffset()==3);
519 assert(myDataView.getRank()==0);
520 assert(myDataView.noValues()==1);
521 assert(myDataView.getShape().size()==0);
522 assert(myDataView()==1.0);
523
524 myDataView = myData.getDefaultValue();
525 assert(!myDataView.isEmpty());
526 assert(myDataView.getOffset()==0);
527 assert(myDataView.getRank()==0);
528 assert(myDataView.noValues()==1);
529 assert(myDataView.getShape().size()==0);
530 assert(myDataView()==0.0);
531
532 }
533
534 {
535
536 cout << "\tTest adding three keys with three values to default DataTagged." << endl;
537 DataTagged myData;
538
539 DataTagged::TagListType keys;
540 keys.push_back(1);
541 keys.push_back(2);
542 keys.push_back(3);
543
544 DataTagged::ValueListType values;
545
546 DataArrayView::ShapeType viewShape;
547 DataArrayView::ValueType viewData1(1);
548 viewData1[0]=1.0;
549 DataArrayView::ValueType viewData2(1);
550 viewData2[0]=2.0;
551 DataArrayView::ValueType viewData3(1);
552 viewData3[0]=3.0;
553 DataArrayView myView1(viewData1,viewShape);
554 DataArrayView myView2(viewData2,viewShape);
555 DataArrayView myView3(viewData3,viewShape);
556 values.push_back(myView1);
557 values.push_back(myView2);
558 values.push_back(myView3);
559
560 myData.addTaggedValues(keys,values);
561
562 assert(myData.isCurrentTag(1));
563 assert(myData.isCurrentTag(2));
564 assert(myData.isCurrentTag(3));
565
566 assert(myData.getTagLookup().size()==3);
567
568 assert(myData.getLength()==4);
569
570 // data-point 0 has tag number 1 by default
571 assert(myData.getTagNumber(0)==1);
572
573 assert(myData.getPointOffset(0,0)==1);
574
575 DataArrayView myDataView = myData.getDataPoint(0,0);
576 assert(!myDataView.isEmpty());
577 assert(myDataView.getOffset()==1);
578 assert(myDataView.getRank()==0);
579 assert(myDataView.noValues()==1);
580 assert(myDataView.getShape().size()==0);
581 assert(myDataView()==1.0);
582
583 myDataView = myData.getDataPointByTag(1);
584 assert(!myDataView.isEmpty());
585 assert(myDataView.getOffset()==1);
586 assert(myDataView.getRank()==0);
587 assert(myDataView.noValues()==1);
588 assert(myDataView.getShape().size()==0);
589 assert(myDataView()==1.0);
590
591 myDataView = myData.getDataPointByTag(2);
592 assert(!myDataView.isEmpty());
593 assert(myDataView.getOffset()==2);
594 assert(myDataView.getRank()==0);
595 assert(myDataView.noValues()==1);
596 assert(myDataView.getShape().size()==0);
597 assert(myDataView()==2.0);
598
599 myDataView = myData.getDataPointByTag(3);
600 assert(!myDataView.isEmpty());
601 assert(myDataView.getOffset()==3);
602 assert(myDataView.getRank()==0);
603 assert(myDataView.noValues()==1);
604 assert(myDataView.getShape().size()==0);
605 assert(myDataView()==3.0);
606
607 myDataView = myData.getDefaultValue();
608 assert(!myDataView.isEmpty());
609 assert(myDataView.getOffset()==0);
610 assert(myDataView.getRank()==0);
611 assert(myDataView.noValues()==1);
612 assert(myDataView.getShape().size()==0);
613 assert(myDataView()==0.0);
614
615 }
616
617 {
618
619 cout << "\tTest adding one key with empty value list to DataTagged with default value only." << endl;
620
621 DataArrayView::ShapeType viewShape;
622 viewShape.push_back(3);
623
624 DataTagged::TagListType keys;
625
626 DataTagged::ValueListType values;
627
628 DataArrayView::ValueType viewData(3);
629 for (int i=0;i<viewShape[0];i++) {
630 viewData[i]=i;
631 }
632 DataArrayView myView(viewData,viewShape);
633
634 DataTagged myData(keys,values,myView,FunctionSpace());
635
636 keys.push_back(1);
637 values.clear();
638
639 myData.addTaggedValues(keys,values);
640
641 assert(myData.isCurrentTag(1));
642
643 assert(myData.getTagLookup().size()==1);
644
645 assert(myData.getLength()==6);
646
647 // data-point 0 has tag number 1 by default
648 assert(myData.getTagNumber(0)==1);
649
650 assert(myData.getPointOffset(0,0)==3);
651
652 DataArrayView myDataView = myData.getDataPoint(0,0);
653 assert(myDataView==myView);
654 assert(!myDataView.isEmpty());
655 assert(myDataView.getOffset()==3);
656 assert(myDataView.getRank()==1);
657 assert(myDataView.noValues()==3);
658 assert(myDataView.getShape().size()==1);
659 assert(myDataView(0)==0);
660 assert(myDataView(1)==1);
661 assert(myDataView(2)==2);
662
663 myDataView = myData.getDataPointByTag(1);
664 assert(myDataView==myView);
665 assert(!myDataView.isEmpty());
666 assert(myDataView.getOffset()==3);
667 assert(myDataView.getRank()==1);
668 assert(myDataView.noValues()==3);
669 assert(myDataView.getShape().size()==1);
670 assert(myDataView(0)==0);
671 assert(myDataView(1)==1);
672 assert(myDataView(2)==2);
673
674 myDataView = myData.getDefaultValue();
675 assert(myDataView==myView);
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 }
686
687 {
688
689 cout << "\tTest adding one key with one value to DataTagged with default value only." << endl;
690
691 DataArrayView::ShapeType viewShape;
692 viewShape.push_back(3);
693
694 DataTagged::TagListType keys;
695
696 DataTagged::ValueListType values;
697
698 DataArrayView::ValueType viewData(3);
699 for (int i=0;i<viewShape[0];i++) {
700 viewData[i]=i;
701 }
702 DataArrayView myView(viewData,viewShape);
703
704 DataTagged myData(keys,values,myView,FunctionSpace());
705
706 keys.push_back(1);
707
708 DataArrayView::ValueType viewData1(3);
709 for (int i=0;i<viewShape[0];i++) {
710 viewData1[i]=i+1;
711 }
712 DataArrayView myView1(viewData1,viewShape);
713 values.push_back(myView1);
714
715 myData.addTaggedValues(keys,values);
716
717 assert(myData.isCurrentTag(1));
718
719 assert(myData.getTagLookup().size()==1);
720
721 assert(myData.getLength()==6);
722
723 // data-point 0 has tag number 1 by default
724 assert(myData.getTagNumber(0)==1);
725
726 assert(myData.getPointOffset(0,0)==3);
727
728 DataArrayView myDataView = myData.getDataPoint(0,0);
729 assert(myDataView==myView1);
730 assert(!myDataView.isEmpty());
731 assert(myDataView.getOffset()==3);
732 assert(myDataView.getRank()==1);
733 assert(myDataView.noValues()==3);
734 assert(myDataView.getShape().size()==1);
735 assert(myDataView(0)==1);
736 assert(myDataView(1)==2);
737 assert(myDataView(2)==3);
738
739 myDataView = myData.getDataPointByTag(1);
740 assert(myDataView==myView1);
741 assert(!myDataView.isEmpty());
742 assert(myDataView.getOffset()==3);
743 assert(myDataView.getRank()==1);
744 assert(myDataView.noValues()==3);
745 assert(myDataView.getShape().size()==1);
746 assert(myDataView(0)==1);
747 assert(myDataView(1)==2);
748 assert(myDataView(2)==3);
749
750 myDataView = myData.getDefaultValue();
751 assert(myDataView==myView);
752 assert(!myDataView.isEmpty());
753 assert(myDataView.getOffset()==0);
754 assert(myDataView.getRank()==1);
755 assert(myDataView.noValues()==3);
756 assert(myDataView.getShape().size()==1);
757 assert(myDataView(0)==0);
758 assert(myDataView(1)==1);
759 assert(myDataView(2)==2);
760
761 }
762
763 {
764
765 cout << "\tTest adding three keys with one value to DataTagged with default value only." << endl;
766
767 DataArrayView::ShapeType viewShape;
768 viewShape.push_back(3);
769
770 DataTagged::TagListType keys;
771
772 DataTagged::ValueListType values;
773
774 DataArrayView::ValueType viewData(3);
775 for (int i=0;i<viewShape[0];i++) {
776 viewData[i]=i;
777 }
778 DataArrayView myView(viewData,viewShape);
779
780 DataTagged myData(keys,values,myView,FunctionSpace());
781
782 keys.push_back(1);
783 keys.push_back(2);
784 keys.push_back(3);
785
786 DataArrayView::ValueType viewData1(3);
787 for (int i=0;i<viewShape[0];i++) {
788 viewData1[i]=i+1;
789 }
790 DataArrayView myView1(viewData1,viewShape);
791 values.push_back(myView1);
792
793 myData.addTaggedValues(keys,values);
794
795 assert(myData.isCurrentTag(1));
796 assert(myData.isCurrentTag(2));
797 assert(myData.isCurrentTag(3));
798
799 assert(myData.getTagLookup().size()==3);
800
801 assert(myData.getLength()==12);
802
803 // data-point 0 has tag number 1 by default
804 assert(myData.getTagNumber(0)==1);
805
806 assert(myData.getPointOffset(0,0)==3);
807
808 DataArrayView myDataView = myData.getDataPoint(0,0);
809 assert(myDataView==myView1);
810 assert(!myDataView.isEmpty());
811 assert(myDataView.getOffset()==3);
812 assert(myDataView.getRank()==1);
813 assert(myDataView.noValues()==3);
814 assert(myDataView.getShape().size()==1);
815 assert(myDataView(0)==1);
816 assert(myDataView(1)==2);
817 assert(myDataView(2)==3);
818
819 myDataView = myData.getDataPointByTag(1);
820 assert(myDataView==myView1);
821 assert(!myDataView.isEmpty());
822 assert(myDataView.getOffset()==3);
823 assert(myDataView.getRank()==1);
824 assert(myDataView.noValues()==3);
825 assert(myDataView.getShape().size()==1);
826 assert(myDataView(0)==1);
827 assert(myDataView(1)==2);
828 assert(myDataView(2)==3);
829
830 myDataView = myData.getDataPointByTag(2);
831 assert(myDataView==myView1);
832 assert(!myDataView.isEmpty());
833 assert(myDataView.getOffset()==6);
834 assert(myDataView.getRank()==1);
835 assert(myDataView.noValues()==3);
836 assert(myDataView.getShape().size()==1);
837 assert(myDataView(0)==1);
838 assert(myDataView(1)==2);
839 assert(myDataView(2)==3);
840
841 myDataView = myData.getDataPointByTag(3);
842 assert(myDataView==myView1);
843 assert(!myDataView.isEmpty());
844 assert(myDataView.getOffset()==9);
845 assert(myDataView.getRank()==1);
846 assert(myDataView.noValues()==3);
847 assert(myDataView.getShape().size()==1);
848 assert(myDataView(0)==1);
849 assert(myDataView(1)==2);
850 assert(myDataView(2)==3);
851
852 myDataView = myData.getDefaultValue();
853 assert(myDataView==myView);
854 assert(!myDataView.isEmpty());
855 assert(myDataView.getOffset()==0);
856 assert(myDataView.getRank()==1);
857 assert(myDataView.noValues()==3);
858 assert(myDataView.getShape().size()==1);
859 assert(myDataView(0)==0);
860 assert(myDataView(1)==1);
861 assert(myDataView(2)==2);
862
863 }
864
865 {
866
867 cout << "\tTest adding three keys with three values to DataTagged with default value only." << endl;
868
869 DataArrayView::ShapeType viewShape;
870 viewShape.push_back(3);
871
872 DataTagged::TagListType keys;
873
874 DataTagged::ValueListType values;
875
876 DataArrayView::ValueType viewData(3);
877 for (int i=0;i<viewShape[0];i++) {
878 viewData[i]=i;
879 }
880 DataArrayView myView(viewData,viewShape);
881
882 DataTagged myData(keys,values,myView,FunctionSpace());
883
884 keys.push_back(1);
885 keys.push_back(2);
886 keys.push_back(3);
887
888 DataArrayView::ValueType viewData1(3);
889 for (int i=0;i<viewShape[0];i++) {
890 viewData1[i]=i+1;
891 }
892 DataArrayView myView1(viewData1,viewShape);
893 values.push_back(myView1);
894
895 DataArrayView::ValueType viewData2(3);
896 for (int i=0;i<viewShape[0];i++) {
897 viewData2[i]=i+2;
898 }
899 DataArrayView myView2(viewData2,viewShape);
900 values.push_back(myView2);
901
902 DataArrayView::ValueType viewData3(3);
903 for (int i=0;i<viewShape[0];i++) {
904 viewData3[i]=i+3;
905 }
906 DataArrayView myView3(viewData3,viewShape);
907 values.push_back(myView3);
908
909 myData.addTaggedValues(keys,values);
910
911 assert(myData.isCurrentTag(1));
912 assert(myData.isCurrentTag(2));
913 assert(myData.isCurrentTag(3));
914
915 assert(myData.getTagLookup().size()==3);
916
917 assert(myData.getLength()==12);
918
919 // data-point 0 has tag number 1 by default
920 assert(myData.getTagNumber(0)==1);
921
922 assert(myData.getPointOffset(0,0)==3);
923
924 DataArrayView myDataView = myData.getDataPoint(0,0);
925 assert(myDataView==myView1);
926 assert(!myDataView.isEmpty());
927 assert(myDataView.getOffset()==3);
928 assert(myDataView.getRank()==1);
929 assert(myDataView.noValues()==3);
930 assert(myDataView.getShape().size()==1);
931 assert(myDataView(0)==1);
932 assert(myDataView(1)==2);
933 assert(myDataView(2)==3);
934
935 myDataView = myData.getDataPointByTag(1);
936 assert(myDataView==myView1);
937 assert(!myDataView.isEmpty());
938 assert(myDataView.getOffset()==3);
939 assert(myDataView.getRank()==1);
940 assert(myDataView.noValues()==3);
941 assert(myDataView.getShape().size()==1);
942 assert(myDataView(0)==1);
943 assert(myDataView(1)==2);
944 assert(myDataView(2)==3);
945
946 myDataView = myData.getDataPointByTag(2);
947 assert(myDataView==myView2);
948 assert(!myDataView.isEmpty());
949 assert(myDataView.getOffset()==6);
950 assert(myDataView.getRank()==1);
951 assert(myDataView.noValues()==3);
952 assert(myDataView.getShape().size()==1);
953 assert(myDataView(0)==2);
954 assert(myDataView(1)==3);
955 assert(myDataView(2)==4);
956
957 myDataView = myData.getDataPointByTag(3);
958 assert(myDataView==myView3);
959 assert(!myDataView.isEmpty());
960 assert(myDataView.getOffset()==9);
961 assert(myDataView.getRank()==1);
962 assert(myDataView.noValues()==3);
963 assert(myDataView.getShape().size()==1);
964 assert(myDataView(0)==3);
965 assert(myDataView(1)==4);
966 assert(myDataView(2)==5);
967
968 myDataView = myData.getDefaultValue();
969 assert(myDataView==myView);
970 assert(!myDataView.isEmpty());
971 assert(myDataView.getOffset()==0);
972 assert(myDataView.getRank()==1);
973 assert(myDataView.noValues()==3);
974 assert(myDataView.getShape().size()==1);
975 assert(myDataView(0)==0);
976 assert(myDataView(1)==1);
977 assert(myDataView(2)==2);
978
979 }
980
981 {
982
983 cout << "\tTest adding one key with empty value list to DataTagged with three tags." << endl;
984
985 DataTagged::TagListType keys;
986 keys.push_back(1);
987 keys.push_back(2);
988 keys.push_back(3);
989
990 DataTagged::ValueListType values;
991
992 DataArrayView::ShapeType viewShape;
993 viewShape.push_back(3);
994
995 // default value
996 DataArrayView::ValueType viewData(3);
997 for (int i=0;i<viewShape[0];i++) {
998 viewData[i]=i;
999 }
1000 DataArrayView myView(viewData,viewShape);
1001
1002 // value for tag "1"
1003 DataArray eOne(myView);
1004 for (int i=0;i<eOne.getView().getShape()[0];i++) {
1005 eOne.getView()(i)=i+1.0;
1006 }
1007 values.push_back(eOne.getView());
1008
1009 // value for tag "2"
1010 DataArray eTwo(myView);
1011 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1012 eTwo.getView()(i)=i+2.0;
1013 }
1014 values.push_back(eTwo.getView());
1015
1016 // value for tag "3"
1017 DataArray eThree(myView);
1018 for (int i=0;i<eThree.getView().getShape()[0];i++) {
1019 eThree.getView()(i)=i+3.0;
1020 }
1021 values.push_back(eThree.getView());
1022
1023 DataTagged myData(keys,values,myView,FunctionSpace());
1024
1025 keys.clear();
1026 keys.push_back(4);
1027 values.clear();
1028
1029 myData.addTaggedValues(keys,values);
1030
1031 assert(myData.isCurrentTag(4));
1032
1033 assert(myData.getTagLookup().size()==4);
1034
1035 assert(myData.getLength()==15);
1036
1037 DataArrayView myDataView = myData.getDataPointByTag(4);
1038 assert(myDataView==myView);
1039 assert(!myDataView.isEmpty());
1040 assert(myDataView.getOffset()==12);
1041 assert(myDataView.getRank()==1);
1042 assert(myDataView.noValues()==3);
1043 assert(myDataView.getShape().size()==1);
1044 assert(myDataView(0)==0);
1045 assert(myDataView(1)==1);
1046 assert(myDataView(2)==2);
1047
1048 }
1049
1050 {
1051
1052 cout << "\tTest adding one key with one value to DataTagged with three tags." << endl;
1053
1054 DataTagged::TagListType keys;
1055 keys.push_back(1);
1056 keys.push_back(2);
1057 keys.push_back(3);
1058
1059 DataTagged::ValueListType values;
1060
1061 DataArrayView::ShapeType viewShape;
1062 viewShape.push_back(3);
1063
1064 // default value
1065 DataArrayView::ValueType viewData(3);
1066 for (int i=0;i<viewShape[0];i++) {
1067 viewData[i]=i;
1068 }
1069 DataArrayView myView(viewData,viewShape);
1070
1071 // value for tag "1"
1072 DataArray eOne(myView);
1073 for (int i=0;i<eOne.getView().getShape()[0];i++) {
1074 eOne.getView()(i)=i+1.0;
1075 }
1076 values.push_back(eOne.getView());
1077
1078 // value for tag "2"
1079 DataArray eTwo(myView);
1080 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1081 eTwo.getView()(i)=i+2.0;
1082 }
1083 values.push_back(eTwo.getView());
1084
1085 // value for tag "3"
1086 DataArray eThree(myView);
1087 for (int i=0;i<eThree.getView().getShape()[0];i++) {
1088 eThree.getView()(i)=i+3.0;
1089 }
1090 values.push_back(eThree.getView());
1091
1092 DataTagged myData(keys,values,myView,FunctionSpace());
1093
1094 keys.clear();
1095 keys.push_back(4);
1096
1097 values.clear();
1098 // value for tag "4"
1099 DataArray eFour(myView);
1100 for (int i=0;i<eFour.getView().getShape()[0];i++) {
1101 eFour.getView()(i)=i+4.0;
1102 }
1103 values.push_back(eFour.getView());
1104
1105 myData.addTaggedValues(keys,values);
1106
1107 assert(myData.isCurrentTag(4));
1108
1109 assert(myData.getTagLookup().size()==4);
1110
1111 assert(myData.getLength()==15);
1112
1113 DataArrayView myDataView = myData.getDataPointByTag(4);
1114 assert(myDataView==eFour.getView());
1115 assert(!myDataView.isEmpty());
1116 assert(myDataView.getOffset()==12);
1117 assert(myDataView.getRank()==1);
1118 assert(myDataView.noValues()==3);
1119 assert(myDataView.getShape().size()==1);
1120 assert(myDataView(0)==4);
1121 assert(myDataView(1)==5);
1122 assert(myDataView(2)==6);
1123
1124 }
1125
1126 {
1127
1128 cout << "\tTest adding three keys with one value to DataTagged with three tags." << endl;
1129
1130 DataTagged::TagListType keys;
1131 keys.push_back(1);
1132 keys.push_back(2);
1133 keys.push_back(3);
1134
1135 DataTagged::ValueListType values;
1136
1137 DataArrayView::ShapeType viewShape;
1138 viewShape.push_back(3);
1139
1140 // default value
1141 DataArrayView::ValueType viewData(3);
1142 for (int i=0;i<viewShape[0];i++) {
1143 viewData[i]=i;
1144 }
1145 DataArrayView myView(viewData,viewShape);
1146
1147 // value for tag "1"
1148 DataArray eOne(myView);
1149 for (int i=0;i<eOne.getView().getShape()[0];i++) {
1150 eOne.getView()(i)=i+1.0;
1151 }
1152 values.push_back(eOne.getView());
1153
1154 // value for tag "2"
1155 DataArray eTwo(myView);
1156 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1157 eTwo.getView()(i)=i+2.0;
1158 }
1159 values.push_back(eTwo.getView());
1160
1161 // value for tag "3"
1162 DataArray eThree(myView);
1163 for (int i=0;i<eThree.getView().getShape()[0];i++) {
1164 eThree.getView()(i)=i+3.0;
1165 }
1166 values.push_back(eThree.getView());
1167
1168 DataTagged myData(keys,values,myView,FunctionSpace());
1169
1170 keys.clear();
1171 keys.push_back(4);
1172 keys.push_back(5);
1173 keys.push_back(6);
1174
1175 values.clear();
1176 // value for tags "4", "5" and "6"
1177 DataArray eFour(myView);
1178 for (int i=0;i<eFour.getView().getShape()[0];i++) {
1179 eFour.getView()(i)=i+4.0;
1180 }
1181 values.push_back(eFour.getView());
1182
1183 myData.addTaggedValues(keys,values);
1184
1185 assert(myData.isCurrentTag(4));
1186 assert(myData.isCurrentTag(5));
1187 assert(myData.isCurrentTag(6));
1188
1189 assert(myData.getTagLookup().size()==6);
1190
1191 assert(myData.getLength()==21);
1192
1193 DataArrayView myDataView = myData.getDataPointByTag(4);
1194 assert(myDataView==eFour.getView());
1195 assert(!myDataView.isEmpty());
1196 assert(myDataView.getOffset()==12);
1197 assert(myDataView.getRank()==1);
1198 assert(myDataView.noValues()==3);
1199 assert(myDataView.getShape().size()==1);
1200 assert(myDataView(0)==4);
1201 assert(myDataView(1)==5);
1202 assert(myDataView(2)==6);
1203
1204 myDataView = myData.getDataPointByTag(5);
1205 assert(myDataView==eFour.getView());
1206 assert(!myDataView.isEmpty());
1207 assert(myDataView.getOffset()==15);
1208 assert(myDataView.getRank()==1);
1209 assert(myDataView.noValues()==3);
1210 assert(myDataView.getShape().size()==1);
1211 assert(myDataView(0)==4);
1212 assert(myDataView(1)==5);
1213 assert(myDataView(2)==6);
1214
1215 myDataView = myData.getDataPointByTag(6);
1216 assert(myDataView==eFour.getView());
1217 assert(!myDataView.isEmpty());
1218 assert(myDataView.getOffset()==18);
1219 assert(myDataView.getRank()==1);
1220 assert(myDataView.noValues()==3);
1221 assert(myDataView.getShape().size()==1);
1222 assert(myDataView(0)==4);
1223 assert(myDataView(1)==5);
1224 assert(myDataView(2)==6);
1225
1226 }
1227
1228 {
1229
1230 cout << "\tTest adding three keys with three values to DataTagged with three tags." << endl;
1231
1232 DataTagged::TagListType keys;
1233 keys.push_back(1);
1234 keys.push_back(2);
1235 keys.push_back(3);
1236
1237 DataTagged::ValueListType values;
1238
1239 DataArrayView::ShapeType viewShape;
1240 viewShape.push_back(3);
1241
1242 // default value
1243 DataArrayView::ValueType viewData(3);
1244 for (int i=0;i<viewShape[0];i++) {
1245 viewData[i]=i;
1246 }
1247 DataArrayView myView(viewData,viewShape);
1248
1249 // value for tag "1"
1250 DataArray eOne(myView);
1251 for (int i=0;i<eOne.getView().getShape()[0];i++) {
1252 eOne.getView()(i)=i+1.0;
1253 }
1254 values.push_back(eOne.getView());
1255
1256 // value for tag "2"
1257 DataArray eTwo(myView);
1258 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1259 eTwo.getView()(i)=i+2.0;
1260 }
1261 values.push_back(eTwo.getView());
1262
1263 // value for tag "3"
1264 DataArray eThree(myView);
1265 for (int i=0;i<eThree.getView().getShape()[0];i++) {
1266 eThree.getView()(i)=i+3.0;
1267 }
1268 values.push_back(eThree.getView());
1269
1270 DataTagged myData(keys,values,myView,FunctionSpace());
1271
1272 keys.clear();
1273 keys.push_back(4);
1274 keys.push_back(5);
1275 keys.push_back(6);
1276
1277 values.clear();
1278
1279 // value for tag "4"
1280 DataArray eFour(myView);
1281 for (int i=0;i<eFour.getView().getShape()[0];i++) {
1282 eFour.getView()(i)=i+4.0;
1283 }
1284 values.push_back(eFour.getView());
1285
1286 // value for tag "5"
1287 DataArray eFive(myView);
1288 for (int i=0;i<eFive.getView().getShape()[0];i++) {
1289 eFive.getView()(i)=i+5.0;
1290 }
1291 values.push_back(eFive.getView());
1292
1293 // value for tag "6"
1294 DataArray eSix(myView);
1295 for (int i=0;i<eSix.getView().getShape()[0];i++) {
1296 eSix.getView()(i)=i+6.0;
1297 }
1298 values.push_back(eSix.getView());
1299
1300 myData.addTaggedValues(keys,values);
1301
1302 assert(myData.isCurrentTag(4));
1303 assert(myData.isCurrentTag(5));
1304 assert(myData.isCurrentTag(6));
1305
1306 assert(myData.getTagLookup().size()==6);
1307
1308 assert(myData.getLength()==21);
1309
1310 DataArrayView myDataView = myData.getDataPointByTag(4);
1311 assert(myDataView==eFour.getView());
1312 assert(!myDataView.isEmpty());
1313 assert(myDataView.getOffset()==12);
1314 assert(myDataView.getRank()==1);
1315 assert(myDataView.noValues()==3);
1316 assert(myDataView.getShape().size()==1);
1317 assert(myDataView(0)==4);
1318 assert(myDataView(1)==5);
1319 assert(myDataView(2)==6);
1320
1321 myDataView = myData.getDataPointByTag(5);
1322 assert(myDataView==eFive.getView());
1323 assert(!myDataView.isEmpty());
1324 assert(myDataView.getOffset()==15);
1325 assert(myDataView.getRank()==1);
1326 assert(myDataView.noValues()==3);
1327 assert(myDataView.getShape().size()==1);
1328 assert(myDataView(0)==5);
1329 assert(myDataView(1)==6);
1330 assert(myDataView(2)==7);
1331
1332 myDataView = myData.getDataPointByTag(6);
1333 assert(myDataView==eSix.getView());
1334 assert(!myDataView.isEmpty());
1335 assert(myDataView.getOffset()==18);
1336 assert(myDataView.getRank()==1);
1337 assert(myDataView.noValues()==3);
1338 assert(myDataView.getShape().size()==1);
1339 assert(myDataView(0)==6);
1340 assert(myDataView(1)==7);
1341 assert(myDataView(2)==8);
1342
1343 }
1344
1345 }
1346
1347 void DataTaggedTestCase::testSetTaggedValue() {
1348
1349 cout << endl;
1350
1351 {
1352
1353 cout << "\tTest setting key in DataTagged with three tags." << endl;
1354
1355 DataTagged::TagListType keys;
1356 keys.push_back(1);
1357 keys.push_back(2);
1358 keys.push_back(3);
1359
1360 DataTagged::ValueListType values;
1361
1362 DataArrayView::ShapeType viewShape;
1363 viewShape.push_back(3);
1364
1365 // default value
1366 DataArrayView::ValueType viewData(3);
1367 for (int i=0;i<viewShape[0];i++) {
1368 viewData[i]=i;
1369 }
1370 DataArrayView myView(viewData,viewShape);
1371
1372 // value for tag "1"
1373 DataArray eOne(myView);
1374 for (int i=0;i<eOne.getView().getShape()[0];i++) {
1375 eOne.getView()(i)=i+1.0;
1376 }
1377 values.push_back(eOne.getView());
1378
1379 // value for tag "2"
1380 DataArray eTwo(myView);
1381 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1382 eTwo.getView()(i)=i+2.0;
1383 }
1384 values.push_back(eTwo.getView());
1385
1386 // value for tag "3"
1387 DataArray eThree(myView);
1388 for (int i=0;i<eThree.getView().getShape()[0];i++) {
1389 eThree.getView()(i)=i+3.0;
1390 }
1391 values.push_back(eThree.getView());
1392
1393 DataTagged myData(keys,values,myView,FunctionSpace());
1394
1395 // new value for tag "2"
1396 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1397 eTwo.getView()(i)=i+5.0;
1398 }
1399
1400 myData.setTaggedValue(2,eTwo.getView());
1401
1402 assert(myData.isCurrentTag(2));
1403
1404 assert(myData.getTagLookup().size()==3);
1405
1406 assert(myData.getLength()==12);
1407
1408 DataArrayView myDataView = myData.getDataPointByTag(2);
1409 assert(myDataView==eTwo.getView());
1410 assert(!myDataView.isEmpty());
1411 assert(myDataView.getOffset()==6);
1412 assert(myDataView.getRank()==1);
1413 assert(myDataView.noValues()==3);
1414 assert(myDataView.getShape().size()==1);
1415 assert(myDataView(0)==5);
1416 assert(myDataView(1)==6);
1417 assert(myDataView(2)==7);
1418
1419 }
1420
1421 }
1422
1423 void DataTaggedTestCase::testAll() {
1424
1425 cout << endl;
1426
1427 {
1428
1429 cout << "\tTest default DataTagged." << endl;
1430 DataTagged myData;
1431
1432 //cout << myData.toString() << endl;
1433
1434 assert(myData.getNumSamples()==1);
1435 assert(myData.getNumDPPSample()==1);
1436
1437 assert(myData.validSamplePointNo(0));
1438 assert(myData.validSampleNo(0));
1439 assert(!myData.validSamplePointNo(1));
1440 assert(!myData.validSampleNo(1));
1441
1442 // data-point 0 has tag number 1 by default
1443 assert(myData.getTagNumber(0)==1);
1444
1445 assert(!myData.isCurrentTag(1));
1446
1447 assert(myData.getTagLookup().size()==0);
1448
1449 assert(myData.getLength()==1);
1450
1451 assert(myData.getPointOffset(0,0)==0);
1452
1453 DataArrayView myDataView = myData.getDataPoint(0,0);
1454 assert(!myDataView.isEmpty());
1455 assert(myDataView.getOffset()==0);
1456 assert(myDataView.getRank()==0);
1457 assert(myDataView.noValues()==1);
1458 assert(myDataView.getShape().size()==0);
1459 assert(myDataView()==0.0);
1460
1461 // Test non-existent tag returns the default value.
1462 myDataView = myData.getDataPointByTag(1);
1463 assert(!myDataView.isEmpty());
1464 assert(myDataView.getOffset()==0);
1465 assert(myDataView.getRank()==0);
1466 assert(myDataView.noValues()==1);
1467 assert(myDataView.getShape().size()==0);
1468 assert(myDataView()==0.0);
1469
1470 myDataView = myData.getDefaultValue();
1471 assert(!myDataView.isEmpty());
1472 assert(myDataView.getOffset()==0);
1473 assert(myDataView.getRank()==0);
1474 assert(myDataView.noValues()==1);
1475 assert(myDataView.getShape().size()==0);
1476 assert(myDataView()==0.0);
1477
1478 }
1479
1480 {
1481
1482 cout << "\tTest DataTagged with default value only." << endl;
1483
1484 DataArrayView::ShapeType viewShape;
1485 viewShape.push_back(3);
1486
1487 DataTagged::TagListType keys;
1488
1489 DataTagged::ValueListType values;
1490
1491 DataArrayView::ValueType viewData(3);
1492 for (int i=0;i<viewShape[0];i++) {
1493 viewData[i]=i;
1494 }
1495 DataArrayView myView(viewData,viewShape);
1496
1497 DataTagged myData(keys,values,myView,FunctionSpace());
1498
1499 //cout << myData.toString() << endl;
1500
1501 assert(myData.getNumSamples()==1);
1502 assert(myData.getNumDPPSample()==1);
1503
1504 assert(myData.validSamplePointNo(0));
1505 assert(myData.validSampleNo(0));
1506 assert(!myData.validSamplePointNo(1));
1507 assert(!myData.validSampleNo(1));
1508
1509 // data-point 0 has tag number 1 by default
1510 assert(myData.getTagNumber(0)==1);
1511
1512 assert(!myData.isCurrentTag(1));
1513
1514 assert(myData.getTagLookup().size()==0);
1515
1516 assert(myData.getLength()==3);
1517
1518 assert(myData.getPointOffset(0,0)==0);
1519
1520 DataArrayView myDataView = myData.getDataPoint(0,0);
1521 assert(myDataView==myView);
1522 assert(!myDataView.isEmpty());
1523 assert(myDataView.getOffset()==0);
1524 assert(myDataView.getRank()==1);
1525 assert(myDataView.noValues()==3);
1526 assert(myDataView.getShape().size()==1);
1527 assert(myDataView(0)==0);
1528 assert(myDataView(1)==1);
1529 assert(myDataView(2)==2);
1530
1531 // Test non-existent tag returns the default value.
1532 myDataView = myData.getDataPointByTag(1);
1533 assert(myDataView==myView);
1534 assert(!myDataView.isEmpty());
1535 assert(myDataView.getOffset()==0);
1536 assert(myDataView.getRank()==1);
1537 assert(myDataView.noValues()==3);
1538 assert(myDataView.getShape().size()==1);
1539 assert(myDataView(0)==0);
1540 assert(myDataView(1)==1);
1541 assert(myDataView(2)==2);
1542
1543 myDataView = myData.getDefaultValue();
1544 assert(myDataView==myView);
1545 assert(!myDataView.isEmpty());
1546 assert(myDataView.getOffset()==0);
1547 assert(myDataView.getRank()==1);
1548 assert(myDataView.noValues()==3);
1549 assert(myDataView.getShape().size()==1);
1550 assert(myDataView(0)==0);
1551 assert(myDataView(1)==1);
1552 assert(myDataView(2)==2);
1553
1554 }
1555
1556 {
1557
1558 cout << "\tTest DataTagged with one tag." << endl;
1559
1560 // the one data-point has tag value "1"
1561
1562 DataTagged::TagListType keys;
1563 keys.push_back(1);
1564
1565 DataTagged::ValueListType values;
1566
1567 DataArrayView::ShapeType viewShape;
1568 viewShape.push_back(3);
1569
1570 // default value
1571 DataArrayView::ValueType viewData(3);
1572 for (int i=0;i<viewShape[0];i++) {
1573 viewData[i]=i;
1574 }
1575 DataArrayView myView(viewData,viewShape);
1576
1577 // value for tag "1"
1578 DataArray eOne(myView);
1579 for (int i=0;i<eOne.getView().getShape()[0];i++) {
1580 eOne.getView()(i)=i+1.0;
1581 }
1582 values.push_back(eOne.getView());
1583
1584 DataTagged myData(keys,values,myView,FunctionSpace());
1585
1586 //cout << myData.toString() << endl;
1587
1588 assert(myData.getNumSamples()==1);
1589 assert(myData.getNumDPPSample()==1);
1590
1591 assert(myData.validSamplePointNo(0));
1592 assert(myData.validSampleNo(0));
1593 assert(!myData.validSamplePointNo(1));
1594 assert(!myData.validSampleNo(1));
1595
1596 // data-point 0 has tag number 1 by default
1597 assert(myData.getTagNumber(0)==1);
1598
1599 assert(!myData.isCurrentTag(0));
1600 assert(myData.isCurrentTag(1));
1601
1602 assert(myData.getTagLookup().size()==1);
1603
1604 assert(myData.getLength()==6);
1605
1606 assert(myData.getPointOffset(0,0)==3);
1607
1608 DataArrayView myDataView = myData.getDataPoint(0,0);
1609 assert(myDataView==eOne.getView());
1610 assert(!myDataView.isEmpty());
1611 assert(myDataView.getOffset()==3);
1612 assert(myDataView.getRank()==1);
1613 assert(myDataView.noValues()==3);
1614 assert(myDataView.getShape().size()==1);
1615 assert(myDataView(0)==1);
1616 assert(myDataView(1)==2);
1617 assert(myDataView(2)==3);
1618
1619 myDataView = myData.getDataPointByTag(1);
1620 assert(myDataView==eOne.getView());
1621 assert(!myDataView.isEmpty());
1622 assert(myDataView.getOffset()==3);
1623 assert(myDataView.getRank()==1);
1624 assert(myDataView.noValues()==3);
1625 assert(myDataView.getShape().size()==1);
1626 assert(myDataView(0)==1);
1627 assert(myDataView(1)==2);
1628 assert(myDataView(2)==3);
1629
1630 // Test non-existent tag returns the default value.
1631 myDataView = myData.getDataPointByTag(0);
1632 assert(myDataView==myView);
1633 assert(!myDataView.isEmpty());
1634 assert(myDataView.getOffset()==0);
1635 assert(myDataView.getRank()==1);
1636 assert(myDataView.noValues()==3);
1637 assert(myDataView.getShape().size()==1);
1638 assert(myDataView(0)==0);
1639 assert(myDataView(1)==1);
1640 assert(myDataView(2)==2);
1641
1642 myDataView = myData.getDefaultValue();
1643 assert(myDataView==myView);
1644 assert(!myDataView.isEmpty());
1645 assert(myDataView.getOffset()==0);
1646 assert(myDataView.getRank()==1);
1647 assert(myDataView.noValues()==3);
1648 assert(myDataView.getShape().size()==1);
1649 assert(myDataView(0)==0);
1650 assert(myDataView(1)==1);
1651 assert(myDataView(2)==2);
1652
1653 }
1654
1655 {
1656
1657 cout << "\tTest DataTagged with multiple tags." << endl;
1658
1659 // the one data-point has tag value "1"
1660
1661 DataTagged::TagListType keys;
1662 keys.push_back(1);
1663 keys.push_back(2);
1664 keys.push_back(3);
1665
1666 DataTagged::ValueListType values;
1667
1668 DataArrayView::ShapeType viewShape;
1669 viewShape.push_back(3);
1670
1671 // default value
1672 DataArrayView::ValueType viewData(3);
1673 for (int i=0;i<viewShape[0];i++) {
1674 viewData[i]=i;
1675 }
1676 DataArrayView myView(viewData,viewShape);
1677
1678 // value for tag "1"
1679 DataArray eOne(myView);
1680 for (int i=0;i<eOne.getView().getShape()[0];i++) {
1681 eOne.getView()(i)=i+1.0;
1682 }
1683 values.push_back(eOne.getView());
1684
1685 // value for tag "2"
1686 DataArray eTwo(myView);
1687 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1688 eTwo.getView()(i)=i+2.0;
1689 }
1690 values.push_back(eTwo.getView());
1691
1692 // value for tag "3"
1693 DataArray eThree(myView);
1694 for (int i=0;i<eThree.getView().getShape()[0];i++) {
1695 eThree.getView()(i)=i+3.0;
1696 }
1697 values.push_back(eThree.getView());
1698
1699 DataTagged myData(keys,values,myView,FunctionSpace());
1700
1701 //cout << myData.toString() << endl;
1702
1703 assert(myData.getNumSamples()==1);
1704 assert(myData.getNumDPPSample()==1);
1705
1706 assert(myData.validSamplePointNo(0));
1707 assert(myData.validSampleNo(0));
1708 assert(!myData.validSamplePointNo(1));
1709 assert(!myData.validSampleNo(1));
1710
1711 // data-point 0 has tag number 1 by default
1712 assert(myData.getTagNumber(0)==1);
1713
1714 assert(!myData.isCurrentTag(0));
1715 assert(myData.isCurrentTag(1));
1716 assert(myData.isCurrentTag(2));
1717 assert(myData.isCurrentTag(3));
1718
1719 assert(myData.getTagLookup().size()==3);
1720
1721 assert(myData.getLength()==12);
1722
1723 assert(myData.getPointOffset(0,0)==3);
1724
1725 DataArrayView myDataView = myData.getDataPoint(0,0);
1726 assert(myDataView==eOne.getView());
1727 assert(!myDataView.isEmpty());
1728 assert(myDataView.getOffset()==3);
1729 assert(myDataView.getRank()==1);
1730 assert(myDataView.noValues()==3);
1731 assert(myDataView.getShape().size()==1);
1732 assert(myDataView(0)==1);
1733 assert(myDataView(1)==2);
1734 assert(myDataView(2)==3);
1735
1736 myDataView = myData.getDataPointByTag(1);
1737 assert(myDataView==eOne.getView());
1738 assert(!myDataView.isEmpty());
1739 assert(myDataView.getOffset()==3);
1740 assert(myDataView.getRank()==1);
1741 assert(myDataView.noValues()==3);
1742 assert(myDataView.getShape().size()==1);
1743 assert(myDataView(0)==1);
1744 assert(myDataView(1)==2);
1745 assert(myDataView(2)==3);
1746
1747 // Test non-existent tag returns the default value.
1748 myDataView = myData.getDataPointByTag(0);
1749 assert(myDataView==myView);
1750 assert(!myDataView.isEmpty());
1751 assert(myDataView.getOffset()==0);
1752 assert(myDataView.getRank()==1);
1753 assert(myDataView.noValues()==3);
1754 assert(myDataView.getShape().size()==1);
1755 assert(myDataView(0)==0);
1756 assert(myDataView(1)==1);
1757 assert(myDataView(2)==2);
1758
1759 myDataView = myData.getDefaultValue();
1760 assert(myDataView==myView);
1761 assert(!myDataView.isEmpty());
1762 assert(myDataView.getOffset()==0);
1763 assert(myDataView.getRank()==1);
1764 assert(myDataView.noValues()==3);
1765 assert(myDataView.getShape().size()==1);
1766 assert(myDataView(0)==0);
1767 assert(myDataView(1)==1);
1768 assert(myDataView(2)==2);
1769
1770 // Test data-points held for remaining tags
1771 myDataView = myData.getDataPointByTag(2);
1772 assert(myDataView==eTwo.getView());
1773 assert(!myDataView.isEmpty());
1774 assert(myDataView.getOffset()==6);
1775 assert(myDataView.getRank()==1);
1776 assert(myDataView.noValues()==3);
1777 assert(myDataView.getShape().size()==1);
1778 assert(myDataView(0)==2);
1779 assert(myDataView(1)==3);
1780 assert(myDataView(2)==4);
1781
1782 myDataView = myData.getDataPointByTag(3);
1783 assert(myDataView==eThree.getView());
1784 assert(!myDataView.isEmpty());
1785 assert(myDataView.getOffset()==9);
1786 assert(myDataView.getRank()==1);
1787 assert(myDataView.noValues()==3);
1788 assert(myDataView.getShape().size()==1);
1789 assert(myDataView(0)==3);
1790 assert(myDataView(1)==4);
1791 assert(myDataView(2)==5);
1792
1793 }
1794
1795 }
1796
1797 void DataTaggedTestCase::testCopyConstructors() {
1798
1799 cout << endl;
1800
1801 {
1802
1803 cout << "\tTest DataTagged copy constructor for DataTagged with multiple tags." << endl;
1804
1805 // the one data-point has tag value "1"
1806
1807 DataTagged::TagListType keys;
1808 keys.push_back(1);
1809 keys.push_back(2);
1810 keys.push_back(3);
1811
1812 DataTagged::ValueListType values;
1813
1814 DataArrayView::ShapeType viewShape;
1815 viewShape.push_back(3);
1816
1817 // default value
1818 DataArrayView::ValueType viewData(3);
1819 for (int i=0;i<viewShape[0];i++) {
1820 viewData[i]=i;
1821 }
1822 DataArrayView myView(viewData,viewShape);
1823
1824 // value for tag "1"
1825 DataArray eOne(myView);
1826 for (int i=0;i<eOne.getView().getShape()[0];i++) {
1827 eOne.getView()(i)=i+1.0;
1828 }
1829 values.push_back(eOne.getView());
1830
1831 // value for tag "2"
1832 DataArray eTwo(myView);
1833 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1834 eTwo.getView()(i)=i+2.0;
1835 }
1836 values.push_back(eTwo.getView());
1837
1838 // value for tag "3"
1839 DataArray eThree(myView);
1840 for (int i=0;i<eThree.getView().getShape()[0];i++) {
1841 eThree.getView()(i)=i+3.0;
1842 }
1843 values.push_back(eThree.getView());
1844
1845 DataTagged myData(keys,values,myView,FunctionSpace());
1846
1847 DataTagged myDataCopy(myData);
1848
1849 //cout << myDataCopy.toString() << endl;
1850
1851 assert(myDataCopy.getNumSamples()==1);
1852 assert(myDataCopy.getNumDPPSample()==1);
1853
1854 assert(myDataCopy.validSamplePointNo(0));
1855 assert(myDataCopy.validSampleNo(0));
1856 assert(!myDataCopy.validSamplePointNo(1));
1857 assert(!myDataCopy.validSampleNo(1));
1858
1859 // data-point 0 has tag number 1 by default
1860 assert(myDataCopy.getTagNumber(0)==1);
1861
1862 assert(!myDataCopy.isCurrentTag(0));
1863 assert(myDataCopy.isCurrentTag(1));
1864 assert(myDataCopy.isCurrentTag(2));
1865 assert(myDataCopy.isCurrentTag(3));
1866
1867 assert(myDataCopy.getTagLookup().size()==3);
1868
1869 assert(myDataCopy.getLength()==12);
1870
1871 assert(myDataCopy.getPointOffset(0,0)==3);
1872
1873 DataArrayView myDataView = myDataCopy.getDataPoint(0,0);
1874 assert(myDataView==eOne.getView());
1875 assert(!myDataView.isEmpty());
1876 assert(myDataView.getOffset()==3);
1877 assert(myDataView.getRank()==1);
1878 assert(myDataView.noValues()==3);
1879 assert(myDataView.getShape().size()==1);
1880 assert(myDataView(0)==1);
1881 assert(myDataView(1)==2);
1882 assert(myDataView(2)==3);
1883
1884 myDataView = myDataCopy.getDataPointByTag(1);
1885 assert(myDataView==eOne.getView());
1886 assert(!myDataView.isEmpty());
1887 assert(myDataView.getOffset()==3);
1888 assert(myDataView.getRank()==1);
1889 assert(myDataView.noValues()==3);
1890 assert(myDataView.getShape().size()==1);
1891 assert(myDataView(0)==1);
1892 assert(myDataView(1)==2);
1893 assert(myDataView(2)==3);
1894
1895 // Test non-existent tag returns the default value.
1896 myDataView = myDataCopy.getDataPointByTag(0);
1897 assert(myDataView==myView);
1898 assert(!myDataView.isEmpty());
1899 assert(myDataView.getOffset()==0);
1900 assert(myDataView.getRank()==1);
1901 assert(myDataView.noValues()==3);
1902 assert(myDataView.getShape().size()==1);
1903 assert(myDataView(0)==0);
1904 assert(myDataView(1)==1);
1905 assert(myDataView(2)==2);
1906
1907 myDataView = myDataCopy.getDefaultValue();
1908 assert(myDataView==myView);
1909 assert(!myDataView.isEmpty());
1910 assert(myDataView.getOffset()==0);
1911 assert(myDataView.getRank()==1);
1912 assert(myDataView.noValues()==3);
1913 assert(myDataView.getShape().size()==1);
1914 assert(myDataView(0)==0);
1915 assert(myDataView(1)==1);
1916 assert(myDataView(2)==2);
1917
1918 // Test data-points held for remaining tags
1919 myDataView = myDataCopy.getDataPointByTag(2);
1920 assert(myDataView==eTwo.getView());
1921 assert(!myDataView.isEmpty());
1922 assert(myDataView.getOffset()==6);
1923 assert(myDataView.getRank()==1);
1924 assert(myDataView.noValues()==3);
1925 assert(myDataView.getShape().size()==1);
1926 assert(myDataView(0)==2);
1927 assert(myDataView(1)==3);
1928 assert(myDataView(2)==4);
1929
1930 myDataView = myDataCopy.getDataPointByTag(3);
1931 assert(myDataView==eThree.getView());
1932 assert(!myDataView.isEmpty());
1933 assert(myDataView.getOffset()==9);
1934 assert(myDataView.getRank()==1);
1935 assert(myDataView.noValues()==3);
1936 assert(myDataView.getShape().size()==1);
1937 assert(myDataView(0)==3);
1938 assert(myDataView(1)==4);
1939 assert(myDataView(2)==5);
1940
1941 }
1942
1943 {
1944
1945 cout << "\tTest DataTagged copy constructor for DataConstant." << endl;
1946
1947 // Create a DataConstant
1948 DataArrayView::ShapeType shape;
1949 DataArrayView::ValueType data(DataArrayView::noValues(shape),0);
1950 DataArrayView pointData(data,shape);
1951 pointData()=1.0;
1952 DataConstant myConstantData(pointData, FunctionSpace());
1953
1954 // use this DataConstant to initialise a DataTagged
1955 DataTagged myData(myConstantData);
1956
1957 //cout << myData.toString() << endl;
1958
1959 assert(myData.getNumSamples()==1);
1960 assert(myData.getNumDPPSample()==1);
1961
1962 assert(myData.validSamplePointNo(0));
1963 assert(myData.validSampleNo(0));
1964 assert(!myData.validSamplePointNo(1));
1965 assert(!myData.validSampleNo(1));
1966
1967 // data-point 0 has tag number 1 by default
1968 assert(myData.getTagNumber(0)==1);
1969
1970 assert(!myData.isCurrentTag(1));
1971
1972 assert(myData.getTagLookup().size()==0);
1973
1974 assert(myData.getLength()==1);
1975
1976 assert(myData.getPointOffset(0,0)==0);
1977
1978 DataArrayView myDataView = myData.getDataPoint(0,0);
1979 assert(!myDataView.isEmpty());
1980 assert(myDataView.getOffset()==0);
1981 assert(myDataView.getRank()==0);
1982 assert(myDataView.noValues()==1);
1983 assert(myDataView.getShape().size()==0);
1984 assert(myDataView()==1.0);
1985
1986 // Test non-existent tag returns the default value.
1987 myDataView = myData.getDataPointByTag(1);
1988 assert(!myDataView.isEmpty());
1989 assert(myDataView.getOffset()==0);
1990 assert(myDataView.getRank()==0);
1991 assert(myDataView.noValues()==1);
1992 assert(myDataView.getShape().size()==0);
1993 assert(myDataView()==1.0);
1994
1995 myDataView = myData.getDefaultValue();
1996 assert(!myDataView.isEmpty());
1997 assert(myDataView.getOffset()==0);
1998 assert(myDataView.getRank()==0);
1999 assert(myDataView.noValues()==1);
2000 assert(myDataView.getShape().size()==0);
2001 assert(myDataView()==1.0);
2002
2003 }
2004
2005 }
2006
2007 TestSuite* DataTaggedTestCase::suite ()
2008 {
2009 //
2010 // create the suite of tests to perform.
2011 TestSuite *testSuite = new TestSuite ("DataTaggedTestCase");
2012 testSuite->addTest (new TestCaller< DataTaggedTestCase>("testAll",&DataTaggedTestCase::testAll));
2013 testSuite->addTest (new TestCaller< DataTaggedTestCase>("testAddTaggedValues",&DataTaggedTestCase::testAddTaggedValues));
2014 testSuite->addTest (new TestCaller< DataTaggedTestCase>("testSetTaggedValue",&DataTaggedTestCase::testSetTaggedValue));
2015 testSuite->addTest (new TestCaller< DataTaggedTestCase>("testCopyConstructors",&DataTaggedTestCase::testCopyConstructors));
2016 testSuite->addTest (new TestCaller< DataTaggedTestCase>("testOperations",&DataTaggedTestCase::testOperations));
2017 // testSuite->addTest (new TestCaller< DataTaggedTestCase>("testReshape",&DataTaggedTestCase::testReshape));
2018 return testSuite;
2019 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26