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

Contents of /trunk-mpi-branch/bruce/test/BruceTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1306 - (show annotations)
Tue Sep 18 05:51:09 2007 UTC (11 years, 11 months ago) by ksteube
File size: 33696 byte(s)
New Copyright in each .c .h .cpp and .py file

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26