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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26