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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 757 - (show annotations)
Mon Jun 26 13:12:56 2006 UTC (14 years ago) by woo409
File size: 34133 byte(s)
+ Merge of intelc_win32 branch (revision 741:755) with trunk. Tested on iVEC altix (run_tests and py_tests all pass)

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26