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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 682 - (show annotations)
Mon Mar 27 02:43:09 2006 UTC (13 years, 6 months ago) by robwdcock
File size: 28319 byte(s)
+ NEW BUILD SYSTEM

This commit contains the new build system with cross-platform support.
Most things work are before though you can have more control.

ENVIRONMENT settings have changed:
+ You no longer require LD_LIBRARY_PATH or PYTHONPATH to point to the
esysroot for building and testing performed via scons
+ ACcESS altix users: It is recommended you change your modules to load
the latest intel compiler and other libraries required by boost to match
the setup in svn (you can override). The correct modules are as follows

module load intel_cc.9.0.026
export
MODULEPATH=${MODULEPATH}:/data/raid2/toolspp4/modulefiles/gcc-3.3.6
module load boost/1.33.0/python-2.4.1
module load python/2.4.1
module load numarray/1.3.3


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 "escript/FunctionSpace.h"
19 #include "esysUtils/EsysException.h"
20
21 #include "escript/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 baseEx(dataView,FunctionSpace(),true);
735 Data baseCon(dataView,FunctionSpace(),false);
736 Data baseTag(dataView,FunctionSpace(),false);
737 baseTag.tag();
738
739 assert(baseEx.isExpanded());
740 assert(baseCon.isConstant());
741 assert(baseTag.isTagged());
742
743 Data resultEx;
744 Data resultCon;
745 Data resultTag;
746
747 // test unary operations
748
749 cout << "\tTest Data::pow." << endl;
750 Data power(3.0,shape,FunctionSpace(),true);
751 resultEx.copy(baseEx.powD(power));
752 resultCon.copy(baseCon.powD(power));
753 resultTag.copy(baseTag.powD(power));
754 for (int i=0;i<shape[0];i++) {
755 for (int j=0;j<shape[1];j++) {
756 assert(resultEx.getPointDataView()(i,j) == pow(dataView.index(i,j),3.0));
757 assert(resultCon.getPointDataView()(i,j) == pow(dataView.index(i,j),3.0));
758 assert(resultTag.getPointDataView()(i,j) == pow(dataView.index(i,j),3.0));
759 }
760 }
761
762 cout << "\tTest Data::sin." << endl;
763 resultEx.copy(baseEx.sin());
764 resultCon.copy(baseCon.sin());
765 resultTag.copy(baseTag.sin());
766 assert(true);
767
768 cout << "\tTest Data::cos." << endl;
769 resultEx.copy(baseEx.cos());
770 resultCon.copy(baseCon.cos());
771 resultTag.copy(baseTag.cos());
772 assert(true);
773
774 cout << "\tTest Data::tan." << endl;
775 resultEx.copy(baseEx.tan());
776 resultCon.copy(baseCon.tan());
777 resultTag.copy(baseTag.tan());
778 assert(true);
779
780 cout << "\tTest Data::asin." << endl;
781 resultEx.copy(baseEx.asin());
782 resultCon.copy(baseCon.asin());
783 resultTag.copy(baseTag.asin());
784 assert(true);
785
786 cout << "\tTest Data::acos." << endl;
787 resultEx.copy(baseEx.acos());
788 resultCon.copy(baseCon.acos());
789 resultTag.copy(baseTag.acos());
790 assert(true);
791
792 cout << "\tTest Data::atan." << endl;
793 resultEx.copy(baseEx.atan());
794 resultCon.copy(baseCon.atan());
795 resultTag.copy(baseTag.atan());
796 assert(true);
797
798 cout << "\tTest Data::sinh." << endl;
799 resultEx.copy(baseEx.sinh());
800 resultCon.copy(baseCon.sinh());
801 resultTag.copy(baseTag.sinh());
802 assert(true);
803
804 cout << "\tTest Data::cosh." << endl;
805 resultEx.copy(baseEx.cosh());
806 resultCon.copy(baseCon.cosh());
807 resultTag.copy(baseTag.cosh());
808 assert(true);
809
810 cout << "\tTest Data::tanh." << endl;
811 resultEx.copy(baseEx.tanh());
812 resultCon.copy(baseCon.tanh());
813 resultTag.copy(baseTag.tanh());
814 assert(true);
815
816 cout << "\tTest Data::asinh." << endl;
817 resultEx.copy(baseEx.asinh());
818 resultCon.copy(baseCon.asinh());
819 resultTag.copy(baseTag.asinh());
820 assert(true);
821
822 cout << "\tTest Data::acosh." << endl;
823 resultEx.copy(baseEx.acosh());
824 resultCon.copy(baseCon.acosh());
825 resultTag.copy(baseTag.acosh());
826 assert(true);
827
828 cout << "\tTest Data::atanh." << endl;
829 resultEx.copy(baseEx.atanh());
830 resultCon.copy(baseCon.atanh());
831 resultTag.copy(baseTag.atanh());
832 assert(true);
833
834 cout << "\tTest Data::log." << endl;
835 resultEx.copy(baseEx.log());
836 resultCon.copy(baseCon.log());
837 resultTag.copy(baseTag.log());
838 assert(true);
839
840 cout << "\tTest Data::abs." << endl;
841 resultEx.copy(baseEx.abs());
842 resultCon.copy(baseCon.abs());
843 resultTag.copy(baseTag.abs());
844 assert(true);
845
846 cout << "\tTest Data::sign." << endl;
847 resultEx.copy(baseEx.sign());
848 resultCon.copy(baseCon.sign());
849 resultTag.copy(baseTag.sign());
850 assert(true);
851
852 cout << "\tTest Data::exp." << endl;
853 resultEx.copy(baseEx.exp());
854 resultCon.copy(baseCon.exp());
855 resultTag.copy(baseTag.exp());
856 assert(true);
857
858 cout << "\tTest Data::sqrt." << endl;
859 resultEx.copy(baseEx.sqrt());
860 resultCon.copy(baseCon.sqrt());
861 resultTag.copy(baseTag.sqrt());
862 assert(true);
863
864 cout << "\tTest Data::neg." << endl;
865 resultEx.copy(baseEx.neg());
866 resultCon.copy(baseCon.neg());
867 resultTag.copy(baseTag.neg());
868 assert(true);
869
870 cout << "\tTest Data::pos." << endl;
871 resultEx.copy(baseEx.pos());
872 resultCon.copy(baseCon.pos());
873 resultTag.copy(baseTag.pos());
874 for (int i=0;i<shape[0];i++) {
875 for (int j=0;j<shape[1];j++) {
876 assert(resultEx.getPointDataView()(i,j) == dataView.index(i,j));
877 assert(resultCon.getPointDataView()(i,j) == dataView.index(i,j));
878 assert(resultTag.getPointDataView()(i,j) == dataView.index(i,j));
879 }
880 }
881
882 // test reduction operations
883
884 cout << "\tTest Data::Lsup." << endl;
885 assert(baseEx.Lsup() == 5);
886 assert(baseCon.Lsup() == 5);
887 assert(baseTag.Lsup() == 5);
888
889 cout << "\tTest Data::sup." << endl;
890 assert(baseEx.sup() == 5);
891 assert(baseCon.sup() == 5);
892 assert(baseTag.sup() == 5);
893
894 cout << "\tTest Data::inf." << endl;
895 assert(baseEx.inf() == 0);
896 assert(baseCon.inf() == 0);
897 assert(baseTag.inf() == 0);
898
899 // test data-point reduction operations
900
901 cout << "\tTest Data::minval." << endl;
902 resultEx.copy(baseEx.minval());
903 resultCon.copy(baseCon.minval());
904 resultTag.copy(baseTag.minval());
905 assert(resultEx.getPointDataView()() == 0);
906 assert(resultCon.getPointDataView()() == 0);
907 assert(resultTag.getPointDataView()() == 0);
908
909 cout << "\tTest Data::maxval." << endl;
910 resultEx.copy(baseEx.maxval());
911 resultCon.copy(baseCon.maxval());
912 resultTag.copy(baseTag.maxval());
913 assert(resultEx.getPointDataView()() == 5);
914 assert(resultCon.getPointDataView()() == 5);
915 assert(resultTag.getPointDataView()() == 5);
916
917 cout << "\tTest Data::trace." << endl;
918 resultEx.copy(baseEx.trace());
919 resultCon.copy(baseCon.trace());
920 resultTag.copy(baseTag.trace());
921 assert(resultEx.getPointDataView()() == 15);
922 assert(resultCon.getPointDataView()() == 15);
923 assert(resultTag.getPointDataView()() == 15);
924
925 }
926
927 void DataTestCase::testRefValue() {
928
929 //
930 // Note - this test can't be run as boost::python::numeric::array
931 // objects can only be created and used from within a python thread!
932 //
933
934 cout << endl;
935
936 cout << "\tTest Data object RefValue methods." << endl;
937
938 // Create three Data object - DataExpanded, DataConstant and DataEmpty
939 DataArrayView::ShapeType viewShape;
940 viewShape.push_back(3);
941 DataArrayView::ValueType viewData(3);
942 for (int i=0;i<viewShape[0];++i) {
943 viewData[i]=i;
944 }
945 DataArrayView myView(viewData,viewShape);
946
947 bool expanded=true;
948
949 Data expandedData(myView,FunctionSpace(),expanded);
950 Data constantData(myView);
951 Data emptyData;
952
953 assert(expandedData.isExpanded());
954 assert(constantData.isConstant());
955 assert(emptyData.isEmpty());
956
957 // Check assertions are thrown for RefValue methods on DataEmpty
958
959 int ref = 0;
960 boost::python::numeric::array num_array(1.0);
961
962 try {
963 emptyData.getRefValue(ref,num_array);
964 assert(false);
965 }
966 catch (EsysException& e) {
967 assert(true);
968 }
969 try {
970 emptyData.setRefValue(ref,num_array);
971 assert(false);
972 }
973 catch (EsysException& e) {
974 assert(true);
975 }
976
977 // Check assertions are thrown for RefValue methods on DataConstant
978 try {
979 constantData.getRefValue(ref,num_array);
980 assert(false);
981 }
982 catch (EsysException& e) {
983 assert(true);
984 }
985 try {
986 constantData.setRefValue(ref,num_array);
987 assert(false);
988 }
989 catch (EsysException& e) {
990 assert(true);
991 }
992
993 // Check calls to RefValue methods on DataExpanded
994 expandedData.getRefValue(ref,num_array);
995 expandedData.setRefValue(ref,num_array);
996
997 }
998
999 void DataTestCase::testMemAlloc() {
1000
1001 //
1002 // Simple little sanity check for the memory allocator
1003
1004 cout << endl;
1005
1006 Data *testData;
1007 for (int i=0; i<1000; i++) {
1008 testData = new Data(0.0, DataArrayView::ShapeType(), FunctionSpace(), true);
1009 delete testData;
1010 }
1011
1012 DataArrayView::ShapeType viewShape;
1013 viewShape.push_back(10);
1014 viewShape.push_back(10);
1015 viewShape.push_back(10);
1016
1017 Data *testData2;
1018 Data *testData3 = new Data(0.0, viewShape, FunctionSpace(), true);
1019 for (int i=0; i<1000; i++) {
1020 testData2 = new Data(0.0, viewShape, FunctionSpace(), true);
1021 delete testData2;
1022 }
1023 delete testData3;
1024
1025 }
1026
1027 TestSuite* DataTestCase::suite ()
1028 {
1029 //
1030 // create the suite of tests to perform.
1031 TestSuite *testSuite = new TestSuite ("DataTestCase");
1032
1033 testSuite->addTest (new TestCaller< DataTestCase>("testAll",&DataTestCase::testAll));
1034 testSuite->addTest (new TestCaller< DataTestCase>("testMore",&DataTestCase::testMore));
1035 testSuite->addTest (new TestCaller< DataTestCase>("testDataConstant",&DataTestCase::testDataConstant));
1036 testSuite->addTest (new TestCaller< DataTestCase>("testDataTagged",&DataTestCase::testDataTagged));
1037 testSuite->addTest (new TestCaller< DataTestCase>("testDataTaggedExceptions",&DataTestCase::testDataTaggedExceptions));
1038 testSuite->addTest (new TestCaller< DataTestCase>("testConstructors",&DataTestCase::testConstructors));
1039 testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));
1040 testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));
1041 //testSuite->addTest (new TestCaller< DataTestCase>("testRefValue",&DataTestCase::testRefValue));
1042 testSuite->addTest (new TestCaller< DataTestCase>("testMemAlloc",&DataTestCase::testMemAlloc));
1043
1044 return testSuite;
1045 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26