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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26