/[escript]/trunk/bruce/test/BruceTestCase.cpp
ViewVC logotype

Contents of /trunk/bruce/test/BruceTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 682 - (show annotations)
Mon Mar 27 02:43:09 2006 UTC (15 years, 6 months ago) by robwdcock
File size: 33885 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 /*
2 *****************************************************************************
3 * *
4 * COPYRIGHT ACcESS - All Rights Reserved *
5 * *
6 * This software is the property of ACcESS. No part of this code *
7 * may be copied in any form or by any means without the expressed written *
8 * consent of ACcESS. Copying, use or modification of this software *
9 * by any unauthorised person is illegal unless that person has a software *
10 * license agreement with ACcESS. *
11 * *
12 *****************************************************************************
13 */
14
15 #include "bruce/Bruce.h"
16
17 #include "escript/FunctionSpaceFactory.h"
18
19 #include "esysUtils/EsysException.h"
20
21 #include "BruceTestCase.h"
22
23 using namespace CppUnitTest;
24
25 using namespace escript;
26 using namespace esysUtils;
27 using namespace bruce;
28
29 using namespace std;
30
31 void BruceTestCase::setUp() {
32 //
33 // This is called before each test is run
34
35 }
36
37 void BruceTestCase::tearDown() {
38 //
39 // This is called after each test has been run
40
41 }
42
43 void BruceTestCase::testConstructorException() {
44
45 cout << endl;
46
47 //
48 // test constructor throws an exception for invalid arguments
49
50 Bruce::DimVec v0;
51 Bruce::DimVec v1;
52 Bruce::DimVec v2;
53 Bruce::DimVec origin;
54
55 // a 4d origin is illegal
56 origin.push_back(0);
57 origin.push_back(0);
58 origin.push_back(0);
59 origin.push_back(0);
60
61 try {
62 Bruce testbruce(v0, v1, v2, 0, 0, 0, origin);
63 assert(false);
64 }
65 catch (EsysException& e) {
66 assert(true);
67 }
68
69 }
70
71 void BruceTestCase::testNull() {
72
73 cout << endl;
74
75 //
76 // test null case
77
78 cout << "\tTest null Bruce" << endl;
79
80 std::pair<int,int> dataShape;
81
82 Bruce testbruce;
83
84 assert(testbruce.getDim()==0);
85
86 AbstractContinuousDomain testbruce_asAbstractContinuousDomain = testbruce.asAbstractContinuousDomain();
87 AbstractDomain testbruce_asAbstractDomain = testbruce.asAbstractDomain();
88
89 assert(testbruce.getDescription() == "Bruce");
90
91 assert(testbruce.isValidFunctionSpaceType(0));
92 assert(testbruce.isValidFunctionSpaceType(1));
93 assert(!testbruce.isValidFunctionSpaceType(3));
94
95 assert(testbruce.functionSpaceTypeAsString(0)=="Bruce_ContinuousFunction");
96 assert(testbruce.functionSpaceTypeAsString(1)=="Bruce_Function");
97 try {
98 testbruce.functionSpaceTypeAsString(3);
99 assert(false);
100 }
101 catch (EsysException& e) {
102 assert(true);
103 }
104
105 assert(testbruce.getContinuousFunctionCode()==0);
106 assert(testbruce.getFunctionCode()==1);
107
108 dataShape = testbruce.getDataShape(0);
109 cout << dataShape.first << " " << dataShape.second << "\n";
110 assert(dataShape.first==1);
111 assert(dataShape.second==0);
112 dataShape = testbruce.getDataShape(1);
113 assert(dataShape.first==1);
114 assert(dataShape.second==0);
115 try {
116 dataShape = testbruce.getDataShape(3);
117 assert(false);
118 }
119 catch (EsysException& e) {
120 assert(true);
121 }
122
123 }
124
125 void BruceTestCase::testZero() {
126
127 cout << endl;
128
129 //
130 // test zero case
131
132 std::pair<int,int> dataShape;
133
134 cout << "\tTest zero Bruce" << endl;
135
136 Bruce::DimVec v0;
137 Bruce::DimVec v1;
138 Bruce::DimVec v2;
139 Bruce::DimVec origin;
140
141 Bruce testbruce0(v0, v1, v2, 0, 0, 0, origin);
142
143 assert(testbruce0.getDim()==0);
144
145 AbstractContinuousDomain testbruce0_asAbstractContinuousDomain = testbruce0.asAbstractContinuousDomain();
146 AbstractDomain testbruce0_asAbstractDomain = testbruce0.asAbstractDomain();
147
148 Bruce testbruce1(testbruce0);
149
150 assert(testbruce0==testbruce1);
151
152 assert(testbruce1.getDim()==0);
153
154 AbstractContinuousDomain testbruce1_asAbstractContinuousDomain = testbruce1.asAbstractContinuousDomain();
155 AbstractDomain testbruce1_asAbstractDomain = testbruce1.asAbstractDomain();
156
157 assert(testbruce1==testbruce0);
158 assert(!(testbruce1!=testbruce0));
159
160 dataShape = testbruce1.getDataShape(0);
161 assert(dataShape.first==1);
162 assert(dataShape.second==1);
163 dataShape = testbruce1.getDataShape(1);
164 assert(dataShape.first==1);
165 assert(dataShape.second==0);
166
167 Bruce testbruce2(v0, v1, v2, 0, 0, 0, origin);
168
169 assert(testbruce0==testbruce2);
170 assert(!(testbruce0!=testbruce2));
171
172 }
173
174 void BruceTestCase::test1d() {
175
176 cout << endl;
177
178 //
179 // test 1d case
180
181 cout << "\tTest 1d Bruces" << endl;
182
183 std::pair<int,int> dataShape;
184
185 Bruce::DimVec v0;
186 Bruce::DimVec v1;
187 Bruce::DimVec v2;
188 Bruce::DimVec origin;
189
190 origin.push_back(0);
191
192 Bruce testbruce0(v0, v1, v2, 1, 0, 0, origin);
193
194 assert(testbruce0.getDim()==1);
195
196 AbstractContinuousDomain testbruce0_asAbstractContinuousDomain = testbruce0.asAbstractContinuousDomain();
197 AbstractDomain testbruce0_asAbstractDomain = testbruce0.asAbstractDomain();
198
199 dataShape = testbruce0.getDataShape(0);
200 assert(dataShape.first==1);
201 assert(dataShape.second==1);
202 dataShape = testbruce0.getDataShape(1);
203 assert(dataShape.first==1);
204 assert(dataShape.second==0);
205
206 v0.push_back(1);
207
208 Bruce testbruce1(v0, v1, v2, 2, 0, 0, origin);
209
210 assert(testbruce1.getDim()==1);
211
212 AbstractContinuousDomain testbruce1_asAbstractContinuousDomain = testbruce1.asAbstractContinuousDomain();
213 AbstractDomain testbruce1_asAbstractDomain = testbruce1.asAbstractDomain();
214
215 Bruce testbruce2(testbruce1);
216
217 assert(testbruce2==testbruce1);
218
219 assert(testbruce2.getDim()==1);
220
221 AbstractContinuousDomain testbruce2_asAbstractContinuousDomain = testbruce2.asAbstractContinuousDomain();
222 AbstractDomain testbruce2_asAbstractDomain = testbruce2.asAbstractDomain();
223
224 assert(testbruce2==testbruce1);
225 assert(!(testbruce2!=testbruce1));
226
227 dataShape = testbruce2.getDataShape(0);
228 assert(dataShape.first==1);
229 assert(dataShape.second==2);
230 dataShape = testbruce2.getDataShape(1);
231 assert(dataShape.first==1);
232 assert(dataShape.second==1);
233
234 }
235
236 void BruceTestCase::test2d() {
237
238 cout << endl;
239
240 //
241 // test 2d case
242
243 std::pair<int,int> dataShape;
244
245 cout << "\tTest 2d Bruces" << endl;
246
247 Bruce::DimVec v0;
248 Bruce::DimVec v1;
249 Bruce::DimVec v2;
250 Bruce::DimVec origin;
251
252 origin.push_back(0);
253 origin.push_back(0);
254
255 Bruce testbruce0(v0, v1, v2, 1, 0, 0, origin);
256
257 assert(testbruce0.getDim()==2);
258
259 AbstractContinuousDomain testbruce0_asAbstractContinuousDomain = testbruce0.asAbstractContinuousDomain();
260 AbstractDomain testbruce0_asAbstractDomain = testbruce0.asAbstractDomain();
261
262 dataShape = testbruce0.getDataShape(0);
263 assert(dataShape.first==1);
264 assert(dataShape.second==1);
265 dataShape = testbruce0.getDataShape(1);
266 assert(dataShape.first==1);
267 assert(dataShape.second==0);
268
269 v0.push_back(1);
270 v0.push_back(0);
271
272 Bruce testbruce1(v0, v1, v2, 2, 0, 0, origin);
273
274 assert(testbruce1.getDim()==2);
275
276 AbstractContinuousDomain testbruce1_asAbstractContinuousDomain = testbruce1.asAbstractContinuousDomain();
277 AbstractDomain testbruce1_asAbstractDomain = testbruce1.asAbstractDomain();
278
279 dataShape = testbruce1.getDataShape(0);
280 assert(dataShape.first==1);
281 assert(dataShape.second==2);
282 dataShape = testbruce1.getDataShape(1);
283 assert(dataShape.first==1);
284 assert(dataShape.second==1);
285
286 v1.push_back(0);
287 v1.push_back(1);
288
289 Bruce testbruce2(v0, v1, v2, 2, 2, 0, origin);
290
291 assert(testbruce2.getDim()==2);
292
293 AbstractContinuousDomain testbruce2_asAbstractContinuousDomain = testbruce2.asAbstractContinuousDomain();
294 AbstractDomain testbruce2_asAbstractDomain = testbruce2.asAbstractDomain();
295
296 Bruce testbruce3(testbruce2);
297
298 assert(testbruce2==testbruce3);
299
300 assert(testbruce3.getDim()==2);
301
302 AbstractContinuousDomain testbruce3_asAbstractContinuousDomain = testbruce3.asAbstractContinuousDomain();
303 AbstractDomain testbruce3_asAbstractDomain = testbruce3.asAbstractDomain();
304
305 assert(testbruce3==testbruce2);
306 assert(!(testbruce3!=testbruce2));
307
308 dataShape = testbruce3.getDataShape(0);
309 assert(dataShape.first==1);
310 assert(dataShape.second==4);
311 dataShape = testbruce3.getDataShape(1);
312 assert(dataShape.first==1);
313 assert(dataShape.second==1);
314
315 }
316
317 void BruceTestCase::test3d() {
318
319 cout << endl;
320
321 //
322 // test 3d case
323
324 std::pair<int,int> dataShape;
325
326 cout << "\tTest 3d Bruces" << endl;
327
328 Bruce::DimVec v0;
329 Bruce::DimVec v1;
330 Bruce::DimVec v2;
331 Bruce::DimVec origin;
332
333 origin.push_back(0);
334 origin.push_back(0);
335 origin.push_back(0);
336
337 Bruce testbruce0(v0, v1, v2, 1, 0, 0, origin);
338
339 assert(testbruce0.getDim()==3);
340
341 AbstractContinuousDomain testbruce0_asAbstractContinuousDomain = testbruce0.asAbstractContinuousDomain();
342 AbstractDomain testbruce0_asAbstractDomain = testbruce0.asAbstractDomain();
343
344 dataShape = testbruce0.getDataShape(0);
345 assert(dataShape.first==1);
346 assert(dataShape.second==1);
347 dataShape = testbruce0.getDataShape(1);
348 assert(dataShape.first==1);
349 assert(dataShape.second==0);
350
351 v0.push_back(1);
352 v0.push_back(0);
353 v0.push_back(0);
354
355 Bruce testbruce1(v0, v1, v2, 2, 0, 0, origin);
356
357 assert(testbruce1.getDim()==3);
358
359 AbstractContinuousDomain testbruce1_asAbstractContinuousDomain = testbruce1.asAbstractContinuousDomain();
360 AbstractDomain testbruce1_asAbstractDomain = testbruce1.asAbstractDomain();
361
362 dataShape = testbruce1.getDataShape(0);
363 assert(dataShape.first==1);
364 assert(dataShape.second==2);
365 dataShape = testbruce1.getDataShape(1);
366 assert(dataShape.first==1);
367 assert(dataShape.second==1);
368
369 v1.push_back(0);
370 v1.push_back(1);
371 v1.push_back(0);
372
373 Bruce testbruce2(v0, v1, v2, 2, 2, 0, origin);
374
375 assert(testbruce2.getDim()==3);
376
377 AbstractContinuousDomain testbruce2_asAbstractContinuousDomain = testbruce2.asAbstractContinuousDomain();
378 AbstractDomain testbruce2_asAbstractDomain = testbruce2.asAbstractDomain();
379
380 dataShape = testbruce2.getDataShape(0);
381 assert(dataShape.first==1);
382 assert(dataShape.second==4);
383 dataShape = testbruce2.getDataShape(1);
384 assert(dataShape.first==1);
385 assert(dataShape.second==1);
386
387 v2.push_back(0);
388 v2.push_back(0);
389 v2.push_back(1);
390
391 Bruce testbruce3(v0, v1, v2, 2, 2, 2, origin);
392
393 assert(testbruce3.getDim()==3);
394
395 AbstractContinuousDomain testbruce3_asAbstractContinuousDomain = testbruce3.asAbstractContinuousDomain();
396 AbstractDomain testbruce3_asAbstractDomain = testbruce3.asAbstractDomain();
397
398 Bruce testbruce4(testbruce3);
399
400 assert(testbruce4==testbruce3);
401
402 assert(testbruce4.getDim()==3);
403
404 AbstractContinuousDomain testbruce4_asAbstractContinuousDomain = testbruce4.asAbstractContinuousDomain();
405 AbstractDomain testbruce4_asAbstractDomain = testbruce4.asAbstractDomain();
406
407 assert(testbruce3==testbruce4);
408 assert(!(testbruce3!=testbruce4));
409
410 dataShape = testbruce4.getDataShape(0);
411 assert(dataShape.first==1);
412 assert(dataShape.second==8);
413 dataShape = testbruce4.getDataShape(1);
414 assert(dataShape.first==1);
415 assert(dataShape.second==1);
416
417 }
418
419 void BruceTestCase::testBig() {
420
421 cout << endl;
422
423 //
424 // test a few larger Bruce objects
425
426 std::pair<int,int> dataShape;
427
428 cout << "\tTest large Bruces" << endl;
429
430 // large 1d Bruce
431
432 Bruce::DimVec v0;
433 Bruce::DimVec v1;
434 Bruce::DimVec v2;
435 Bruce::DimVec origin;
436
437 origin.push_back(0);
438 v0.push_back(1);
439
440 Bruce testbruce0(v0, v1, v2, 100, 0, 0, origin);
441
442 assert(testbruce0.getDim()==1);
443
444 dataShape = testbruce0.getDataShape(0);
445 assert(dataShape.first==1);
446 assert(dataShape.second==100);
447 dataShape = testbruce0.getDataShape(1);
448 assert(dataShape.first==1);
449 assert(dataShape.second==99);
450
451 // large 2d Bruce
452
453 origin.push_back(0);
454
455 v0.push_back(0);
456 v1.push_back(0);
457 v1.push_back(1);
458
459 Bruce testbruce1(v0, v1, v2, 100, 100, 0, origin);
460
461 assert(testbruce1.getDim()==2);
462
463 dataShape = testbruce1.getDataShape(0);
464 assert(dataShape.first==1);
465 assert(dataShape.second==10000);
466 dataShape = testbruce1.getDataShape(1);
467 assert(dataShape.first==1);
468 assert(dataShape.second==9801);
469
470 // large 3d Bruce
471
472 origin.push_back(0);
473
474 v0.push_back(0);
475
476 v1.push_back(0);
477
478 v2.push_back(0);
479 v2.push_back(0);
480 v2.push_back(1);
481
482 Bruce testbruce2(v0, v1, v2, 100, 100, 100, origin);
483
484 assert(testbruce2.getDim()==3);
485
486 dataShape = testbruce2.getDataShape(0);
487 assert(dataShape.first==1);
488 assert(dataShape.second==1000000);
489 dataShape = testbruce2.getDataShape(1);
490 assert(dataShape.first==1);
491 assert(dataShape.second==970299);
492
493 }
494
495 void BruceTestCase::testSetToXcon() {
496
497 cout << endl;
498
499 //
500 // test setToX method on continuousFunction domains
501
502 cout << "\tTest Bruce::setToX for continuousFunctions" << endl;
503
504 Bruce::DimVec v0;
505 Bruce::DimVec v1;
506 Bruce::DimVec v2;
507 Bruce::DimVec origin;
508
509 DataArrayView::ShapeType shape;
510
511 int sampleNo;
512 DataAbstract::ValueType::value_type* sampleData;
513
514 origin.clear();
515
516 cout << "\t0d Bruce" << endl;
517
518 v0.clear();
519 v1.clear();
520 v2.clear();
521
522 cout << "\t\t0d domain" << endl;
523
524 Bruce testbruce1(v0, v1, v2, 1, 0, 0, origin);
525 shape.clear();
526 Data data1(0.0,shape,continuousFunction(testbruce1.asAbstractContinuousDomain()));
527 testbruce1.setToX(data1);
528
529 sampleNo=0;
530 sampleData = data1.getSampleData(sampleNo);
531 assert(sampleData[0]==0);
532 sampleNo++;
533
534 cout << "\t1d Bruce" << endl;
535
536 v0.clear();
537 v1.clear();
538 v2.clear();
539
540 origin.push_back(0);
541
542 cout << "\t\t0d domain" << endl;
543
544 Bruce testbruce2(v0, v1, v2, 1, 0, 0, origin);
545 shape.clear();
546 shape.push_back(1);
547 Data data2(0.0,shape,continuousFunction(testbruce2.asAbstractContinuousDomain()),true);
548 testbruce2.setToX(data2);
549
550 sampleNo=0;
551 sampleData = data2.getSampleData(sampleNo);
552 assert(sampleData[0]==0);
553 sampleNo++;
554
555 cout << "\t\t1d domain" << endl;
556
557 v0.push_back(1);
558
559 Bruce testbruce3(v0, v1, v2, 10, 0, 0, origin);
560 shape.clear();
561 shape.push_back(1);
562 Data data3(0.0,shape,continuousFunction(testbruce3.asAbstractContinuousDomain()),true);
563 testbruce3.setToX(data3);
564
565 sampleNo=0;
566 for (int i=0; i<10; i++) {
567 DataAbstract::ValueType::value_type* sampleData = data3.getSampleData(sampleNo);
568 assert(sampleData[0]==i);
569 sampleNo++;
570 }
571
572 cout << "\t2d Bruce" << endl;
573
574 v0.clear();
575 v1.clear();
576 v2.clear();
577
578 origin.push_back(0);
579
580 cout << "\t\t0d domain" << endl;
581
582 Bruce testbruce4(v0, v1, v2, 1, 0, 0, origin);
583 shape.clear();
584 shape.push_back(2);
585 Data data4(0.0,shape,continuousFunction(testbruce4.asAbstractContinuousDomain()),true);
586 testbruce4.setToX(data4);
587
588 sampleNo=0;
589 sampleData = data4.getSampleData(sampleNo);
590 assert(sampleData[0]==0);
591 assert(sampleData[1]==0);
592 sampleNo++;
593
594 cout << "\t\t1d domain" << endl;
595
596 v0.push_back(1);
597 v0.push_back(0);
598
599 Bruce testbruce5(v0, v1, v2, 10, 0, 0, origin);
600 shape.clear();
601 shape.push_back(2);
602 Data data5(0.0,shape,continuousFunction(testbruce5.asAbstractContinuousDomain()),true);
603 testbruce5.setToX(data5);
604
605 sampleNo=0;
606 for (int i=0; i<10; i++) {
607 DataAbstract::ValueType::value_type* sampleData = data5.getSampleData(sampleNo);
608 assert(sampleData[0]==i);
609 assert(sampleData[1]==0);
610 sampleNo++;
611 }
612
613 cout << "\t\t2d domain" << endl;
614
615 v1.push_back(0);
616 v1.push_back(1);
617
618 Bruce testbruce6(v0, v1, v2, 10, 10, 0, origin);
619 shape.clear();
620 shape.push_back(2);
621 Data data6(0.0,shape,continuousFunction(testbruce6.asAbstractContinuousDomain()),true);
622 testbruce6.setToX(data6);
623
624 sampleNo=0;
625 for (int i=0; i<10; i++) {
626 for (int j=0; j<10; j++) {
627 DataAbstract::ValueType::value_type* sampleData = data6.getSampleData(sampleNo);
628 assert(sampleData[0]==i);
629 assert(sampleData[1]==j);
630 sampleNo++;
631 }
632 }
633
634 cout << "\t3d Bruce" << endl;
635
636 v0.clear();
637 v1.clear();
638 v2.clear();
639
640 origin.push_back(0);
641
642 cout << "\t\t0d domain" << endl;
643
644 Bruce testbruce7(v0, v1, v2, 1, 0, 0, origin);
645 shape.clear();
646 shape.push_back(3);
647 Data data7(0.0,shape,continuousFunction(testbruce7.asAbstractContinuousDomain()),true);
648 testbruce7.setToX(data7);
649
650 sampleNo=0;
651 sampleData = data7.getSampleData(sampleNo);
652 assert(sampleData[0]==0);
653 assert(sampleData[1]==0);
654 assert(sampleData[2]==0);
655 sampleNo++;
656
657 cout << "\t\t1d domain" << endl;
658
659 v0.push_back(1);
660 v0.push_back(0);
661 v0.push_back(0);
662
663 Bruce testbruce8(v0, v1, v2, 10, 0, 0, origin);
664 shape.clear();
665 shape.push_back(3);
666 Data data8(0.0,shape,continuousFunction(testbruce8.asAbstractContinuousDomain()),true);
667 testbruce8.setToX(data8);
668
669 sampleNo=0;
670 for (int i=0; i<10; i++) {
671 DataAbstract::ValueType::value_type* sampleData = data8.getSampleData(sampleNo);
672 assert(sampleData[0]==i);
673 assert(sampleData[1]==0);
674 assert(sampleData[2]==0);
675 sampleNo++;
676 }
677
678 cout << "\t\t2d domain" << endl;
679
680 v1.push_back(0);
681 v1.push_back(1);
682 v1.push_back(0);
683
684 Bruce testbruce9(v0, v1, v2, 10, 10, 0, origin);
685 shape.clear();
686 shape.push_back(3);
687 Data data9(0.0,shape,continuousFunction(testbruce9.asAbstractContinuousDomain()),true);
688 testbruce9.setToX(data9);
689
690 sampleNo=0;
691 for (int i=0; i<10; i++) {
692 for (int j=0; j<10; j++) {
693 DataAbstract::ValueType::value_type* sampleData = data9.getSampleData(sampleNo);
694 assert(sampleData[0]==i);
695 assert(sampleData[1]==j);
696 assert(sampleData[2]==0);
697 sampleNo++;
698 }
699 }
700
701 cout << "\t\t3d domain" << endl;
702
703 v2.push_back(0);
704 v2.push_back(0);
705 v2.push_back(1);
706
707 Bruce testbruce10(v0, v1, v2, 10, 10, 10, origin);
708 shape.clear();
709 shape.push_back(3);
710 Data data10(0.0,shape,continuousFunction(testbruce10.asAbstractContinuousDomain()),true);
711 testbruce10.setToX(data10);
712
713 sampleNo=0;
714 for (int i=0; i<10; i++) {
715 for (int j=0; j<10; j++) {
716 for (int k=0; k<10; k++) {
717 DataAbstract::ValueType::value_type* sampleData = data10.getSampleData(sampleNo);
718 assert(sampleData[0]==i);
719 assert(sampleData[1]==j);
720 assert(sampleData[2]==k);
721 sampleNo++;
722 }
723 }
724 }
725
726 }
727
728 void BruceTestCase::testSetToXfun() {
729
730 cout << endl;
731
732 //
733 // test setToX method on Function domains
734
735 cout << "\tTest Bruce::setToX for functions" << endl;
736
737 Bruce::DimVec v0;
738 Bruce::DimVec v1;
739 Bruce::DimVec v2;
740 Bruce::DimVec origin;
741
742 DataArrayView::ShapeType shape;
743
744 int sampleNo;
745 DataAbstract::ValueType::value_type* sampleData;
746
747 origin.clear();
748
749 cout << "\t1d Bruce" << endl;
750
751 v0.clear();
752 v1.clear();
753 v2.clear();
754
755 origin.push_back(0);
756
757 cout << "\t\t1d domain" << endl;
758
759 v0.push_back(1);
760
761 Bruce testbruce3(v0, v1, v2, 10, 0, 0, origin);
762 shape.clear();
763 shape.push_back(1);
764 Data data3(0.0,shape,function(testbruce3.asAbstractContinuousDomain()),true);
765 testbruce3.setToX(data3);
766
767 sampleNo=0;
768 for (int i=0; i<9; i++) {
769 DataAbstract::ValueType::value_type* sampleData = data3.getSampleData(sampleNo);
770 assert(sampleData[0]==i+0.5);
771 sampleNo++;
772 }
773
774 cout << "\t2d Bruce" << endl;
775
776 v0.clear();
777 v1.clear();
778 v2.clear();
779
780 origin.push_back(0);
781
782 cout << "\t\t1d domain" << endl;
783
784 v0.push_back(1);
785 v0.push_back(0);
786
787 Bruce testbruce5(v0, v1, v2, 10, 0, 0, origin);
788 shape.clear();
789 shape.push_back(2);
790 Data data5(0.0,shape,function(testbruce5.asAbstractContinuousDomain()),true);
791 testbruce5.setToX(data5);
792
793 sampleNo=0;
794 for (int i=0; i<9; i++) {
795 DataAbstract::ValueType::value_type* sampleData = data5.getSampleData(sampleNo);
796 assert(sampleData[0]==i+0.5);
797 assert(sampleData[1]==0);
798 sampleNo++;
799 }
800
801 cout << "\t\t2d domain" << endl;
802
803 v1.push_back(0);
804 v1.push_back(1);
805
806 Bruce testbruce6(v0, v1, v2, 10, 10, 0, origin);
807 shape.clear();
808 shape.push_back(2);
809 Data data6(0.0,shape,function(testbruce6.asAbstractContinuousDomain()),true);
810 testbruce6.setToX(data6);
811
812 sampleNo=0;
813 for (int i=0; i<9; i++) {
814 for (int j=0; j<9; j++) {
815 DataAbstract::ValueType::value_type* sampleData = data6.getSampleData(sampleNo);
816 assert(sampleData[0]==i+0.5);
817 assert(sampleData[1]==j+0.5);
818 sampleNo++;
819 }
820 }
821
822 cout << "\t3d Bruce" << endl;
823
824 v0.clear();
825 v1.clear();
826 v2.clear();
827
828 origin.push_back(0);
829
830 cout << "\t\t1d domain" << endl;
831
832 v0.push_back(1);
833 v0.push_back(0);
834 v0.push_back(0);
835
836 Bruce testbruce8(v0, v1, v2, 10, 0, 0, origin);
837 shape.clear();
838 shape.push_back(3);
839 Data data8(0.0,shape,function(testbruce8.asAbstractContinuousDomain()),true);
840 testbruce8.setToX(data8);
841
842 sampleNo=0;
843 for (int i=0; i<9; i++) {
844 DataAbstract::ValueType::value_type* sampleData = data8.getSampleData(sampleNo);
845 assert(sampleData[0]==i+0.5);
846 assert(sampleData[1]==0);
847 assert(sampleData[2]==0);
848 sampleNo++;
849 }
850
851 cout << "\t\t2d domain" << endl;
852
853 v1.push_back(0);
854 v1.push_back(1);
855 v1.push_back(0);
856
857 Bruce testbruce9(v0, v1, v2, 10, 10, 0, origin);
858 shape.clear();
859 shape.push_back(3);
860 Data data9(0.0,shape,function(testbruce9.asAbstractContinuousDomain()),true);
861 testbruce9.setToX(data9);
862
863 sampleNo=0;
864 for (int i=0; i<9; i++) {
865 for (int j=0; j<9; j++) {
866 DataAbstract::ValueType::value_type* sampleData = data9.getSampleData(sampleNo);
867 assert(sampleData[0]==i+0.5);
868 assert(sampleData[1]==j+0.5);
869 assert(sampleData[2]==0);
870 sampleNo++;
871 }
872 }
873
874 cout << "\t\t3d domain" << endl;
875
876 v2.push_back(0);
877 v2.push_back(0);
878 v2.push_back(1);
879
880 Bruce testbruce10(v0, v1, v2, 10, 10, 10, origin);
881 shape.clear();
882 shape.push_back(3);
883 Data data10(0.0,shape,function(testbruce10.asAbstractContinuousDomain()),true);
884 testbruce10.setToX(data10);
885
886 sampleNo=0;
887 for (int i=0; i<9; i++) {
888 for (int j=0; j<9; j++) {
889 for (int k=0; k<9; k++) {
890 DataAbstract::ValueType::value_type* sampleData = data10.getSampleData(sampleNo);
891 assert(sampleData[0]==i+0.5);
892 assert(sampleData[1]==j+0.5);
893 assert(sampleData[2]==k+0.5);
894 sampleNo++;
895 }
896 }
897 }
898
899 }
900
901 void BruceTestCase::testSetToSizecon() {
902
903 cout << endl;
904
905 //
906 // test setToSize method on continuousFunction domains
907
908 cout << "\tTest Bruce::setToSize for continuousFunctions" << endl;
909
910 Bruce::DimVec v0;
911 Bruce::DimVec v1;
912 Bruce::DimVec v2;
913 Bruce::DimVec origin;
914
915 DataArrayView::ShapeType shape;
916 shape.clear();
917 shape.push_back(1);
918
919 int sampleNo;
920 DataAbstract::ValueType::value_type* sampleData;
921
922 origin.clear();
923
924 cout << "\t0d Bruce" << endl;
925
926 v0.clear();
927 v1.clear();
928 v2.clear();
929
930 cout << "\t\t0d domain" << endl;
931
932 Bruce testbruce1(v0, v1, v2, 1, 0, 0, origin);
933 Data data1(0.0,shape,continuousFunction(testbruce1.asAbstractContinuousDomain()));
934 testbruce1.setToSize(data1);
935
936 sampleNo=0;
937 sampleData = data1.getSampleData(sampleNo);
938 assert(sampleData[0]==0);
939 sampleNo++;
940
941 cout << "\t1d Bruce" << endl;
942
943 v0.clear();
944 v1.clear();
945 v2.clear();
946
947 origin.push_back(0);
948
949 cout << "\t\t0d domain" << endl;
950
951 Bruce testbruce2(v0, v1, v2, 1, 0, 0, origin);
952 Data data2(0.0,shape,continuousFunction(testbruce2.asAbstractContinuousDomain()),true);
953 testbruce2.setToSize(data2);
954
955 sampleNo=0;
956 sampleData = data2.getSampleData(sampleNo);
957 assert(sampleData[0]==0);
958 sampleNo++;
959
960 cout << "\t\t1d domain" << endl;
961
962 v0.push_back(1);
963
964 Bruce testbruce3(v0, v1, v2, 10, 0, 0, origin);
965 Data data3(0.0,shape,continuousFunction(testbruce3.asAbstractContinuousDomain()),true);
966 testbruce3.setToSize(data3);
967
968 sampleNo=0;
969 for (int i=0; i<10; i++) {
970 DataAbstract::ValueType::value_type* sampleData = data3.getSampleData(sampleNo);
971 assert(sampleData[0]==1);
972 sampleNo++;
973 }
974
975 cout << "\t2d Bruce" << endl;
976
977 v0.clear();
978 v1.clear();
979 v2.clear();
980
981 origin.push_back(0);
982
983 cout << "\t\t0d domain" << endl;
984
985 Bruce testbruce4(v0, v1, v2, 1, 0, 0, origin);
986 Data data4(0.0,shape,continuousFunction(testbruce4.asAbstractContinuousDomain()),true);
987 testbruce4.setToSize(data4);
988
989 sampleNo=0;
990 sampleData = data4.getSampleData(sampleNo);
991 assert(sampleData[0]==0);
992 sampleNo++;
993
994 cout << "\t\t1d domain" << endl;
995
996 v0.push_back(1);
997 v0.push_back(0);
998
999 Bruce testbruce5(v0, v1, v2, 10, 0, 0, origin);
1000 Data data5(0.0,shape,continuousFunction(testbruce5.asAbstractContinuousDomain()),true);
1001 testbruce5.setToSize(data5);
1002
1003 sampleNo=0;
1004 for (int i=0; i<10; i++) {
1005 DataAbstract::ValueType::value_type* sampleData = data5.getSampleData(sampleNo);
1006 assert(sampleData[0]==1);
1007 sampleNo++;
1008 }
1009
1010 cout << "\t\t2d domain" << endl;
1011
1012 v1.push_back(0);
1013 v1.push_back(1);
1014
1015 Bruce testbruce6(v0, v1, v2, 10, 10, 0, origin);
1016 Data data6(0.0,shape,continuousFunction(testbruce6.asAbstractContinuousDomain()),true);
1017 testbruce6.setToSize(data6);
1018
1019 sampleNo=0;
1020 for (int i=0; i<10; i++) {
1021 for (int j=0; j<10; j++) {
1022 DataAbstract::ValueType::value_type* sampleData = data6.getSampleData(sampleNo);
1023 assert(sampleData[0]==std::sqrt(2.0));
1024 sampleNo++;
1025 }
1026 }
1027
1028 cout << "\t3d Bruce" << endl;
1029
1030 v0.clear();
1031 v1.clear();
1032 v2.clear();
1033
1034 origin.push_back(0);
1035
1036 cout << "\t\t0d domain" << endl;
1037
1038 Bruce testbruce7(v0, v1, v2, 1, 0, 0, origin);
1039 Data data7(0.0,shape,continuousFunction(testbruce7.asAbstractContinuousDomain()),true);
1040 testbruce7.setToSize(data7);
1041
1042 sampleNo=0;
1043 sampleData = data7.getSampleData(sampleNo);
1044 assert(sampleData[0]==0);
1045 sampleNo++;
1046
1047 cout << "\t\t1d domain" << endl;
1048
1049 v0.push_back(1);
1050 v0.push_back(0);
1051 v0.push_back(0);
1052
1053 Bruce testbruce8(v0, v1, v2, 10, 0, 0, origin);
1054 Data data8(0.0,shape,continuousFunction(testbruce8.asAbstractContinuousDomain()),true);
1055 testbruce8.setToSize(data8);
1056
1057 sampleNo=0;
1058 for (int i=0; i<10; i++) {
1059 DataAbstract::ValueType::value_type* sampleData = data8.getSampleData(sampleNo);
1060 assert(sampleData[0]==1);
1061 sampleNo++;
1062 }
1063
1064 cout << "\t\t2d domain" << endl;
1065
1066 v1.push_back(0);
1067 v1.push_back(1);
1068 v1.push_back(0);
1069
1070 Bruce testbruce9(v0, v1, v2, 10, 10, 0, origin);
1071 Data data9(0.0,shape,continuousFunction(testbruce9.asAbstractContinuousDomain()),true);
1072 testbruce9.setToSize(data9);
1073
1074 sampleNo=0;
1075 for (int i=0; i<10; i++) {
1076 for (int j=0; j<10; j++) {
1077 DataAbstract::ValueType::value_type* sampleData = data9.getSampleData(sampleNo);
1078 assert(sampleData[0]==std::sqrt(2.0));
1079 sampleNo++;
1080 }
1081 }
1082
1083 cout << "\t\t3d domain" << endl;
1084
1085 v2.push_back(0);
1086 v2.push_back(0);
1087 v2.push_back(1);
1088
1089 Bruce testbruce10(v0, v1, v2, 10, 10, 10, origin);
1090 Data data10(0.0,shape,continuousFunction(testbruce10.asAbstractContinuousDomain()),true);
1091 testbruce10.setToSize(data10);
1092
1093 sampleNo=0;
1094 for (int i=0; i<10; i++) {
1095 for (int j=0; j<10; j++) {
1096 for (int k=0; k<10; k++) {
1097 DataAbstract::ValueType::value_type* sampleData = data10.getSampleData(sampleNo);
1098 assert(sampleData[0]==std::sqrt(3.0));
1099 sampleNo++;
1100 }
1101 }
1102 }
1103
1104 }
1105
1106 void BruceTestCase::testSetToSizefun() {
1107
1108 cout << endl;
1109
1110 //
1111 // test setToSize method on Function domains
1112
1113 cout << "\tTest Bruce::setToSize for functions" << endl;
1114
1115 Bruce::DimVec v0;
1116 Bruce::DimVec v1;
1117 Bruce::DimVec v2;
1118 Bruce::DimVec origin;
1119
1120 DataArrayView::ShapeType shape;
1121 shape.clear();
1122 shape.push_back(1);
1123
1124 int sampleNo;
1125 DataAbstract::ValueType::value_type* sampleData;
1126
1127 origin.clear();
1128
1129 cout << "\t1d Bruce" << endl;
1130
1131 v0.clear();
1132 v1.clear();
1133 v2.clear();
1134
1135 origin.push_back(0);
1136
1137 cout << "\t\t1d domain" << endl;
1138
1139 v0.push_back(1);
1140
1141 Bruce testbruce3(v0, v1, v2, 10, 0, 0, origin);
1142 Data data3(0.0,shape,function(testbruce3.asAbstractContinuousDomain()),true);
1143 testbruce3.setToSize(data3);
1144
1145 sampleNo=0;
1146 for (int i=0; i<9; i++) {
1147 DataAbstract::ValueType::value_type* sampleData = data3.getSampleData(sampleNo);
1148 assert(sampleData[0]==1);
1149 sampleNo++;
1150 }
1151
1152 cout << "\t2d Bruce" << endl;
1153
1154 v0.clear();
1155 v1.clear();
1156 v2.clear();
1157
1158 origin.push_back(0);
1159
1160 cout << "\t\t1d domain" << endl;
1161
1162 v0.push_back(1);
1163 v0.push_back(0);
1164
1165 Bruce testbruce5(v0, v1, v2, 10, 0, 0, origin);
1166 Data data5(0.0,shape,function(testbruce5.asAbstractContinuousDomain()),true);
1167 testbruce5.setToSize(data5);
1168
1169 sampleNo=0;
1170 for (int i=0; i<9; i++) {
1171 DataAbstract::ValueType::value_type* sampleData = data5.getSampleData(sampleNo);
1172 assert(sampleData[0]==1);
1173 sampleNo++;
1174 }
1175
1176 cout << "\t\t2d domain" << endl;
1177
1178 v1.push_back(0);
1179 v1.push_back(1);
1180
1181 Bruce testbruce6(v0, v1, v2, 10, 10, 0, origin);
1182 Data data6(0.0,shape,function(testbruce6.asAbstractContinuousDomain()),true);
1183 testbruce6.setToSize(data6);
1184
1185 sampleNo=0;
1186 for (int i=0; i<9; i++) {
1187 for (int j=0; j<9; j++) {
1188 DataAbstract::ValueType::value_type* sampleData = data6.getSampleData(sampleNo);
1189 assert(sampleData[0]==std::sqrt(2.0));
1190 sampleNo++;
1191 }
1192 }
1193
1194 cout << "\t3d Bruce" << endl;
1195
1196 v0.clear();
1197 v1.clear();
1198 v2.clear();
1199
1200 origin.push_back(0);
1201
1202 cout << "\t\t1d domain" << endl;
1203
1204 v0.push_back(1);
1205 v0.push_back(0);
1206 v0.push_back(0);
1207
1208 Bruce testbruce8(v0, v1, v2, 10, 0, 0, origin);
1209 Data data8(0.0,shape,function(testbruce8.asAbstractContinuousDomain()),true);
1210 testbruce8.setToSize(data8);
1211
1212 sampleNo=0;
1213 for (int i=0; i<9; i++) {
1214 DataAbstract::ValueType::value_type* sampleData = data8.getSampleData(sampleNo);
1215 assert(sampleData[0]==1);
1216 sampleNo++;
1217 }
1218
1219 cout << "\t\t2d domain" << endl;
1220
1221 v1.push_back(0);
1222 v1.push_back(1);
1223 v1.push_back(0);
1224
1225 Bruce testbruce9(v0, v1, v2, 10, 10, 0, origin);
1226 Data data9(0.0,shape,function(testbruce9.asAbstractContinuousDomain()),true);
1227 testbruce9.setToSize(data9);
1228
1229 sampleNo=0;
1230 for (int i=0; i<9; i++) {
1231 for (int j=0; j<9; j++) {
1232 DataAbstract::ValueType::value_type* sampleData = data9.getSampleData(sampleNo);
1233 assert(sampleData[0]==std::sqrt(2.0));
1234 sampleNo++;
1235 }
1236 }
1237
1238 cout << "\t\t3d domain" << endl;
1239
1240 v2.push_back(0);
1241 v2.push_back(0);
1242 v2.push_back(1);
1243
1244 Bruce testbruce10(v0, v1, v2, 10, 10, 10, origin);
1245 Data data10(0.0,shape,function(testbruce10.asAbstractContinuousDomain()),true);
1246 testbruce10.setToSize(data10);
1247
1248 sampleNo=0;
1249 for (int i=0; i<9; i++) {
1250 for (int j=0; j<9; j++) {
1251 for (int k=0; k<9; k++) {
1252 DataAbstract::ValueType::value_type* sampleData = data10.getSampleData(sampleNo);
1253 assert(sampleData[0]==std::sqrt(3.0));
1254 sampleNo++;
1255 }
1256 }
1257 }
1258
1259 }
1260
1261 void BruceTestCase::testSetToXException() {
1262
1263 cout << endl;
1264
1265 //
1266 // test setToX method exception on function domains
1267
1268 Bruce::DimVec v0;
1269 Bruce::DimVec v1;
1270 Bruce::DimVec v2;
1271 Bruce::DimVec origin;
1272
1273 DataArrayView::ShapeType shape;
1274 shape.clear();
1275 shape.push_back(1);
1276
1277 origin.clear();
1278
1279 v0.clear();
1280 v1.clear();
1281 v2.clear();
1282
1283 Bruce testbruce1(v0, v1, v2, 1, 0, 0, origin);
1284 Data data1(0.0,shape,function(testbruce1.asAbstractContinuousDomain()));
1285
1286 try {
1287 testbruce1.setToX(data1);
1288 assert(false);
1289 }
1290 catch (EsysException& e) {
1291 assert(true);
1292 }
1293
1294 }
1295
1296 void BruceTestCase::testSetToSizeException() {
1297
1298 cout << endl;
1299
1300 //
1301 // test setToSize method exception on function domains
1302
1303 Bruce::DimVec v0;
1304 Bruce::DimVec v1;
1305 Bruce::DimVec v2;
1306 Bruce::DimVec origin;
1307
1308 DataArrayView::ShapeType shape;
1309 shape.clear();
1310 shape.push_back(1);
1311
1312 origin.clear();
1313
1314 v0.clear();
1315 v1.clear();
1316 v2.clear();
1317
1318 Bruce testbruce1(v0, v1, v2, 1, 0, 0, origin);
1319 Data data1(0.0,shape,function(testbruce1.asAbstractContinuousDomain()));
1320
1321 try {
1322 testbruce1.setToSize(data1);
1323 assert(false);
1324 }
1325 catch (EsysException& e) {
1326 assert(true);
1327 }
1328
1329 }
1330
1331 void BruceTestCase::testGetReferenceNoFromSampleNo() {
1332
1333 cout << endl;
1334
1335 //
1336 // test getReferenceNoFromSampleNo method
1337
1338 Bruce::DimVec v0;
1339 Bruce::DimVec v1;
1340 Bruce::DimVec v2;
1341 Bruce::DimVec origin;
1342
1343 std::pair<int,int> dataShape;
1344 int numSamples;
1345
1346 v0.push_back(1);
1347 v0.push_back(0);
1348 v0.push_back(0);
1349
1350 v1.push_back(0);
1351 v1.push_back(1);
1352 v1.push_back(0);
1353
1354 v2.push_back(0);
1355 v2.push_back(0);
1356 v2.push_back(1);
1357
1358 origin.push_back(0);
1359 origin.push_back(0);
1360 origin.push_back(0);
1361
1362 Bruce testbruce(v0, v1, v2, 10, 10, 10, origin);
1363
1364 cout << "\tTest Bruce::getReferenceNoFromSampleNo for functions" << endl;
1365
1366 dataShape = testbruce.getDataShape(0);
1367 numSamples=dataShape.second;
1368
1369 for (int i=0; i<numSamples; i++) {
1370 assert(testbruce.getReferenceNoFromSampleNo(0,i)==i);
1371 }
1372
1373 cout << "\tTest Bruce::getReferenceNoFromSampleNo for continuousFunctions" << endl;
1374
1375 dataShape = testbruce.getDataShape(1);
1376 numSamples=dataShape.second;
1377
1378 for (int i=0; i<numSamples; i++) {
1379 assert(testbruce.getReferenceNoFromSampleNo(1,i)==i);
1380 }
1381
1382 }
1383
1384 TestSuite* BruceTestCase::suite ()
1385 {
1386 //
1387 // create the suite of tests to perform.
1388 TestSuite *testSuite = new TestSuite ("BruceTestCase");
1389
1390 testSuite->addTest (new TestCaller< BruceTestCase>("testConstructorException",&BruceTestCase::testConstructorException));
1391 testSuite->addTest (new TestCaller< BruceTestCase>("testNull",&BruceTestCase::testNull));
1392 testSuite->addTest (new TestCaller< BruceTestCase>("testZero",&BruceTestCase::testZero));
1393 testSuite->addTest (new TestCaller< BruceTestCase>("test1d",&BruceTestCase::test1d));
1394 testSuite->addTest (new TestCaller< BruceTestCase>("test2d",&BruceTestCase::test2d));
1395 testSuite->addTest (new TestCaller< BruceTestCase>("test3d",&BruceTestCase::test3d));
1396 testSuite->addTest (new TestCaller< BruceTestCase>("testBig",&BruceTestCase::testBig));
1397 testSuite->addTest (new TestCaller< BruceTestCase>("testSetToXcon",&BruceTestCase::testSetToXcon));
1398 testSuite->addTest (new TestCaller< BruceTestCase>("testSetToXfun",&BruceTestCase::testSetToXfun));
1399 testSuite->addTest (new TestCaller< BruceTestCase>("testSetToSizecon",&BruceTestCase::testSetToSizecon));
1400 testSuite->addTest (new TestCaller< BruceTestCase>("testSetToSizefun",&BruceTestCase::testSetToSizefun));
1401 testSuite->addTest (new TestCaller< BruceTestCase>("testSetToXException",&BruceTestCase::testSetToXException));
1402 testSuite->addTest (new TestCaller< BruceTestCase>("testSetToSizeException",&BruceTestCase::testSetToSizeException));
1403 testSuite->addTest (new TestCaller< BruceTestCase>("testGetReferenceNoFromSampleNo();",&BruceTestCase::testGetReferenceNoFromSampleNo));
1404 return testSuite;
1405 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26