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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 549 - (show annotations)
Wed Feb 22 00:45:48 2006 UTC (13 years, 7 months ago) by jgs
Original Path: trunk/escript/test/Data/DataTestCase.cpp
File size: 25830 byte(s)
extend testing of DataTagged setSlice to include case where
source and target have mismatched tag sets

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 "DataTestCase.h"
17
18 #include "FunctionSpace.h"
19 #include "EsysException.h"
20
21 #include "Data.h"
22
23 #include <iostream>
24 #include <math.h>
25
26 using namespace std;
27 using namespace CppUnitTest;
28 using namespace escript;
29 using namespace esysUtils;
30
31 void DataTestCase::setUp() {
32 //
33 // This is called before each test is run
34 }
35
36 void DataTestCase::tearDown() {
37 //
38 // This is called after each test has been run
39 }
40
41 void DataTestCase::testSlicing() {
42
43 cout << endl;
44
45 {
46
47 cout << "\tTest get-slicing DataConstant" << endl;
48
49 DataArrayView::ShapeType viewShape;
50 viewShape.push_back(2);
51 viewShape.push_back(3);
52 Data data(1.3,viewShape,FunctionSpace(),false);
53
54 //cout << data.toString() << endl;
55
56 DataArrayView::RegionType region;
57 region.push_back(DataArrayView::RegionType::value_type(0,0));
58 region.push_back(DataArrayView::RegionType::value_type(0,0));
59
60 Data slice1(data.getSlice(region));
61
62 //cout << slice1.toString() << endl;
63
64 assert(slice1.getDataPointRank()==0);
65 assert(slice1.getDataPoint(0,0)()==1.3);
66
67 region.clear();
68 region.push_back(DataArrayView::RegionType::value_type(0,1));
69 region.push_back(DataArrayView::RegionType::value_type(0,1));
70
71 Data slice2(data.getSlice(region));
72
73 //cout << slice2.toString() << endl;
74
75 assert(slice2.getDataPointRank()==2);
76 assert(slice2.getDataPoint(0,0)(0,0)==1.3);
77
78 region.clear();
79 region.push_back(DataArrayView::RegionType::value_type(0,1));
80 region.push_back(DataArrayView::RegionType::value_type(0,2));
81
82 Data slice3(data.getSlice(region));
83
84 //cout << slice3.toString() << endl;
85
86 assert(slice3.getDataPointRank()==2);
87 assert(slice3.getDataPoint(0,0)(0,0)==1.3);
88 assert(slice3.getDataPoint(0,0)(0,1)==1.3);
89
90 }
91
92 {
93
94 cout << "\tTest set-slicing DataConstant" << endl;
95
96 DataArrayView::ShapeType viewShape;
97 Data source(10.0,viewShape,FunctionSpace(),false);
98
99 //cout << source.toString() << endl;
100
101 viewShape.push_back(2);
102 viewShape.push_back(3);
103 Data target(1.3,viewShape,FunctionSpace(),false);
104
105 //cout << target.toString() << endl;
106
107 DataArrayView::RegionType region;
108 region.push_back(DataArrayView::RegionType::value_type(0,0));
109 region.push_back(DataArrayView::RegionType::value_type(0,0));
110
111 target.setSlice(source,region);
112
113 //cout << target.toString() << endl;
114
115 assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)());
116
117 }
118
119 {
120
121 cout << "\tTest get-slicing DataTagged" << endl;
122
123 //
124 // create a DataTagged with a default value only
125
126 DataArrayView::ShapeType viewShape;
127 viewShape.push_back(2);
128 viewShape.push_back(3);
129 Data data(1.3,viewShape,FunctionSpace(),false);
130 data.tag();
131 data.getDataPoint(0,0)(0,0)=1.0;
132 data.getDataPoint(0,0)(1,1)=2.0;
133
134 //cout << data.toString() << endl;
135
136 //
137 // create a scalar slice
138
139 DataArrayView::RegionType region;
140 region.push_back(DataArrayView::RegionType::value_type(0,0));
141 region.push_back(DataArrayView::RegionType::value_type(0,0));
142
143 Data slice1(data.getSlice(region));
144
145 //cout << slice1.toString() << endl;
146
147 assert(slice1.isTagged());
148 assert(slice1.getDataPointRank()==0);
149 assert(slice1.getDataPoint(0,0)()==1.0);
150
151 //
152 // create a rank 2 slice with one value
153
154 region.clear();
155 region.push_back(DataArrayView::RegionType::value_type(0,1));
156 region.push_back(DataArrayView::RegionType::value_type(0,1));
157
158 Data slice2(data.getSlice(region));
159
160 //cout << slice2.toString() << endl;
161
162 assert(slice2.isTagged());
163 assert(slice2.getDataPointRank()==2);
164 assert(slice2.getDataPoint(0,0)(0,0)==1.0);
165
166 //
167 // create a rank 2 slice with four values
168
169 region.clear();
170 region.push_back(DataArrayView::RegionType::value_type(0,2));
171 region.push_back(DataArrayView::RegionType::value_type(0,2));
172
173 Data slice3(data.getSlice(region));
174
175 //cout << slice3.toString() << endl;
176
177 assert(slice3.isTagged());
178 assert(slice3.getDataPointRank()==2);
179 assert(slice3.getDataPoint(0,0)(0,0)==1.0);
180 assert(slice3.getDataPoint(0,0)(0,1)==1.3);
181 assert(slice3.getDataPoint(0,0)(1,0)==1.3);
182 assert(slice3.getDataPoint(0,0)(1,1)==2.0);
183
184 //
185 // add a value for tag "1"
186
187 DataArrayView::ValueType viewData(6);
188 for (int i=0;i<viewData.size();i++) {
189 viewData[i]=i;
190 }
191 DataArrayView dataView(viewData,viewShape);
192
193 data.setTaggedValueFromCPP(1, dataView);
194
195 //
196 // create a full slice
197
198 region.clear();
199 region.push_back(DataArrayView::RegionType::value_type(0,2));
200 region.push_back(DataArrayView::RegionType::value_type(0,3));
201
202 Data slice4(data.getSlice(region));
203
204 //cout << slice4.toString() << endl;
205
206 assert(slice4.isTagged());
207 assert(slice4.getDataPointRank()==2);
208 assert(slice4.getDataPoint(0,0)(0,0)==0);
209 assert(slice4.getDataPoint(0,0)(0,1)==2);
210 assert(slice4.getDataPoint(0,0)(0,2)==4);
211 assert(slice4.getDataPoint(0,0)(1,0)==1);
212 assert(slice4.getDataPoint(0,0)(1,1)==3);
213 assert(slice4.getDataPoint(0,0)(1,2)==5);
214
215 }
216
217 {
218
219 cout << "\tTest set-slicing DataTagged" << endl;
220
221 //
222 // create a source DataTagged with a scalar default value only
223
224 DataArrayView::ShapeType viewShape;
225 Data source(10.0,viewShape,FunctionSpace(),false);
226 source.tag();
227
228 //cout << "source:\n" << source.toString() << endl;
229
230 //
231 // create a target DataTagged with a rank 2 default value only
232
233 viewShape.push_back(2);
234 viewShape.push_back(3);
235 Data target(1.3,viewShape,FunctionSpace(),false);
236 target.tag();
237
238 //cout << "target:\n" << target.toString() << endl;
239
240 //
241 // set a slice in target from source
242
243 DataArrayView::RegionType region;
244 region.push_back(DataArrayView::RegionType::value_type(1,1));
245 region.push_back(DataArrayView::RegionType::value_type(1,1));
246
247 target.setSlice(source,region);
248
249 //cout << "target:\n" << target.toString() << endl;
250
251 assert(target.isTagged());
252 assert(target.getDataPointRank()==2);
253 assert(target.getDataPoint(0,0)(0,0)==1.3);
254 assert(target.getDataPoint(0,0)(0,1)==1.3);
255 assert(target.getDataPoint(0,0)(0,2)==1.3);
256 assert(target.getDataPoint(0,0)(1,0)==1.3);
257 assert(target.getDataPoint(0,0)(1,1)==source.getDataPoint(0,0)());
258 assert(target.getDataPoint(0,0)(1,2)==1.3);
259
260 //
261 // add a value for tag "1" to target
262
263 DataArrayView::ValueType viewData(6);
264 for (int i=0;i<viewData.size();i++) {
265 viewData[i]=i;
266 }
267 DataArrayView dataView(viewData,viewShape);
268
269 target.setTaggedValueFromCPP(1, dataView);
270
271 //cout << "target:\n" << target.toString() << endl;
272
273 //
274 // set a slice in target from source
275
276 region.clear();
277 region.push_back(DataArrayView::RegionType::value_type(0,0));
278 region.push_back(DataArrayView::RegionType::value_type(1,1));
279
280 target.setSlice(source,region);
281
282 //cout << "target:\n" << target.toString() << endl;
283
284 assert(target.isTagged());
285 assert(target.getDataPointRank()==2);
286 assert(target.getDataPoint(0,0)(0,0)==0);
287 assert(target.getDataPoint(0,0)(0,1)==source.getDataPoint(0,0)());
288 assert(target.getDataPoint(0,0)(0,2)==4);
289 assert(target.getDataPoint(0,0)(1,0)==1);
290 assert(target.getDataPoint(0,0)(1,1)==3);
291 assert(target.getDataPoint(0,0)(1,2)==5);
292
293 //
294 // add a value for tag "2" to source
295
296 DataArrayView::ShapeType viewShape2;
297 DataArrayView::ValueType viewData2(1);
298 viewData2[0]=6;
299 DataArrayView dataView2(viewData2,viewShape2);
300
301 source.setTaggedValueFromCPP(2, dataView2);
302
303 //cout << "source:\n" << source.toString() << endl;
304
305 //
306 // set a slice in target from source
307
308 region.clear();
309 region.push_back(DataArrayView::RegionType::value_type(0,0));
310 region.push_back(DataArrayView::RegionType::value_type(1,1));
311
312 target.setSlice(source,region);
313
314 //cout << "target:\n" << target.toString() << endl;
315
316 assert(target.isTagged());
317 assert(target.getDataPointRank()==2);
318
319 // use a non-existant tag so we get a pointer to the default value
320 // ie: the first element in the data array
321 DataAbstract::ValueType::value_type* targetData=target.getSampleDataByTag(9);
322 for (int i=0; i<target.getLength(); i++) {
323 assert(targetData[i]>=0);
324 }
325 assert(targetData[0]==1.3);
326 assert(targetData[1]==1.3);
327 assert(targetData[2]==10);
328 assert(targetData[3]==10);
329 assert(targetData[4]==1.3);
330 assert(targetData[5]==1.3);
331 assert(targetData[6]==0);
332 assert(targetData[7]==1);
333 assert(targetData[8]==10);
334 assert(targetData[9]==3);
335 assert(targetData[10]==4);
336 assert(targetData[11]==5);
337 assert(targetData[12]==1.3);
338 assert(targetData[13]==1.3);
339 assert(targetData[14]==6);
340 assert(targetData[15]==10);
341 assert(targetData[16]==1.3);
342 assert(targetData[17]==1.3);
343
344 }
345
346 {
347
348 cout << "\tTest get-slicing DataExpanded" << endl;
349
350 DataArrayView::ShapeType viewShape;
351 viewShape.push_back(2);
352 viewShape.push_back(3);
353 Data temp(1.3,viewShape,FunctionSpace(),true);
354
355 temp.getDataPoint(0,0)(0,0)=0.0;
356 temp.getDataPoint(0,0)(1,1)=1.0;
357
358 DataArrayView::RegionType region;
359 region.push_back(DataArrayView::RegionType::value_type(0,0));
360 region.push_back(DataArrayView::RegionType::value_type(0,0));
361
362 Data slice(temp.getSlice(region));
363
364 assert(slice.getDataPointRank()==0);
365 assert(slice.getDataPoint(0,0)()==0.0);
366
367 region.clear();
368 region.push_back(DataArrayView::RegionType::value_type(0,1));
369 region.push_back(DataArrayView::RegionType::value_type(0,1));
370
371 slice=temp.getSlice(region);
372
373 assert(slice.getDataPointRank()==2);
374 assert(slice.getDataPoint(0,0)(0,0)==0.0);
375
376 region.clear();
377 region.push_back(DataArrayView::RegionType::value_type(0,2));
378 region.push_back(DataArrayView::RegionType::value_type(0,2));
379
380 slice=temp.getSlice(region);
381
382 assert(slice.getDataPoint(0,0)(0,0)==0.0);
383 assert(slice.getDataPoint(0,0)(1,1)==1.0);
384
385 }
386
387 {
388
389 cout << "\tTest set-slicing DataExpanded" << endl;
390
391 DataArrayView::ShapeType viewShape;
392 Data source(10.0,viewShape,FunctionSpace(),true);
393
394 viewShape.push_back(2);
395 viewShape.push_back(3);
396 Data target(1.3,viewShape,FunctionSpace(),true);
397
398 DataArrayView::RegionType region;
399 region.push_back(DataArrayView::RegionType::value_type(0,0));
400 region.push_back(DataArrayView::RegionType::value_type(0,0));
401
402 target.setSlice(source,region);
403
404 assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)());
405
406 }
407
408 }
409
410 void DataTestCase::testAll() {
411
412 cout << endl;
413
414 cout << "\tCreate a Data object from a DataArrayView" << endl;
415
416 DataArrayView::ShapeType viewShape;
417 viewShape.push_back(3);
418 DataArrayView::ValueType viewData(3);
419 for (int i=0;i<viewShape[0];++i) {
420 viewData[i]=i;
421 }
422 DataArrayView myView(viewData,viewShape);
423
424 bool expanded=true;
425 Data exData(myView,FunctionSpace(),expanded);
426 Data cData(myView);
427 Data result;
428
429 assert(exData.isExpanded());
430 assert(cData.isConstant());
431 assert(result.isEmpty());
432
433 cout << "\tTest some basic operations" << endl;
434 result=exData*cData;
435 assert(result.isExpanded());
436
437 }
438
439 void DataTestCase::testMore() {
440
441 cout << endl;
442
443 cout << "\tCreate a Data object from a DataArrayView" << endl;
444
445 DataArrayView::ShapeType viewShape;
446 viewShape.push_back(3);
447 DataArrayView::ValueType viewData(3);
448 for (int i=0;i<viewShape[0];++i) {
449 viewData[i]=i;
450 }
451 DataArrayView myView(viewData,viewShape);
452
453 bool expanded=true;
454 Data exData(myView,FunctionSpace(),expanded);
455 Data cData(myView);
456 Data result;
457
458 assert(exData.isExpanded());
459 assert(cData.isConstant());
460 assert(result.isEmpty());
461
462 cout << "\tTest some basic operations" << endl;
463 result=exData*cData;
464 assert(result.isExpanded());
465
466 assert(result.Lsup()==4);
467 assert(result.sup()==4);
468 assert(result.inf()==0);
469
470 result=exData+cData;
471 result=exData-cData;
472 result=exData/cData;
473
474 cout << "\tExercise wherePositive method" << endl;
475 assert(!exData.wherePositive().isEmpty());
476
477 cout << "\tExercise copyWithMask method" << endl;
478 exData.copyWithMask(result, exData.wherePositive());
479 assert(!exData.wherePositive().isEmpty());
480
481 }
482
483 void DataTestCase::testDataConstant() {
484
485 cout << endl;
486
487 cout << "\tCreate a DataConstant object from a DataArrayView" << endl;
488
489 DataArrayView::ShapeType viewShape;
490 viewShape.push_back(2);
491 viewShape.push_back(3);
492 viewShape.push_back(4);
493 DataArrayView::ValueType viewData(2*3*4);
494 for (int i=0;i<DataArrayView::noValues(viewShape);++i) {
495 viewData[i]=i;
496 }
497 DataArrayView myView(viewData,viewShape);
498
499 Data left(myView);
500 Data right(myView);
501 Data result;
502
503 cout << "\tTest some basic operations" << endl;
504
505 result=left-right;
506
507 assert(left.isConstant());
508 assert(right.isConstant());
509 assert(result.isConstant());
510
511 result=left+right;
512
513 assert(left.isConstant());
514 assert(right.isConstant());
515 assert(result.isConstant());
516
517 assert(!result.isExpanded());
518 assert(!result.isTagged());
519
520 }
521
522 void DataTestCase::testDataTagged() {
523
524 cout << endl;
525
526 {
527
528 cout << "\tCreate a DataTagged object with a default value only." << endl;
529
530 DataTagged::TagListType keys;
531
532 DataTagged::ValueListType values;
533
534 DataArrayView::ShapeType viewShape;
535 viewShape.push_back(3);
536
537 DataArrayView::ValueType viewData(3);
538 for (int i=0;i<viewShape[0];i++) {
539 viewData[i]=i;
540 }
541 DataArrayView defaultValue(viewData,viewShape);
542
543 bool expanded=false;
544
545 Data myData(keys,values,defaultValue,FunctionSpace(),expanded);
546
547 // cout << myData.toString() << endl;
548
549 assert(!myData.isEmpty());
550 assert(myData.isTagged());
551 assert(myData.getTagNumber(0)==1);
552 assert(myData.getDataPointRank()==1);
553 assert(myData.getLength()==3);
554
555 DataArrayView myDataView = myData.getPointDataView();
556 assert(!myDataView.isEmpty());
557 assert(myDataView.getOffset()==0);
558 assert(myDataView.getRank()==1);
559 assert(myDataView.noValues()==3);
560 assert(myDataView.getShape().size()==1);
561 assert(myDataView(0)==0.0);
562 assert(myDataView(1)==1.0);
563 assert(myDataView(2)==2.0);
564
565 myDataView = myData.getDataPoint(0,0);
566 assert(!myDataView.isEmpty());
567 assert(myDataView.getOffset()==0);
568 assert(myDataView.getRank()==1);
569 assert(myDataView.noValues()==3);
570 assert(myDataView.getShape().size()==1);
571 assert(myDataView(0)==0.0);
572 assert(myDataView(1)==1.0);
573 assert(myDataView(2)==2.0);
574
575 double* sampleData=myData.getSampleData(0);
576 for (int i=0; i<myDataView.noValues(); i++) {
577 assert(sampleData[i]==i);
578 }
579 // use a non-existent tag so we get a pointer to
580 // the first element of the data array
581 sampleData=myData.getSampleDataByTag(9);
582 for (int i=0; i<myData.getLength(); i++) {
583 assert(sampleData[i]==i);
584 }
585
586 cout << "\tTest setting of a tag and associated value." << endl;
587
588 // value for tag "1"
589 DataArray eTwo(defaultValue);
590 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
591 eTwo.getView()(i)=i+2.0;
592 }
593
594 myData.setTaggedValueFromCPP(1,eTwo.getView());
595
596 assert(myData.getLength()==6);
597
598 myDataView = myData.getDataPoint(0,0);
599 assert(myDataView==eTwo.getView());
600 assert(!myDataView.isEmpty());
601 assert(myDataView.getOffset()==3);
602 assert(myDataView.getRank()==1);
603 assert(myDataView.noValues()==3);
604 assert(myDataView.getShape().size()==1);
605 assert(myDataView(0)==2);
606 assert(myDataView(1)==3);
607 assert(myDataView(2)==4);
608
609 sampleData=myData.getSampleDataByTag(1);
610 for (int i=0; i<myDataView.noValues(); i++) {
611 assert(sampleData[i]==i+2);
612 }
613
614 }
615
616 {
617
618 cout << "\tCreate a DataTagged object via tag() method." << endl;
619
620 DataArrayView::ShapeType viewShape;
621 viewShape.push_back(2);
622 viewShape.push_back(3);
623 Data myData(1.3,viewShape,FunctionSpace(),false);
624 myData.tag();
625
626 //cout << myData.toString() << endl;
627
628 assert(!myData.isEmpty());
629 assert(myData.isTagged());
630 assert(myData.getTagNumber(0)==1);
631 assert(myData.getDataPointRank()==2);
632 assert(myData.getLength()==6);
633
634 // check default value
635 DataArrayView myDataView = myData.getPointDataView();
636 assert(!myDataView.isEmpty());
637 assert(myDataView.getOffset()==0);
638 assert(myDataView.getRank()==2);
639 assert(myDataView.noValues()==6);
640 assert(myDataView.getShape().size()==2);
641 assert(myDataView(0,0)==1.3);
642 assert(myDataView(0,1)==1.3);
643 assert(myDataView(0,2)==1.3);
644 assert(myDataView(1,0)==1.3);
645 assert(myDataView(1,1)==1.3);
646 assert(myDataView(1,2)==1.3);
647
648 // check value for data-point (0,0).
649 myDataView = myData.getDataPoint(0,0);
650 assert(!myDataView.isEmpty());
651 assert(myDataView.getOffset()==0);
652 assert(myDataView.getRank()==2);
653 assert(myDataView.noValues()==6);
654 assert(myDataView.getShape().size()==2);
655 assert(myDataView(0,0)==1.3);
656 assert(myDataView(0,1)==1.3);
657 assert(myDataView(0,2)==1.3);
658 assert(myDataView(1,0)==1.3);
659 assert(myDataView(1,1)==1.3);
660 assert(myDataView(1,2)==1.3);
661
662 }
663
664 }
665
666 void DataTestCase::testDataTaggedExceptions() {
667
668 cout << endl;
669
670 cout << "\tTest DataTagged exceptions." << endl;
671
672 Data myData;
673 DataArrayView myView;
674
675 try {
676 myData.getSampleDataByTag(0);;
677 assert(false);
678 }
679 catch (EsysException& e) {
680 //cout << e.what() << endl;
681 assert(true);
682 }
683
684 try {
685 myData.setTaggedValueFromCPP(0,myView);;
686 assert(false);
687 }
688 catch (EsysException& e) {
689 //cout << e.what() << endl;
690 assert(true);
691 }
692
693 }
694
695 void DataTestCase::testConstructors() {
696
697 cout << endl;
698
699 DataArrayView::ShapeType viewShape;
700 {
701 cout << "\tCreate an Empty Data object" << endl;
702 Data temp(1.3,viewShape,FunctionSpace(),false);
703 }
704 {
705 cout << "\tCreate a rank 2 Data object" << endl;
706 viewShape.push_back(2);
707 viewShape.push_back(3);
708 Data temp(1.3,viewShape,FunctionSpace(),false);
709 }
710 }
711
712 void DataTestCase::testOperations() {
713
714 cout << endl;
715
716 // define the shape for the DataArrayView test data
717 DataArrayView::ShapeType shape;
718 shape.push_back(2);
719 shape.push_back(3);
720
721 // allocate the data for the DataArrayView
722 DataArrayView::ValueType data(DataArrayView::noValues(shape),0);
723
724 // construct DataArrayView
725 DataArrayView dataView(data,shape);
726
727 // assign values to the data
728 for (int i=0;i<shape[0];i++) {
729 for (int j=0;j<shape[1];j++) {
730 dataView(i,j)=dataView.index(i,j);
731 }
732 }
733
734 Data base(dataView);
735
736 // test unary operations
737
738 cout << "\tTest Data::pow." << endl;
739 Data power(3.0,shape,FunctionSpace(),true);
740 Data result(base.powD(power));
741 for (int i=0;i<shape[0];i++) {
742 for (int j=0;j<shape[1];j++) {
743 assert(result.getPointDataView()(i,j) == pow(dataView.index(i,j),3.0));
744 }
745 }
746
747 cout << "\tTest Data::sin." << endl;
748 result.copy(base.sin());
749 assert(true);
750
751 cout << "\tTest Data::cos." << endl;
752 result.copy(base.cos());
753 assert(true);
754
755 cout << "\tTest Data::tan." << endl;
756 result.copy(base.tan());
757 assert(true);
758
759 cout << "\tTest Data::asin." << endl;
760 result.copy(base.asin());
761 assert(true);
762
763 cout << "\tTest Data::acos." << endl;
764 result.copy(base.acos());
765 assert(true);
766
767 cout << "\tTest Data::atan." << endl;
768 result.copy(base.atan());
769 assert(true);
770
771 cout << "\tTest Data::sinh." << endl;
772 result.copy(base.sinh());
773 assert(true);
774
775 cout << "\tTest Data::cosh." << endl;
776 result.copy(base.cosh());
777 assert(true);
778
779 cout << "\tTest Data::tanh." << endl;
780 result.copy(base.tanh());
781 assert(true);
782
783 cout << "\tTest Data::asinh." << endl;
784 result.copy(base.asinh());
785 assert(true);
786
787 cout << "\tTest Data::acosh." << endl;
788 result.copy(base.acosh());
789 assert(true);
790
791 cout << "\tTest Data::atanh." << endl;
792 result.copy(base.atanh());
793 assert(true);
794
795 cout << "\tTest Data::log." << endl;
796 result.copy(base.log());
797 assert(true);
798
799 //cout << "\tTest Data::ln." << endl;
800 //result.copy(base.ln());
801 //assert(true);
802
803 cout << "\tTest Data::abs." << endl;
804 result.copy(base.abs());
805 assert(true);
806
807 cout << "\tTest Data::sign." << endl;
808 result.copy(base.sign());
809 assert(true);
810
811 cout << "\tTest Data::exp." << endl;
812 result.copy(base.exp());
813 assert(true);
814
815 cout << "\tTest Data::sqrt." << endl;
816 result.copy(base.sqrt());
817 assert(true);
818
819 cout << "\tTest Data::neg." << endl;
820 result.copy(base.neg());
821 assert(true);
822
823 cout << "\tTest Data::pos." << endl;
824 result.copy(base.pos());
825 for (int i=0;i<shape[0];i++) {
826 for (int j=0;j<shape[1];j++) {
827 assert(result.getPointDataView()(i,j) == dataView.index(i,j));
828 }
829 }
830
831 // test reduction operations
832
833 cout << "\tTest Data::Lsup." << endl;
834 assert(base.Lsup() == 5);
835
836 cout << "\tTest Data::sup." << endl;
837 assert(base.sup() == 5);
838
839 cout << "\tTest Data::inf." << endl;
840 assert(base.inf() == 0);
841
842 // test data-point reduction operations
843
844 cout << "\tTest Data::minval." << endl;
845 result.copy(base.minval());
846 assert(result.getPointDataView()() == 0);
847
848 cout << "\tTest Data::maxval." << endl;
849 result.copy(base.maxval());
850 assert(result.getPointDataView()() == 5);
851
852 //cout << "\tTest Data::length." << endl;
853 //result.copy(base.length());
854 //assert(pow(result.getPointDataView()(),2.0) == 55);
855
856 cout << "\tTest Data::trace." << endl;
857 result.copy(base.trace());
858 assert(result.getPointDataView()() == 15);
859
860 //result.copy(base.transpose(0));
861 //assert(true);
862
863 }
864
865 void DataTestCase::testRefValue() {
866
867 //
868 // Note - this test can't be run as boost::python::numeric::array
869 // objects can only be created and used from within a python thread!
870 //
871
872 cout << endl;
873
874 cout << "\tTest Data object RefValue methods." << endl;
875
876 // Create three Data object - DataExpanded, DataConstant and DataEmpty
877 DataArrayView::ShapeType viewShape;
878 viewShape.push_back(3);
879 DataArrayView::ValueType viewData(3);
880 for (int i=0;i<viewShape[0];++i) {
881 viewData[i]=i;
882 }
883 DataArrayView myView(viewData,viewShape);
884
885 bool expanded=true;
886
887 Data expandedData(myView,FunctionSpace(),expanded);
888 Data constantData(myView);
889 Data emptyData;
890
891 assert(expandedData.isExpanded());
892 assert(constantData.isConstant());
893 assert(emptyData.isEmpty());
894
895 // Check assertions are thrown for RefValue methods on DataEmpty
896
897 int ref = 0;
898 boost::python::numeric::array num_array(1.0);
899
900 try {
901 emptyData.getRefValue(ref,num_array);
902 assert(false);
903 }
904 catch (EsysException& e) {
905 assert(true);
906 }
907 try {
908 emptyData.setRefValue(ref,num_array);
909 assert(false);
910 }
911 catch (EsysException& e) {
912 assert(true);
913 }
914
915 // Check assertions are thrown for RefValue methods on DataConstant
916 try {
917 constantData.getRefValue(ref,num_array);
918 assert(false);
919 }
920 catch (EsysException& e) {
921 assert(true);
922 }
923 try {
924 constantData.setRefValue(ref,num_array);
925 assert(false);
926 }
927 catch (EsysException& e) {
928 assert(true);
929 }
930
931 // Check calls to RefValue methods on DataExpanded
932 expandedData.getRefValue(ref,num_array);
933 expandedData.setRefValue(ref,num_array);
934
935 }
936
937 void DataTestCase::testMemAlloc() {
938
939 //
940 // Simple little sanity check for the memory allocator
941
942 cout << endl;
943
944 Data *testData;
945 for (int i=0; i<1000; i++) {
946 testData = new Data(0.0, DataArrayView::ShapeType(), FunctionSpace(), true);
947 delete testData;
948 }
949
950 DataArrayView::ShapeType viewShape;
951 viewShape.push_back(10);
952 viewShape.push_back(10);
953 viewShape.push_back(10);
954
955 Data *testData2;
956 Data *testData3 = new Data(0.0, viewShape, FunctionSpace(), true);
957 for (int i=0; i<1000; i++) {
958 testData2 = new Data(0.0, viewShape, FunctionSpace(), true);
959 delete testData2;
960 }
961 delete testData3;
962
963 }
964
965 TestSuite* DataTestCase::suite ()
966 {
967 //
968 // create the suite of tests to perform.
969 TestSuite *testSuite = new TestSuite ("DataTestCase");
970
971 testSuite->addTest (new TestCaller< DataTestCase>("testAll",&DataTestCase::testAll));
972 testSuite->addTest (new TestCaller< DataTestCase>("testMore",&DataTestCase::testMore));
973 testSuite->addTest (new TestCaller< DataTestCase>("testDataConstant",&DataTestCase::testDataConstant));
974 testSuite->addTest (new TestCaller< DataTestCase>("testDataTagged",&DataTestCase::testDataTagged));
975 testSuite->addTest (new TestCaller< DataTestCase>("testDataTaggedExceptions",&DataTestCase::testDataTaggedExceptions));
976 testSuite->addTest (new TestCaller< DataTestCase>("testConstructors",&DataTestCase::testConstructors));
977 testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));
978 testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));
979 //testSuite->addTest (new TestCaller< DataTestCase>("testRefValue",&DataTestCase::testRefValue));
980 testSuite->addTest (new TestCaller< DataTestCase>("testMemAlloc",&DataTestCase::testMemAlloc));
981
982 return testSuite;
983 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26