cloudy trunk
Loading...
Searching...
No Matches
TestMultiArr.cpp
Go to the documentation of this file.
1/* This file is part of Cloudy and is copyright (C)1978-2013 by Gary J. Ferland and
2 * others. For conditions of distribution and use see copyright notice in license.txt */
3#include "cdstd.h"
4#include <UnitTest++.h>
5#include "cddefines.h"
6#include <functional>
7
8namespace {
9
10 // use this for out-of-bounds array access tests to avoid comiler warnings
11 long m1 = -1L;
12
13 template<mem_layout ALLOC,bool lgBC>
14 struct LongInt2DFixtureGeneric
15 {
16 multi_arr<long,2,ALLOC,lgBC> arr;
17 LongInt2DFixtureGeneric()
18 {
19 arr.alloc(10,9);
20 for (int i=0; i<10; ++i)
21 for (int j=0; j<9; ++j)
22 arr[i][j] = i*10+j;
23 }
24 ~LongInt2DFixtureGeneric() {}
25 };
26
27 typedef LongInt2DFixtureGeneric<ARPA_TYPE,false> LongInt2DFixture;
28 typedef LongInt2DFixtureGeneric<ARPA_TYPE,true> LongInt2DFixtureBC;
29 typedef LongInt2DFixtureGeneric<C_TYPE,false> LongInt2DFixtureCType;
30 typedef LongInt2DFixtureGeneric<C_TYPE,true> LongInt2DFixtureCTypeBC;
31
32 template<mem_layout ALLOC,bool lgBC>
33 struct LongInt3DFixtureGeneric
34 {
35 multi_arr<long,3,ALLOC,lgBC> arr;
36 LongInt3DFixtureGeneric()
37 {
38 arr.alloc(10,9,8);
39 for (int i=0; i<10; ++i)
40 for (int j=0; j<9; ++j)
41 for (int k=0; k<8; ++k)
42 arr[i][j][k] = i*100+j*10+k;
43 }
44 ~LongInt3DFixtureGeneric() {}
45 };
46
47 typedef LongInt3DFixtureGeneric<ARPA_TYPE,false> LongInt3DFixture;
48 typedef LongInt3DFixtureGeneric<ARPA_TYPE,true> LongInt3DFixtureBC;
49 typedef LongInt3DFixtureGeneric<C_TYPE,false> LongInt3DFixtureCType;
50 typedef LongInt3DFixtureGeneric<C_TYPE,true> LongInt3DFixtureCTypeBC;
51
52 struct RealNum3DFixture
53 {
54 multi_arr<realnum,3,ARPA_TYPE,false> arr;
55 RealNum3DFixture()
56 {
57 arr.alloc(10,9,8);
58 }
59 ~RealNum3DFixture() {}
60 };
61
62 struct Double3DFixture
63 {
64 multi_arr<double,3,ARPA_TYPE,false> arr;
65 Double3DFixture()
66 {
67 arr.alloc(10,9,8);
68 }
69 ~Double3DFixture() {}
70 };
71
72 template<mem_layout ALLOC>
73 struct StructWithConstructor3DFixtureGeneric
74 {
75 struct a
76 {
77 long n;
78 a() { n = 23; }
79 ~a() {}
80 };
81 multi_arr<a,3,ALLOC,false> arr;
82 StructWithConstructor3DFixtureGeneric()
83 {
84 arr.alloc(2,3,4);
85 }
86 ~StructWithConstructor3DFixtureGeneric() {}
87 };
88
89 typedef StructWithConstructor3DFixtureGeneric<ARPA_TYPE> StructWithConstructor3DFixture;
90 typedef StructWithConstructor3DFixtureGeneric<C_TYPE> StructWithConstructor3DFixtureCType;
91
92 template<mem_layout ALLOC,bool lgBC>
93 struct LongInt4DFixtureGeneric
94 {
95 multi_arr<long,4,ALLOC,lgBC> arr;
96 LongInt4DFixtureGeneric()
97 {
98 arr.alloc(10,9,8,7);
99 for (int i=0; i<10; ++i)
100 for (int j=0; j<9; ++j)
101 for (int k=0; k<8; ++k)
102 for (int l=0; l<7; ++l)
103 arr[i][j][k][l] = i*1000+j*100+k*10+l;
104 }
105 ~LongInt4DFixtureGeneric() {}
106 };
107
108 typedef LongInt4DFixtureGeneric<ARPA_TYPE,false> LongInt4DFixture;
109 typedef LongInt4DFixtureGeneric<ARPA_TYPE,true> LongInt4DFixtureBC;
110 typedef LongInt4DFixtureGeneric<C_TYPE,false> LongInt4DFixtureCType;
111 typedef LongInt4DFixtureGeneric<C_TYPE,true> LongInt4DFixtureCTypeBC;
112
113 template<mem_layout ALLOC,bool lgBC>
114 struct LongInt5DFixtureGeneric
115 {
116 multi_arr<long,5,ALLOC,lgBC> arr;
117 LongInt5DFixtureGeneric()
118 {
119 arr.alloc(10,9,8,7,6);
120 for (int i=0; i<10; ++i)
121 for (int j=0; j<9; ++j)
122 for (int k=0; k<8; ++k)
123 for (int l=0; l<7; ++l)
124 for (int m=0; m<6; ++m)
125 arr[i][j][k][l][m] = i*10000+j*1000+k*100+l*10+m;
126 }
127 ~LongInt5DFixtureGeneric() {}
128 };
129
130 typedef LongInt5DFixtureGeneric<ARPA_TYPE,false> LongInt5DFixture;
131 typedef LongInt5DFixtureGeneric<ARPA_TYPE,true> LongInt5DFixtureBC;
132 typedef LongInt5DFixtureGeneric<C_TYPE,false> LongInt5DFixtureCType;
133 typedef LongInt5DFixtureGeneric<C_TYPE,true> LongInt5DFixtureCTypeBC;
134
135 template<mem_layout ALLOC,bool lgBC>
136 struct LongInt6DFixtureGeneric
137 {
138 multi_arr<long,6,ALLOC,lgBC> arr;
139 LongInt6DFixtureGeneric()
140 {
141 arr.alloc(10,9,8,7,6,5);
142 for (int i=0; i<10; ++i)
143 for (int j=0; j<9; ++j)
144 for (int k=0; k<8; ++k)
145 for (int l=0; l<7; ++l)
146 for (int m=0; m<6; ++m)
147 for (int n=0; n<5; ++n)
148 arr[i][j][k][l][m][n] =
149 i*100000+j*10000+k*1000+l*100+m*10+n;
150 }
151 ~LongInt6DFixtureGeneric() {}
152 };
153
154 typedef LongInt6DFixtureGeneric<ARPA_TYPE,false> LongInt6DFixture;
155 typedef LongInt6DFixtureGeneric<ARPA_TYPE,true> LongInt6DFixtureBC;
156 typedef LongInt6DFixtureGeneric<C_TYPE,false> LongInt6DFixtureCType;
157 typedef LongInt6DFixtureGeneric<C_TYPE,true> LongInt6DFixtureCTypeBC;
158
159 struct LongInt6DFixtureExplicitReserve
160 {
161 multi_arr<long,6,ARPA_TYPE,true> arr;
162 LongInt6DFixtureExplicitReserve()
163 {
164 arr.reserve(10);
165 for (int i=0; i<10; ++i)
166 {
167 arr.reserve(i,9);
168 for (int j=0; j<9; ++j)
169 {
170 arr.reserve(i,j,8);
171 for (int k=0; k<8; ++k)
172 {
173 arr.reserve(i,j,k,7);
174 for (int l=0; l<7; ++l)
175 {
176 arr.reserve(i,j,k,l,6);
177 for (int m=0; m<6; ++m)
178 {
179 arr.reserve(i,j,k,l,m,5);
180 }
181 }
182 }
183 }
184 }
185 arr.alloc();
186 }
187 ~LongInt6DFixtureExplicitReserve() {}
188 };
189
190 struct TestAllocFixture
191 {
192 TestAllocFixture() {}
193 ~TestAllocFixture() {}
194 long mytest()
195 {
196 multi_arr<long,2,ARPA_TYPE,true> a2(2,3);
197 multi_arr<long,3,ARPA_TYPE,true> a3(2,3,4);
198 multi_arr<long,4,ARPA_TYPE,true> a4(2,3,4,5);
199 multi_arr<long,5,ARPA_TYPE,true> a5(2,3,4,5,6);
200 multi_arr<long,6,ARPA_TYPE,true> a6(2,3,4,5,6,7);
201
207
208 a2.zero();
209 a3.zero();
210 a4.zero();
211 a5.zero();
212 a6.zero();
213
214 long res = 0;
215 for (int i=0; i<2; ++i)
216 for (int j=0; j<3; ++j)
217 {
218 p2 = a2.ptr(i,j);
219 res += ( *p2 != 0 );
220 for (int k=0; k<4; ++k)
221 {
222 p3 = a3.ptr(i,j,k);
223 res += ( *p3 != 0 );
224 for (int l=0; l<5; ++l)
225 {
226 p4 = a4.ptr(i,j,k,l);
227 res += ( *p4 != 0 );
228 for (int m=0; m<6; ++m)
229 {
230 p5 = a5.ptr(i,j,k,l,m);
231 res += ( *p5 != 0 );
232 for (int n=0; n<7; ++n)
233 {
234 p6 = a6.ptr(i,j,k,l,m,n);
235 res += ( *p6 != 0 );
236 }
237 }
238 }
239 }
240 }
241
242 return res;
243 }
244 };
245
246 struct LongInt3DCLayoutFixture
247 {
248 multi_arr<long,3,C_TYPE,false> arr;
249 LongInt3DCLayoutFixture()
250 {
251 arr.alloc(10,10,10);
252 for (int i=0; i<10; ++i)
253 for (int j=0; j<10; ++j)
254 for (int k=0; k<10; ++k)
255 arr[i][j][k] = 100*i+10*j+k;
256 }
257 ~LongInt3DCLayoutFixture() {}
258 long mytest(const long a[][10][10])
259 {
260 long res = 0;
261 for (int i=0; i<10; ++i)
262 for (int j=0; j<10; ++j)
263 for (int k=0; k<10; ++k)
264 res += ( a[i][j][k] != 100*i+10*j+k );
265
266 return res;
267 }
268 };
269
270 template<mem_layout ALLOC>
271 struct LongInt3DCloneFixtureGeneric
272 {
273 multi_arr<long,3,ALLOC,true> arr;
274 LongInt3DCloneFixtureGeneric()
275 {
276 arr.reserve(10);
277 for (int i=0; i<10; ++i)
278 {
279 arr.reserve(i,i+1);
280 for (int j=0; j<i+1; ++j)
281 arr.reserve(i,j,j+1);
282 }
283 arr.alloc();
284 }
285 ~LongInt3DCloneFixtureGeneric() {}
286 };
287
288 typedef LongInt3DCloneFixtureGeneric<ARPA_TYPE> LongInt3DCloneFixture;
289 typedef LongInt3DCloneFixtureGeneric<C_TYPE> LongInt3DCloneFixtureCType;
290
291 template<mem_layout ALLOC>
292 struct LongInt2DEmptyDimGeneric
293 {
294 multi_arr<long,2,ALLOC,true> arr;
295 LongInt2DEmptyDimGeneric()
296 {
297 arr.reserve(2);
298 for (int i=1; i<2; ++i)
299 {
300 arr.reserve(i,2);
301 }
302 arr.alloc();
303 }
304 ~LongInt2DEmptyDimGeneric() {}
305 };
306
307 typedef LongInt2DEmptyDimGeneric<ARPA_TYPE> LongInt2DEmptyDim;
308 typedef LongInt2DEmptyDimGeneric<C_TYPE> LongInt2DEmptyDimCType;
309
310 template<mem_layout ALLOC>
311 struct LongInt3DEmptyDimGeneric
312 {
313 multi_arr<long,3,ALLOC,true> arr;
314 LongInt3DEmptyDimGeneric()
315 {
316 arr.reserve(2);
317 for (int i=0; i<2; ++i)
318 {
319 arr.reserve(i,2);
320 for (int j=1; j<2; ++j)
321 {
322 arr.reserve(i,j,2);
323 }
324 }
325 arr.alloc();
326 }
327 ~LongInt3DEmptyDimGeneric() {}
328 };
329
330 typedef LongInt3DEmptyDimGeneric<ARPA_TYPE> LongInt3DEmptyDim;
331 typedef LongInt3DEmptyDimGeneric<C_TYPE> LongInt3DEmptyDimCType;
332
333 template<mem_layout ALLOC>
334 struct LongInt4DEmptyDimGeneric
335 {
336 multi_arr<long,4,ALLOC,true> arr;
337 LongInt4DEmptyDimGeneric()
338 {
339 arr.reserve(2);
340 for (int i=0; i<2; ++i)
341 {
342 arr.reserve(i,2);
343 for (int j=0; j<2; ++j)
344 {
345 arr.reserve(i,j,2);
346 for (int k=1; k<2; ++k)
347 {
348 arr.reserve(i,j,k,2);
349 }
350 }
351 }
352 arr.alloc();
353 }
354 ~LongInt4DEmptyDimGeneric() {}
355 };
356
357 typedef LongInt4DEmptyDimGeneric<ARPA_TYPE> LongInt4DEmptyDim;
358 typedef LongInt4DEmptyDimGeneric<C_TYPE> LongInt4DEmptyDimCType;
359
360 template<mem_layout ALLOC>
361 struct LongInt5DEmptyDimGeneric
362 {
363 multi_arr<long,5,ALLOC,true> arr;
364 LongInt5DEmptyDimGeneric()
365 {
366 arr.reserve(2);
367 for (int i=0; i<2; ++i)
368 {
369 arr.reserve(i,2);
370 for (int j=0; j<2; ++j)
371 {
372 arr.reserve(i,j,2);
373 for (int k=0; k<2; ++k)
374 {
375 arr.reserve(i,j,k,2);
376 for (int l=1; l<2; ++l)
377 {
378 arr.reserve(i,j,k,l,2);
379 }
380 }
381 }
382 }
383 arr.alloc();
384 }
385 ~LongInt5DEmptyDimGeneric() {}
386 };
387
388 typedef LongInt5DEmptyDimGeneric<ARPA_TYPE> LongInt5DEmptyDim;
389 typedef LongInt5DEmptyDimGeneric<C_TYPE> LongInt5DEmptyDimCType;
390
391 template<mem_layout ALLOC>
392 struct LongInt6DEmptyDimGeneric
393 {
394 multi_arr<long,6,ALLOC,true> arr;
395 LongInt6DEmptyDimGeneric()
396 {
397 arr.reserve(2);
398 for (int i=0; i<2; ++i)
399 {
400 arr.reserve(i,2);
401 for (int j=0; j<2; ++j)
402 {
403 arr.reserve(i,j,2);
404 for (int k=0; k<2; ++k)
405 {
406 arr.reserve(i,j,k,2);
407 for (int l=0; l<2; ++l)
408 {
409 arr.reserve(i,j,k,l,2);
410 for (int m=1; m<2; ++m)
411 {
412 arr.reserve(i,j,k,l,m,2);
413 }
414 }
415 }
416 }
417 }
418 arr.alloc();
419 }
420 ~LongInt6DEmptyDimGeneric() {}
421 };
422
423 typedef LongInt6DEmptyDimGeneric<ARPA_TYPE> LongInt6DEmptyDim;
424 typedef LongInt6DEmptyDimGeneric<C_TYPE> LongInt6DEmptyDimCType;
425
426 // first test all the forms of iterator arithmetic on the pntr class
427 TEST_FIXTURE(LongInt2DFixture,TestIteratorPostIncrement)
428 {
430 p = arr.ptr(5,6);
431 p++;
432 CHECK_EQUAL(57,*p);
433 }
434 TEST_FIXTURE(LongInt2DFixture,TestIteratorPreIncrement)
435 {
437 p = arr.ptr(5,6);
438 ++p;
439 CHECK_EQUAL(57,*p);
440 }
441 TEST_FIXTURE(LongInt2DFixture,TestIteratorPostDecrement)
442 {
444 p = arr.ptr(5,6);
445 p--;
446 CHECK_EQUAL(55,*p);
447 }
448 TEST_FIXTURE(LongInt2DFixture,TestIteratorPreDecrement)
449 {
451 p = arr.ptr(5,6);
452 --p;
453 CHECK_EQUAL(55,*p);
454 }
455 TEST_FIXTURE(LongInt2DFixture,TestIteratorAddition1)
456 {
458 p = arr.ptr(5,6);
459 p += 2;
460 CHECK_EQUAL(58,*p);
461 }
462 TEST_FIXTURE(LongInt2DFixture,TestIteratorSubtraction1)
463 {
465 p = arr.ptr(5,6);
466 p -= 2;
467 CHECK_EQUAL(54,*p);
468 }
469 TEST_FIXTURE(LongInt2DFixture,TestIteratorAddition2)
470 {
472 p = arr.ptr(5,6);
473 q = p + 2;
474 CHECK_EQUAL(58,*q);
475 }
476 TEST_FIXTURE(LongInt2DFixture,TestIteratorSubtraction2)
477 {
479 p = arr.ptr(5,6);
480 q = p - 2;
481 CHECK_EQUAL(54,*q);
482 }
483 TEST_FIXTURE(LongInt2DFixture,TestIteratorAddition3)
484 {
486 p = arr.ptr(5,6);
487 q = 2 + p;
488 CHECK_EQUAL(58,*q);
489 }
490 TEST_FIXTURE(LongInt2DFixture,TestIteratorSubtraction3)
491 {
493 p = arr.ptr(5,6);
494 q = p - 2;
495 CHECK_EQUAL(2,p-q);
496 }
497 TEST_FIXTURE(LongInt2DFixture,TestIteratorBrackets)
498 {
500 p = arr.ptr(5,6);
501 CHECK_EQUAL(57,p[1]);
502 }
503
504 // now test all 6 forms of logical comparison on the pntr class
505 TEST_FIXTURE(LongInt2DFixture,TestIteratorComparison1)
506 {
508 p = arr.ptr(5,6);
509 q = ++p;
510 CHECK(p == q);
511 }
512 TEST_FIXTURE(LongInt2DFixture,TestIteratorComparison2)
513 {
515 p = arr.ptr(5,6);
516 q = p++;
517 CHECK(p != q);
518 }
519 TEST_FIXTURE(LongInt2DFixture,TestIteratorComparison3)
520 {
522 p = arr.ptr(5,6);
523 q = p--;
524 CHECK(p < q);
525 }
526 TEST_FIXTURE(LongInt2DFixture,TestIteratorComparison4)
527 {
529 p = arr.ptr(5,6);
530 q = --p;
531 CHECK(p <= q);
532 }
533 TEST_FIXTURE(LongInt2DFixture,TestIteratorComparison5)
534 {
536 p = arr.ptr(5,6);
537 q = p++;
538 CHECK(p > q);
539 }
540 TEST_FIXTURE(LongInt2DFixture,TestIteratorComparison6)
541 {
543 p = arr.ptr(5,6);
544 q = --p;
545 CHECK(p >= q);
546 }
547
548 // test out-of-bounds access via a pntr
549 TEST_FIXTURE(LongInt2DFixtureBC,TestIteratorBoundsCheck)
550 {
552 p = arr.ptr(5,8);
553 CHECK_THROW(( *++p == 59 ),out_of_range);
554 }
555
556 // now do all the tests from above again on the const_pntr class
557 TEST_FIXTURE(LongInt2DFixture,TestConstIteratorPostIncrement)
558 {
560 p = arr.ptr(5,6);
561 p++;
562 CHECK_EQUAL(57,*p);
563 }
564 TEST_FIXTURE(LongInt2DFixture,TestConstIteratorPreIncrement)
565 {
567 p = arr.ptr(5,6);
568 ++p;
569 CHECK_EQUAL(57,*p);
570 }
571 TEST_FIXTURE(LongInt2DFixture,TestConstIteratorPostDecrement)
572 {
574 p = arr.ptr(5,6);
575 p--;
576 CHECK_EQUAL(55,*p);
577 }
578 TEST_FIXTURE(LongInt2DFixture,TestConstIteratorPreDecrement)
579 {
581 p = arr.ptr(5,6);
582 --p;
583 CHECK_EQUAL(55,*p);
584 }
585 TEST_FIXTURE(LongInt2DFixture,TestConstIteratorAddition1)
586 {
588 p = arr.ptr(5,6);
589 p += 2;
590 CHECK_EQUAL(58,*p);
591 }
592 TEST_FIXTURE(LongInt2DFixture,TestConstIteratorSubtraction1)
593 {
595 p = arr.ptr(5,6);
596 p -= 2;
597 CHECK_EQUAL(54,*p);
598 }
599 TEST_FIXTURE(LongInt2DFixture,TestConstIteratorAddition2)
600 {
602 p = arr.ptr(5,6);
603 q = p + 2;
604 CHECK_EQUAL(58,*q);
605 }
606 TEST_FIXTURE(LongInt2DFixture,TestConstIteratorSubtraction2)
607 {
609 p = arr.ptr(5,6);
610 q = p - 2;
611 CHECK_EQUAL(54,*q);
612 }
613 TEST_FIXTURE(LongInt2DFixture,TestConstIteratorAddition3)
614 {
616 p = arr.ptr(5,6);
617 q = 2 + p;
618 CHECK_EQUAL(58,*q);
619 }
620 TEST_FIXTURE(LongInt2DFixture,TestConstIteratorSubtraction3)
621 {
623 p = arr.ptr(5,6);
624 q = p - 2;
625 CHECK_EQUAL(2,p-q);
626 }
627 TEST_FIXTURE(LongInt2DFixture,TestConstIteratorBrackets)
628 {
630 p = arr.ptr(5,6);
631 CHECK_EQUAL(57,p[1]);
632 }
633
634 TEST_FIXTURE(LongInt2DFixture,TestConstIteratorComparison1)
635 {
637 p = arr.ptr(5,6);
638 q = ++p;
639 CHECK(p == q);
640 }
641 TEST_FIXTURE(LongInt2DFixture,TestConstIteratorComparison2)
642 {
644 p = arr.ptr(5,6);
645 q = p++;
646 CHECK(p != q);
647 }
648 TEST_FIXTURE(LongInt2DFixture,TestConstIteratorComparison3)
649 {
651 p = arr.ptr(5,6);
652 q = p--;
653 CHECK(p < q);
654 }
655 TEST_FIXTURE(LongInt2DFixture,TestConstIteratorComparison4)
656 {
658 p = arr.ptr(5,6);
659 q = --p;
660 CHECK(p <= q);
661 }
662 TEST_FIXTURE(LongInt2DFixture,TestConstIteratorComparison5)
663 {
665 p = arr.ptr(5,6);
666 q = p++;
667 CHECK(p > q);
668 }
669 TEST_FIXTURE(LongInt2DFixture,TestConstIteratorComparison6)
670 {
672 p = arr.ptr(5,6);
673 q = --p;
674 CHECK(p >= q);
675 }
676
677 TEST_FIXTURE(LongInt2DFixtureBC,TestConstIteratorBoundsCheck)
678 {
680 p = arr.ptr(5,8);
681 CHECK_THROW(( *++p == 59 ),out_of_range);
682 }
683
684 TEST_FIXTURE(LongInt3DFixture,TestDataEmpty)
685 {
686 arr.clear();
687 // calling alloc() should be safe...
688 arr.alloc();
689 CHECK_EQUAL( 0UL, arr.size() );
690 CHECK( NULL == arr.data() );
691 }
692
693 // now we test the zero() and invalidate() methods
694 TEST_FIXTURE(LongInt3DFixture,TestFill)
695 {
696 arr.zero();
697 for (int i=0; i<10; ++i)
698 for (int j=0; j<9; ++j)
699 for (int k=0; k<8; ++k)
700 CHECK_EQUAL(0,arr[i][j][k]);
701 arr.invalidate();
702 for (int i=0; i<10; ++i)
703 for (int j=0; j<9; ++j)
704 for (int k=0; k<8; ++k)
705 CHECK_EQUAL(-1,arr[i][j][k]);
706 arr.clear();
707 // these operations should be safe and do nothing
708 arr.zero();
709 arr.invalidate();
710 }
711 // same for C_TYPE arrays, also checks whether any legal index
712 // accidientally throws an out_of_range exception
713 TEST_FIXTURE(LongInt3DFixtureCTypeBC,TestFillCType)
714 {
715 arr.zero();
716 for (int i=0; i<10; ++i)
717 for (int j=0; j<9; ++j)
718 for (int k=0; k<8; ++k)
719 CHECK_EQUAL(0.,arr[i][j][k]);
720 arr.invalidate();
721 for (int i=0; i<10; ++i)
722 for (int j=0; j<9; ++j)
723 for (int k=0; k<8; ++k)
724 CHECK_EQUAL(-1,arr[i][j][k]);
725 }
726 // now test whether realnum and double are properly invalidated
727 TEST_FIXTURE(RealNum3DFixture,TestInvalidRealNum)
728 {
729 arr.invalidate();
730 for (int i=0; i<10; ++i)
731 for (int j=0; j<9; ++j)
732 for (int k=0; k<8; ++k)
733 CHECK(isnan(arr[i][j][k]));
734 arr.clear();
735 // these operations should be safe and do nothing
736 arr.invalidate();
737 }
738 TEST_FIXTURE(Double3DFixture,TestInvalidDouble)
739 {
740 arr.invalidate();
741 for (int i=0; i<10; ++i)
742 for (int j=0; j<9; ++j)
743 for (int k=0; k<8; ++k)
744 CHECK(isnan(arr[i][j][k]));
745 arr.clear();
746 // these operations should be safe and do nothing
747 arr.invalidate();
748 }
749 // test the state_do function
750 TEST_FIXTURE(LongInt3DFixture,TestStateDo)
751 {
752 const char *fnam = "tma.872GqS";
753 FILE *io = fopen( fnam, "wb" );
754 CHECK( io != NULL );
755 arr.state_do( io, false ); // dump state
756 fclose( io );
757 arr.invalidate(); // trash contents
758 io = fopen( fnam, "rb" );
759 CHECK( io != NULL );
760 arr.state_do( io, true ); // restore state
761 fclose( io );
762 remove(fnam);
763 CHECK_EQUAL(304,arr[3][0][4]);
764 }
765 // same for a C_TYPE array
766 TEST_FIXTURE(LongInt3DFixtureCType,TestStateDoCType)
767 {
768 const char *fnam = "tma.872GqS";
769 FILE *io = fopen( fnam, "wb" );
770 CHECK( io != NULL );
771 arr.state_do( io, false ); // dump state
772 fclose( io );
773 arr.invalidate(); // trash contents
774 io = fopen( fnam, "rb" );
775 CHECK( io != NULL );
776 arr.state_do( io, true ); // restore state
777 fclose( io );
778 remove(fnam);
779 CHECK_EQUAL(304,arr[3][0][4]);
780 }
781
782 // test access through both indexing and ptr methods for all dimensions
783 // some of this will already have been tested implicitly above
784 TEST_FIXTURE(LongInt2DFixture,Test2DIndexedValue)
785 {
786 CHECK_EQUAL(98,arr[9][8]);
787 CHECK_EQUAL(37,*arr.ptr(3,7));
788 const multi_arr<long,2,ARPA_TYPE,false>* carr = &arr;
790 CHECK_EQUAL(46,*p);
791 const long& q = (*carr)[7][5];
792 CHECK_EQUAL(75,q);
793 }
794 TEST_FIXTURE(LongInt3DFixture,Test3DIndexedValue)
795 {
796 CHECK_EQUAL(987,arr[9][8][7]);
797 CHECK_EQUAL(137,*arr.ptr(1,3,7));
798 const multi_arr<long,3,ARPA_TYPE,false>* carr = &arr;
800 CHECK_EQUAL(462,*p);
801 const long& q = (*carr)[7][5][6];
802 CHECK_EQUAL(756,q);
803 }
804 TEST_FIXTURE(LongInt4DFixture,Test4DIndexedValue)
805 {
806 CHECK_EQUAL(9876,arr[9][8][7][6]);
807 CHECK_EQUAL(1342,*arr.ptr(1,3,4,2));
808 const multi_arr<long,4,ARPA_TYPE,false>* carr = &arr;
810 CHECK_EQUAL(4620,*p);
811 const long& q = (*carr)[7][5][6][3];
812 CHECK_EQUAL(7563,q);
813 }
814 TEST_FIXTURE(LongInt5DFixture,Test5DIndexedValue)
815 {
816 CHECK_EQUAL(98765,arr[9][8][7][6][5]);
817 CHECK_EQUAL(10342,*arr.ptr(1,0,3,4,2));
818 const multi_arr<long,5,ARPA_TYPE,false>* carr = &arr;
820 CHECK_EQUAL(46201,*p);
821 const long& q = (*carr)[7][5][6][3][2];
822 CHECK_EQUAL(75632,q);
823 }
824 TEST_FIXTURE(LongInt6DFixture,Test6DIndexedValue)
825 {
826 CHECK_EQUAL(987654,arr[9][8][7][6][5][4]);
827 CHECK_EQUAL(106423,*arr.ptr(1,0,6,4,2,3));
828 const multi_arr<long,6,ARPA_TYPE,false>* carr = &arr;
830 CHECK_EQUAL(462013,*p);
831 const long& q = (*carr)[7][5][6][3][2][1];
832 CHECK_EQUAL(756321,q);
833 }
834
835 // check whether out-of-bounds access is detected
836 // create two exceptions for each dimension,
837 // just below and above the valid range
838 TEST_FIXTURE(LongInt2DFixture,Test2DAtOutOfBounds)
839 {
840 CHECK_THROW(arr.at(m1,1),out_of_range);
841 CHECK_THROW(arr.at(10,1),out_of_range);
842 CHECK_THROW(arr.at(7,m1),out_of_range);
843 CHECK_THROW(arr.at(7,9),out_of_range);
844 const multi_arr<long,2,ARPA_TYPE,false>* carr = &arr;
845 CHECK_THROW(carr->at(m1,1),out_of_range);
846 CHECK_THROW(carr->at(10,1),out_of_range);
847 CHECK_THROW(carr->at(7,m1),out_of_range);
848 CHECK_THROW(carr->at(7,9),out_of_range);
849 }
850 TEST_FIXTURE(LongInt3DFixture,Test3DAtOutOfBounds)
851 {
852 CHECK_THROW(arr.at(m1,1,2),out_of_range);
853 CHECK_THROW(arr.at(10,1,2),out_of_range);
854 CHECK_THROW(arr.at(7,m1,3),out_of_range);
855 CHECK_THROW(arr.at(7,9,3),out_of_range);
856 CHECK_THROW(arr.at(7,3,m1),out_of_range);
857 CHECK_THROW(arr.at(7,3,8),out_of_range);
858 const multi_arr<long,3,ARPA_TYPE,false>* carr = &arr;
859 CHECK_THROW(carr->at(m1,1,2),out_of_range);
860 CHECK_THROW(carr->at(10,1,2),out_of_range);
861 CHECK_THROW(carr->at(7,m1,3),out_of_range);
862 CHECK_THROW(carr->at(7,9,3),out_of_range);
863 CHECK_THROW(carr->at(7,3,m1),out_of_range);
864 CHECK_THROW(carr->at(7,3,8),out_of_range);
865 }
866 TEST_FIXTURE(LongInt4DFixture,Test4DAtOutOfBounds)
867 {
868 CHECK_THROW(arr.at(m1,1,2,3),out_of_range);
869 CHECK_THROW(arr.at(10,1,2,3),out_of_range);
870 CHECK_THROW(arr.at(7,m1,3,2),out_of_range);
871 CHECK_THROW(arr.at(7,9,3,2),out_of_range);
872 CHECK_THROW(arr.at(7,3,m1,1),out_of_range);
873 CHECK_THROW(arr.at(7,3,8,1),out_of_range);
874 CHECK_THROW(arr.at(7,3,1,m1),out_of_range);
875 CHECK_THROW(arr.at(7,3,1,7),out_of_range);
876 const multi_arr<long,4,ARPA_TYPE,false>* carr = &arr;
877 CHECK_THROW(carr->at(m1,1,2,3),out_of_range);
878 CHECK_THROW(carr->at(10,1,2,3),out_of_range);
879 CHECK_THROW(carr->at(7,m1,3,2),out_of_range);
880 CHECK_THROW(carr->at(7,9,3,2),out_of_range);
881 CHECK_THROW(carr->at(7,3,m1,1),out_of_range);
882 CHECK_THROW(carr->at(7,3,8,1),out_of_range);
883 CHECK_THROW(carr->at(7,3,1,m1),out_of_range);
884 CHECK_THROW(carr->at(7,3,1,7),out_of_range);
885 }
886 TEST_FIXTURE(LongInt5DFixture,Test5DAtOutOfBounds)
887 {
888 CHECK_THROW(arr.at(m1,1,2,3,4),out_of_range);
889 CHECK_THROW(arr.at(10,1,2,3,4),out_of_range);
890 CHECK_THROW(arr.at(7,m1,3,2,4),out_of_range);
891 CHECK_THROW(arr.at(7,9,3,2,4),out_of_range);
892 CHECK_THROW(arr.at(7,3,m1,1,0),out_of_range);
893 CHECK_THROW(arr.at(7,3,8,1,0),out_of_range);
894 CHECK_THROW(arr.at(7,3,1,m1,2),out_of_range);
895 CHECK_THROW(arr.at(7,3,1,7,2),out_of_range);
896 CHECK_THROW(arr.at(7,3,1,2,m1),out_of_range);
897 CHECK_THROW(arr.at(7,3,1,2,6),out_of_range);
898 const multi_arr<long,5,ARPA_TYPE,false>* carr = &arr;
899 CHECK_THROW(carr->at(m1,1,2,3,4),out_of_range);
900 CHECK_THROW(carr->at(10,1,2,3,4),out_of_range);
901 CHECK_THROW(carr->at(7,m1,3,2,4),out_of_range);
902 CHECK_THROW(carr->at(7,9,3,2,4),out_of_range);
903 CHECK_THROW(carr->at(7,3,m1,1,0),out_of_range);
904 CHECK_THROW(carr->at(7,3,8,1,0),out_of_range);
905 CHECK_THROW(carr->at(7,3,1,m1,2),out_of_range);
906 CHECK_THROW(carr->at(7,3,1,7,2),out_of_range);
907 CHECK_THROW(carr->at(7,3,1,2,m1),out_of_range);
908 CHECK_THROW(carr->at(7,3,1,2,6),out_of_range);
909 }
910 TEST_FIXTURE(LongInt6DFixture,Test6DAtOutOfBounds)
911 {
912 CHECK_THROW(arr.at(m1,1,2,3,4,0),out_of_range);
913 CHECK_THROW(arr.at(10,1,2,3,4,0),out_of_range);
914 CHECK_THROW(arr.at(7,m1,3,2,4,1),out_of_range);
915 CHECK_THROW(arr.at(7,9,3,2,4,1),out_of_range);
916 CHECK_THROW(arr.at(7,3,m1,1,0,2),out_of_range);
917 CHECK_THROW(arr.at(7,3,8,1,0,2),out_of_range);
918 CHECK_THROW(arr.at(7,3,1,m1,2,0),out_of_range);
919 CHECK_THROW(arr.at(7,3,1,7,2,0),out_of_range);
920 CHECK_THROW(arr.at(7,4,1,2,m1,3),out_of_range);
921 CHECK_THROW(arr.at(7,4,1,2,6,3),out_of_range);
922 CHECK_THROW(arr.at(7,4,1,2,3,m1),out_of_range);
923 CHECK_THROW(arr.at(7,4,1,2,3,5),out_of_range);
924 const multi_arr<long,6,ARPA_TYPE,false>* carr = &arr;
925 CHECK_THROW(carr->at(m1,1,2,3,4,0),out_of_range);
926 CHECK_THROW(carr->at(10,1,2,3,4,0),out_of_range);
927 CHECK_THROW(carr->at(7,m1,3,2,4,1),out_of_range);
928 CHECK_THROW(carr->at(7,9,3,2,4,1),out_of_range);
929 CHECK_THROW(carr->at(7,3,m1,1,0,2),out_of_range);
930 CHECK_THROW(carr->at(7,3,8,1,0,2),out_of_range);
931 CHECK_THROW(carr->at(7,3,1,m1,2,0),out_of_range);
932 CHECK_THROW(carr->at(7,3,1,7,2,0),out_of_range);
933 CHECK_THROW(carr->at(7,4,1,2,m1,3),out_of_range);
934 CHECK_THROW(carr->at(7,4,1,2,6,3),out_of_range);
935 CHECK_THROW(carr->at(7,4,1,2,3,m1),out_of_range);
936 CHECK_THROW(carr->at(7,4,1,2,3,5),out_of_range);
937 }
938
939 TEST_FIXTURE(LongInt2DFixtureBC,Test2DOutOfBounds)
940 {
941 CHECK_THROW(arr[m1][1],out_of_range);
942 CHECK_THROW(arr[10][1],out_of_range);
943 CHECK_THROW(arr[7][m1],out_of_range);
944 CHECK_THROW(arr[7][9],out_of_range);
945 CHECK_THROW(arr.ptr(m1,1),out_of_range);
946 CHECK_THROW(arr.ptr(10,1),out_of_range);
947 const multi_arr<long,2,ARPA_TYPE,true>* carr = &arr;
948 CHECK_THROW((*carr)[m1][1],out_of_range);
949 CHECK_THROW((*carr)[10][1],out_of_range);
950 CHECK_THROW((*carr)[7][m1],out_of_range);
951 CHECK_THROW((*carr)[7][9],out_of_range);
952 }
953 TEST_FIXTURE(LongInt3DFixtureBC,Test3DOutOfBounds)
954 {
955 CHECK_THROW(arr[m1][1][2],out_of_range);
956 CHECK_THROW(arr[10][1][2],out_of_range);
957 CHECK_THROW(arr[7][m1][3],out_of_range);
958 CHECK_THROW(arr[7][9][3],out_of_range);
959 CHECK_THROW(arr[7][3][m1],out_of_range);
960 CHECK_THROW(arr[7][3][8],out_of_range);
961 CHECK_THROW(arr.ptr(m1,1,2),out_of_range);
962 CHECK_THROW(arr.ptr(10,1,2),out_of_range);
963 CHECK_THROW(arr.ptr(7,m1,3),out_of_range);
964 CHECK_THROW(arr.ptr(7,9,3),out_of_range);
965 const multi_arr<long,3,ARPA_TYPE,true>* carr = &arr;
966 CHECK_THROW((*carr)[m1][1][2],out_of_range);
967 CHECK_THROW((*carr)[10][1][2],out_of_range);
968 CHECK_THROW((*carr)[7][m1][3],out_of_range);
969 CHECK_THROW((*carr)[7][9][3],out_of_range);
970 CHECK_THROW((*carr)[7][3][m1],out_of_range);
971 CHECK_THROW((*carr)[7][3][8],out_of_range);
972 }
973 TEST_FIXTURE(LongInt4DFixtureBC,Test4DOutOfBounds)
974 {
975 CHECK_THROW(arr[m1][1][2][3],out_of_range);
976 CHECK_THROW(arr[10][1][2][3],out_of_range);
977 CHECK_THROW(arr[7][m1][3][2],out_of_range);
978 CHECK_THROW(arr[7][9][3][2],out_of_range);
979 CHECK_THROW(arr[7][3][m1][1],out_of_range);
980 CHECK_THROW(arr[7][3][8][1],out_of_range);
981 CHECK_THROW(arr[7][3][1][m1],out_of_range);
982 CHECK_THROW(arr[7][3][1][7],out_of_range);
983 CHECK_THROW(arr.ptr(m1,1,2,3),out_of_range);
984 CHECK_THROW(arr.ptr(10,1,2,3),out_of_range);
985 CHECK_THROW(arr.ptr(7,m1,3,2),out_of_range);
986 CHECK_THROW(arr.ptr(7,9,3,2),out_of_range);
987 CHECK_THROW(arr.ptr(7,3,m1,1),out_of_range);
988 CHECK_THROW(arr.ptr(7,3,8,1),out_of_range);
989 const multi_arr<long,4,ARPA_TYPE,true>* carr = &arr;
990 CHECK_THROW((*carr)[m1][1][2][3],out_of_range);
991 CHECK_THROW((*carr)[10][1][2][3],out_of_range);
992 CHECK_THROW((*carr)[7][m1][3][2],out_of_range);
993 CHECK_THROW((*carr)[7][9][3][2],out_of_range);
994 CHECK_THROW((*carr)[7][3][m1][1],out_of_range);
995 CHECK_THROW((*carr)[7][3][8][1],out_of_range);
996 CHECK_THROW((*carr)[7][3][1][m1],out_of_range);
997 CHECK_THROW((*carr)[7][3][1][7],out_of_range);
998 }
999 TEST_FIXTURE(LongInt5DFixtureBC,Test5DOutOfBounds)
1000 {
1001 CHECK_THROW(arr[m1][1][2][3][4],out_of_range);
1002 CHECK_THROW(arr[10][1][2][3][4],out_of_range);
1003 CHECK_THROW(arr[7][m1][3][2][4],out_of_range);
1004 CHECK_THROW(arr[7][9][3][2][4],out_of_range);
1005 CHECK_THROW(arr[7][3][m1][1][0],out_of_range);
1006 CHECK_THROW(arr[7][3][8][1][0],out_of_range);
1007 CHECK_THROW(arr[7][3][1][m1][2],out_of_range);
1008 CHECK_THROW(arr[7][3][1][7][2],out_of_range);
1009 CHECK_THROW(arr[7][3][1][2][m1],out_of_range);
1010 CHECK_THROW(arr[7][3][1][2][6],out_of_range);
1011 CHECK_THROW(arr.ptr(m1,1,2,3,4),out_of_range);
1012 CHECK_THROW(arr.ptr(10,1,2,3,4),out_of_range);
1013 CHECK_THROW(arr.ptr(7,m1,3,2,4),out_of_range);
1014 CHECK_THROW(arr.ptr(7,9,3,2,4),out_of_range);
1015 CHECK_THROW(arr.ptr(7,3,m1,1,0),out_of_range);
1016 CHECK_THROW(arr.ptr(7,3,8,1,0),out_of_range);
1017 CHECK_THROW(arr.ptr(7,3,1,m1,2),out_of_range);
1018 CHECK_THROW(arr.ptr(7,3,1,7,2),out_of_range);
1019 const multi_arr<long,5,ARPA_TYPE,true>* carr = &arr;
1020 CHECK_THROW((*carr)[m1][1][2][3][4],out_of_range);
1021 CHECK_THROW((*carr)[10][1][2][3][4],out_of_range);
1022 CHECK_THROW((*carr)[7][m1][3][2][4],out_of_range);
1023 CHECK_THROW((*carr)[7][9][3][2][4],out_of_range);
1024 CHECK_THROW((*carr)[7][3][m1][1][0],out_of_range);
1025 CHECK_THROW((*carr)[7][3][8][1][0],out_of_range);
1026 CHECK_THROW((*carr)[7][3][1][m1][2],out_of_range);
1027 CHECK_THROW((*carr)[7][3][1][7][2],out_of_range);
1028 CHECK_THROW((*carr)[7][3][1][2][m1],out_of_range);
1029 CHECK_THROW((*carr)[7][3][1][2][6],out_of_range);
1030 }
1031 TEST_FIXTURE(LongInt6DFixtureBC,Test6DOutOfBounds)
1032 {
1033 CHECK_THROW(arr[m1][1][2][3][4][0],out_of_range);
1034 CHECK_THROW(arr[10][1][2][3][4][0],out_of_range);
1035 CHECK_THROW(arr[7][m1][3][2][4][1],out_of_range);
1036 CHECK_THROW(arr[7][9][3][2][4][1],out_of_range);
1037 CHECK_THROW(arr[7][3][m1][1][0][2],out_of_range);
1038 CHECK_THROW(arr[7][3][8][1][0][2],out_of_range);
1039 CHECK_THROW(arr[7][3][1][m1][2][0],out_of_range);
1040 CHECK_THROW(arr[7][3][1][7][2][0],out_of_range);
1041 CHECK_THROW(arr[7][4][1][2][m1][3],out_of_range);
1042 CHECK_THROW(arr[7][4][1][2][6][3],out_of_range);
1043 CHECK_THROW(arr[7][4][1][2][3][m1],out_of_range);
1044 CHECK_THROW(arr[7][4][1][2][3][5],out_of_range);
1045 CHECK_THROW(arr.ptr(m1,1,2,3,4,0),out_of_range);
1046 CHECK_THROW(arr.ptr(10,1,2,3,4,0),out_of_range);
1047 CHECK_THROW(arr.ptr(7,m1,3,2,4,1),out_of_range);
1048 CHECK_THROW(arr.ptr(7,9,3,2,4,1),out_of_range);
1049 CHECK_THROW(arr.ptr(7,3,m1,1,0,2),out_of_range);
1050 CHECK_THROW(arr.ptr(7,3,8,1,0,2),out_of_range);
1051 CHECK_THROW(arr.ptr(7,3,1,m1,2,0),out_of_range);
1052 CHECK_THROW(arr.ptr(7,3,1,7,2,0),out_of_range);
1053 CHECK_THROW(arr.ptr(7,4,1,2,m1,3),out_of_range);
1054 CHECK_THROW(arr.ptr(7,4,1,2,6,3),out_of_range);
1055 const multi_arr<long,6,ARPA_TYPE,true>* carr = &arr;
1056 CHECK_THROW((*carr)[m1][1][2][3][4][0],out_of_range);
1057 CHECK_THROW((*carr)[10][1][2][3][4][0],out_of_range);
1058 CHECK_THROW((*carr)[7][m1][3][2][4][1],out_of_range);
1059 CHECK_THROW((*carr)[7][9][3][2][4][1],out_of_range);
1060 CHECK_THROW((*carr)[7][3][m1][1][0][2],out_of_range);
1061 CHECK_THROW((*carr)[7][3][8][1][0][2],out_of_range);
1062 CHECK_THROW((*carr)[7][3][1][m1][2][0],out_of_range);
1063 CHECK_THROW((*carr)[7][3][1][7][2][0],out_of_range);
1064 CHECK_THROW((*carr)[7][4][1][2][m1][3],out_of_range);
1065 CHECK_THROW((*carr)[7][4][1][2][6][3],out_of_range);
1066 CHECK_THROW((*carr)[7][4][1][2][3][m1],out_of_range);
1067 CHECK_THROW((*carr)[7][4][1][2][3][5],out_of_range);
1068 }
1069
1070 // now repeat access and out-of-bounds tests for C_TYPE arrays
1071 TEST_FIXTURE(LongInt2DFixtureCType,Test2DIndexedValueCType)
1072 {
1073 CHECK_EQUAL(98,arr[9][8]);
1074 CHECK_EQUAL(37,*arr.ptr(3,7));
1075 const multi_arr<long,2,C_TYPE,false>* carr = &arr;
1077 CHECK_EQUAL(46,*p);
1078 const long& q = (*carr)[7][5];
1079 CHECK_EQUAL(75,q);
1080 }
1081 TEST_FIXTURE(LongInt3DFixtureCType,Test3DIndexedValueCType)
1082 {
1083 CHECK_EQUAL(987,arr[9][8][7]);
1084 CHECK_EQUAL(137,*arr.ptr(1,3,7));
1085 const multi_arr<long,3,C_TYPE,false>* carr = &arr;
1087 CHECK_EQUAL(462,*p);
1088 const long& q = (*carr)[7][5][6];
1089 CHECK_EQUAL(756,q);
1090 }
1091 TEST_FIXTURE(LongInt4DFixtureCType,Test4DIndexedValueCType)
1092 {
1093 CHECK_EQUAL(9876,arr[9][8][7][6]);
1094 CHECK_EQUAL(1342,*arr.ptr(1,3,4,2));
1095 const multi_arr<long,4,C_TYPE,false>* carr = &arr;
1097 CHECK_EQUAL(4620,*p);
1098 const long& q = (*carr)[7][5][6][3];
1099 CHECK_EQUAL(7563,q);
1100 }
1101 TEST_FIXTURE(LongInt5DFixtureCType,Test5DIndexedValueCType)
1102 {
1103 CHECK_EQUAL(98765,arr[9][8][7][6][5]);
1104 CHECK_EQUAL(10342,*arr.ptr(1,0,3,4,2));
1105 const multi_arr<long,5,C_TYPE,false>* carr = &arr;
1107 CHECK_EQUAL(46201,*p);
1108 const long& q = (*carr)[7][5][6][3][2];
1109 CHECK_EQUAL(75632,q);
1110 }
1111 TEST_FIXTURE(LongInt6DFixtureCType,Test6DIndexedValueCType)
1112 {
1113 CHECK_EQUAL(987654,arr[9][8][7][6][5][4]);
1114 CHECK_EQUAL(106423,*arr.ptr(1,0,6,4,2,3));
1115 const multi_arr<long,6,C_TYPE,false>* carr = &arr;
1117 CHECK_EQUAL(462013,*p);
1118 const long& q = (*carr)[7][5][6][3][2][1];
1119 CHECK_EQUAL(756321,q);
1120 }
1121
1122 TEST_FIXTURE(LongInt2DFixtureCType,Test2DAtOutOfBoundsCType)
1123 {
1124 CHECK_THROW(arr.at(m1,1),out_of_range);
1125 CHECK_THROW(arr.at(10,1),out_of_range);
1126 CHECK_THROW(arr.at(7,m1),out_of_range);
1127 CHECK_THROW(arr.at(7,9),out_of_range);
1128 const multi_arr<long,2,C_TYPE,false>* carr = &arr;
1129 CHECK_THROW(carr->at(m1,1),out_of_range);
1130 CHECK_THROW(carr->at(10,1),out_of_range);
1131 CHECK_THROW(carr->at(7,m1),out_of_range);
1132 CHECK_THROW(carr->at(7,9),out_of_range);
1133 }
1134 TEST_FIXTURE(LongInt3DFixtureCType,Test3DAtOutOfBoundsCType)
1135 {
1136 CHECK_THROW(arr.at(m1,1,2),out_of_range);
1137 CHECK_THROW(arr.at(10,1,2),out_of_range);
1138 CHECK_THROW(arr.at(7,m1,3),out_of_range);
1139 CHECK_THROW(arr.at(7,9,3),out_of_range);
1140 CHECK_THROW(arr.at(7,3,m1),out_of_range);
1141 CHECK_THROW(arr.at(7,3,8),out_of_range);
1142 const multi_arr<long,3,C_TYPE,false>* carr = &arr;
1143 CHECK_THROW(carr->at(m1,1,2),out_of_range);
1144 CHECK_THROW(carr->at(10,1,2),out_of_range);
1145 CHECK_THROW(carr->at(7,m1,3),out_of_range);
1146 CHECK_THROW(carr->at(7,9,3),out_of_range);
1147 CHECK_THROW(carr->at(7,3,m1),out_of_range);
1148 CHECK_THROW(carr->at(7,3,8),out_of_range);
1149 }
1150 TEST_FIXTURE(LongInt4DFixtureCType,Test4DAtOutOfBoundsCType)
1151 {
1152 CHECK_THROW(arr.at(m1,1,2,3),out_of_range);
1153 CHECK_THROW(arr.at(10,1,2,3),out_of_range);
1154 CHECK_THROW(arr.at(7,m1,3,2),out_of_range);
1155 CHECK_THROW(arr.at(7,9,3,2),out_of_range);
1156 CHECK_THROW(arr.at(7,3,m1,1),out_of_range);
1157 CHECK_THROW(arr.at(7,3,8,1),out_of_range);
1158 CHECK_THROW(arr.at(7,3,1,m1),out_of_range);
1159 CHECK_THROW(arr.at(7,3,1,7),out_of_range);
1160 const multi_arr<long,4,C_TYPE,false>* carr = &arr;
1161 CHECK_THROW(carr->at(m1,1,2,3),out_of_range);
1162 CHECK_THROW(carr->at(10,1,2,3),out_of_range);
1163 CHECK_THROW(carr->at(7,m1,3,2),out_of_range);
1164 CHECK_THROW(carr->at(7,9,3,2),out_of_range);
1165 CHECK_THROW(carr->at(7,3,m1,1),out_of_range);
1166 CHECK_THROW(carr->at(7,3,8,1),out_of_range);
1167 CHECK_THROW(carr->at(7,3,1,m1),out_of_range);
1168 CHECK_THROW(carr->at(7,3,1,7),out_of_range);
1169 }
1170 TEST_FIXTURE(LongInt5DFixtureCType,Test5DAtOutOfBoundsCType)
1171 {
1172 CHECK_THROW(arr.at(m1,1,2,3,4),out_of_range);
1173 CHECK_THROW(arr.at(10,1,2,3,4),out_of_range);
1174 CHECK_THROW(arr.at(7,m1,3,2,4),out_of_range);
1175 CHECK_THROW(arr.at(7,9,3,2,4),out_of_range);
1176 CHECK_THROW(arr.at(7,3,m1,1,0),out_of_range);
1177 CHECK_THROW(arr.at(7,3,8,1,0),out_of_range);
1178 CHECK_THROW(arr.at(7,3,1,m1,2),out_of_range);
1179 CHECK_THROW(arr.at(7,3,1,7,2),out_of_range);
1180 CHECK_THROW(arr.at(7,3,1,2,m1),out_of_range);
1181 CHECK_THROW(arr.at(7,3,1,2,6),out_of_range);
1182 const multi_arr<long,5,C_TYPE,false>* carr = &arr;
1183 CHECK_THROW(carr->at(m1,1,2,3,4),out_of_range);
1184 CHECK_THROW(carr->at(10,1,2,3,4),out_of_range);
1185 CHECK_THROW(carr->at(7,m1,3,2,4),out_of_range);
1186 CHECK_THROW(carr->at(7,9,3,2,4),out_of_range);
1187 CHECK_THROW(carr->at(7,3,m1,1,0),out_of_range);
1188 CHECK_THROW(carr->at(7,3,8,1,0),out_of_range);
1189 CHECK_THROW(carr->at(7,3,1,m1,2),out_of_range);
1190 CHECK_THROW(carr->at(7,3,1,7,2),out_of_range);
1191 CHECK_THROW(carr->at(7,3,1,2,m1),out_of_range);
1192 CHECK_THROW(carr->at(7,3,1,2,6),out_of_range);
1193 }
1194 TEST_FIXTURE(LongInt6DFixtureCType,Test6DAtOutOfBoundsCType)
1195 {
1196 CHECK_THROW(arr.at(m1,1,2,3,4,0),out_of_range);
1197 CHECK_THROW(arr.at(10,1,2,3,4,0),out_of_range);
1198 CHECK_THROW(arr.at(7,m1,3,2,4,1),out_of_range);
1199 CHECK_THROW(arr.at(7,9,3,2,4,1),out_of_range);
1200 CHECK_THROW(arr.at(7,3,m1,1,0,2),out_of_range);
1201 CHECK_THROW(arr.at(7,3,8,1,0,2),out_of_range);
1202 CHECK_THROW(arr.at(7,3,1,m1,2,0),out_of_range);
1203 CHECK_THROW(arr.at(7,3,1,7,2,0),out_of_range);
1204 CHECK_THROW(arr.at(7,4,1,2,m1,3),out_of_range);
1205 CHECK_THROW(arr.at(7,4,1,2,6,3),out_of_range);
1206 CHECK_THROW(arr.at(7,4,1,2,3,m1),out_of_range);
1207 CHECK_THROW(arr.at(7,4,1,2,3,5),out_of_range);
1208 const multi_arr<long,6,C_TYPE,false>* carr = &arr;
1209 CHECK_THROW(carr->at(m1,1,2,3,4,0),out_of_range);
1210 CHECK_THROW(carr->at(10,1,2,3,4,0),out_of_range);
1211 CHECK_THROW(carr->at(7,m1,3,2,4,1),out_of_range);
1212 CHECK_THROW(carr->at(7,9,3,2,4,1),out_of_range);
1213 CHECK_THROW(carr->at(7,3,m1,1,0,2),out_of_range);
1214 CHECK_THROW(carr->at(7,3,8,1,0,2),out_of_range);
1215 CHECK_THROW(carr->at(7,3,1,m1,2,0),out_of_range);
1216 CHECK_THROW(carr->at(7,3,1,7,2,0),out_of_range);
1217 CHECK_THROW(carr->at(7,4,1,2,m1,3),out_of_range);
1218 CHECK_THROW(carr->at(7,4,1,2,6,3),out_of_range);
1219 CHECK_THROW(carr->at(7,4,1,2,3,m1),out_of_range);
1220 CHECK_THROW(carr->at(7,4,1,2,3,5),out_of_range);
1221 }
1222
1223 TEST_FIXTURE(LongInt2DFixtureCTypeBC,Test2DOutOfBoundsCType)
1224 {
1225 CHECK_THROW(arr[m1][1],out_of_range);
1226 CHECK_THROW(arr[10][1],out_of_range);
1227 CHECK_THROW(arr[7][m1],out_of_range);
1228 CHECK_THROW(arr[7][9],out_of_range);
1229 CHECK_THROW(arr.ptr(m1,1),out_of_range);
1230 CHECK_THROW(arr.ptr(10,1),out_of_range);
1231 const multi_arr<long,2,C_TYPE,true>* carr = &arr;
1232 CHECK_THROW((*carr)[m1][1],out_of_range);
1233 CHECK_THROW((*carr)[10][1],out_of_range);
1234 CHECK_THROW((*carr)[7][m1],out_of_range);
1235 CHECK_THROW((*carr)[7][9],out_of_range);
1236 }
1237 TEST_FIXTURE(LongInt3DFixtureCTypeBC,Test3DOutOfBoundsCType)
1238 {
1239 CHECK_THROW(arr[m1][1][2],out_of_range);
1240 CHECK_THROW(arr[10][1][2],out_of_range);
1241 CHECK_THROW(arr[7][m1][3],out_of_range);
1242 CHECK_THROW(arr[7][9][3],out_of_range);
1243 CHECK_THROW(arr[7][3][m1],out_of_range);
1244 CHECK_THROW(arr[7][3][8],out_of_range);
1245 CHECK_THROW(arr.ptr(m1,1,2),out_of_range);
1246 CHECK_THROW(arr.ptr(10,1,2),out_of_range);
1247 CHECK_THROW(arr.ptr(7,m1,3),out_of_range);
1248 CHECK_THROW(arr.ptr(7,9,3),out_of_range);
1249 const multi_arr<long,3,C_TYPE,true>* carr = &arr;
1250 CHECK_THROW((*carr)[m1][1][2],out_of_range);
1251 CHECK_THROW((*carr)[10][1][2],out_of_range);
1252 CHECK_THROW((*carr)[7][m1][3],out_of_range);
1253 CHECK_THROW((*carr)[7][9][3],out_of_range);
1254 CHECK_THROW((*carr)[7][3][m1],out_of_range);
1255 CHECK_THROW((*carr)[7][3][8],out_of_range);
1256 }
1257 TEST_FIXTURE(LongInt4DFixtureCTypeBC,Test4DOutOfBoundsCType)
1258 {
1259 CHECK_THROW(arr[m1][1][2][3],out_of_range);
1260 CHECK_THROW(arr[10][1][2][3],out_of_range);
1261 CHECK_THROW(arr[7][m1][3][2],out_of_range);
1262 CHECK_THROW(arr[7][9][3][2],out_of_range);
1263 CHECK_THROW(arr[7][3][m1][1],out_of_range);
1264 CHECK_THROW(arr[7][3][8][1],out_of_range);
1265 CHECK_THROW(arr[7][3][1][m1],out_of_range);
1266 CHECK_THROW(arr[7][3][1][7],out_of_range);
1267 CHECK_THROW(arr.ptr(m1,1,2,3),out_of_range);
1268 CHECK_THROW(arr.ptr(10,1,2,3),out_of_range);
1269 CHECK_THROW(arr.ptr(7,m1,3,2),out_of_range);
1270 CHECK_THROW(arr.ptr(7,9,3,2),out_of_range);
1271 CHECK_THROW(arr.ptr(7,3,m1,1),out_of_range);
1272 CHECK_THROW(arr.ptr(7,3,8,1),out_of_range);
1273 const multi_arr<long,4,C_TYPE,true>* carr = &arr;
1274 CHECK_THROW((*carr)[m1][1][2][3],out_of_range);
1275 CHECK_THROW((*carr)[10][1][2][3],out_of_range);
1276 CHECK_THROW((*carr)[7][m1][3][2],out_of_range);
1277 CHECK_THROW((*carr)[7][9][3][2],out_of_range);
1278 CHECK_THROW((*carr)[7][3][m1][1],out_of_range);
1279 CHECK_THROW((*carr)[7][3][8][1],out_of_range);
1280 CHECK_THROW((*carr)[7][3][1][m1],out_of_range);
1281 CHECK_THROW((*carr)[7][3][1][7],out_of_range);
1282 }
1283 TEST_FIXTURE(LongInt5DFixtureCTypeBC,Test5DOutOfBoundsCType)
1284 {
1285 CHECK_THROW(arr[m1][1][2][3][4],out_of_range);
1286 CHECK_THROW(arr[10][1][2][3][4],out_of_range);
1287 CHECK_THROW(arr[7][m1][3][2][4],out_of_range);
1288 CHECK_THROW(arr[7][9][3][2][4],out_of_range);
1289 CHECK_THROW(arr[7][3][m1][1][0],out_of_range);
1290 CHECK_THROW(arr[7][3][8][1][0],out_of_range);
1291 CHECK_THROW(arr[7][3][1][m1][2],out_of_range);
1292 CHECK_THROW(arr[7][3][1][7][2],out_of_range);
1293 CHECK_THROW(arr[7][3][1][2][m1],out_of_range);
1294 CHECK_THROW(arr[7][3][1][2][6],out_of_range);
1295 CHECK_THROW(arr.ptr(m1,1,2,3,4),out_of_range);
1296 CHECK_THROW(arr.ptr(10,1,2,3,4),out_of_range);
1297 CHECK_THROW(arr.ptr(7,m1,3,2,4),out_of_range);
1298 CHECK_THROW(arr.ptr(7,9,3,2,4),out_of_range);
1299 CHECK_THROW(arr.ptr(7,3,m1,1,0),out_of_range);
1300 CHECK_THROW(arr.ptr(7,3,8,1,0),out_of_range);
1301 CHECK_THROW(arr.ptr(7,3,1,m1,2),out_of_range);
1302 CHECK_THROW(arr.ptr(7,3,1,7,2),out_of_range);
1303 const multi_arr<long,5,C_TYPE,true>* carr = &arr;
1304 CHECK_THROW((*carr)[m1][1][2][3][4],out_of_range);
1305 CHECK_THROW((*carr)[10][1][2][3][4],out_of_range);
1306 CHECK_THROW((*carr)[7][m1][3][2][4],out_of_range);
1307 CHECK_THROW((*carr)[7][9][3][2][4],out_of_range);
1308 CHECK_THROW((*carr)[7][3][m1][1][0],out_of_range);
1309 CHECK_THROW((*carr)[7][3][8][1][0],out_of_range);
1310 CHECK_THROW((*carr)[7][3][1][m1][2],out_of_range);
1311 CHECK_THROW((*carr)[7][3][1][7][2],out_of_range);
1312 CHECK_THROW((*carr)[7][3][1][2][m1],out_of_range);
1313 CHECK_THROW((*carr)[7][3][1][2][6],out_of_range);
1314 }
1315 TEST_FIXTURE(LongInt6DFixtureCTypeBC,Test6DOutOfBoundsCType)
1316 {
1317 CHECK_THROW(arr[m1][1][2][3][4][0],out_of_range);
1318 CHECK_THROW(arr[10][1][2][3][4][0],out_of_range);
1319 CHECK_THROW(arr[7][m1][3][2][4][1],out_of_range);
1320 CHECK_THROW(arr[7][9][3][2][4][1],out_of_range);
1321 CHECK_THROW(arr[7][3][m1][1][0][2],out_of_range);
1322 CHECK_THROW(arr[7][3][8][1][0][2],out_of_range);
1323 CHECK_THROW(arr[7][3][1][m1][2][0],out_of_range);
1324 CHECK_THROW(arr[7][3][1][7][2][0],out_of_range);
1325 CHECK_THROW(arr[7][4][1][2][m1][3],out_of_range);
1326 CHECK_THROW(arr[7][4][1][2][6][3],out_of_range);
1327 CHECK_THROW(arr[7][4][1][2][3][m1],out_of_range);
1328 CHECK_THROW(arr[7][4][1][2][3][5],out_of_range);
1329 CHECK_THROW(arr.ptr(m1,1,2,3,4,0),out_of_range);
1330 CHECK_THROW(arr.ptr(10,1,2,3,4,0),out_of_range);
1331 CHECK_THROW(arr.ptr(7,m1,3,2,4,1),out_of_range);
1332 CHECK_THROW(arr.ptr(7,9,3,2,4,1),out_of_range);
1333 CHECK_THROW(arr.ptr(7,3,m1,1,0,2),out_of_range);
1334 CHECK_THROW(arr.ptr(7,3,8,1,0,2),out_of_range);
1335 CHECK_THROW(arr.ptr(7,3,1,m1,2,0),out_of_range);
1336 CHECK_THROW(arr.ptr(7,3,1,7,2,0),out_of_range);
1337 CHECK_THROW(arr.ptr(7,4,1,2,m1,3),out_of_range);
1338 CHECK_THROW(arr.ptr(7,4,1,2,6,3),out_of_range);
1339 const multi_arr<long,6,C_TYPE,true>* carr = &arr;
1340 CHECK_THROW((*carr)[m1][1][2][3][4][0],out_of_range);
1341 CHECK_THROW((*carr)[10][1][2][3][4][0],out_of_range);
1342 CHECK_THROW((*carr)[7][m1][3][2][4][1],out_of_range);
1343 CHECK_THROW((*carr)[7][9][3][2][4][1],out_of_range);
1344 CHECK_THROW((*carr)[7][3][m1][1][0][2],out_of_range);
1345 CHECK_THROW((*carr)[7][3][8][1][0][2],out_of_range);
1346 CHECK_THROW((*carr)[7][3][1][m1][2][0],out_of_range);
1347 CHECK_THROW((*carr)[7][3][1][7][2][0],out_of_range);
1348 CHECK_THROW((*carr)[7][4][1][2][m1][3],out_of_range);
1349 CHECK_THROW((*carr)[7][4][1][2][6][3],out_of_range);
1350 CHECK_THROW((*carr)[7][4][1][2][3][m1],out_of_range);
1351 CHECK_THROW((*carr)[7][4][1][2][3][5],out_of_range);
1352 }
1353
1354 // check whether the constructor is executed for multi_arr members
1355 // also checks whether indirection works for pntr and const_pntr
1356 TEST_FIXTURE(StructWithConstructor3DFixture,TestConstructorExecuted)
1357 {
1359 CHECK_EQUAL(23,p1->n);
1361 CHECK_EQUAL(23,p2->n);
1362 }
1363 TEST_FIXTURE(StructWithConstructor3DFixtureCType,TestConstructorExecutedCType)
1364 {
1366 CHECK_EQUAL(23,p1->n);
1368 CHECK_EQUAL(23,p2->n);
1369 }
1370
1371 // check whether the size(), capacity(), and empty() methods work correctly
1372 TEST_FIXTURE(LongInt3DFixtureBC,TestSize)
1373 {
1374 CHECK_EQUAL((size_t)(10*9*8),arr.size());
1375 arr.clear();
1376 CHECK(arr.empty());
1377 // check whether we can allocate a new array
1378 arr.alloc(10,11,12);
1379 CHECK_EQUAL((size_t)(10*11*12),arr.capacity());
1380 arr.zero();
1381 // check whether all the strides are properly set up
1382 // this is done through bounds checking
1383 // this also tests bounds checking const_iterator
1384 for (int i=0; i<10; ++i)
1385 for (int j=0; j<11; ++j)
1386 {
1388 for (int k=0; k<12; ++k)
1389 CHECK_EQUAL(0,p[k]);
1390 }
1391 }
1392
1393 // check whether the size(), capacity(), and empty() methods work correctly
1394 // and iterator is compatible with STL algorithms
1395 TEST_FIXTURE(LongInt3DFixtureBC,TestSizeAlgorithm)
1396 {
1397 arr.clear();
1398 arr.alloc(10,11,12);
1399 arr.zero();
1400
1401 for (int i=0; i<10; ++i)
1402 for (int j=0; j<11; ++j)
1403 {
1404 CHECK_EQUAL(0,count_if(arr.begin(i,j),arr.end(i,j),
1405 bind1st(not_equal_to<long>(),0)));
1406 }
1407 }
1408
1409 TEST_FIXTURE(LongInt3DFixtureCTypeBC,TestSizeCType)
1410 {
1411 CHECK_EQUAL((size_t)(10*9*8),arr.size());
1412 arr.clear();
1413 CHECK(arr.empty());
1414 // check whether we can allocate a new array
1415 arr.alloc(10,11,12);
1416 CHECK_EQUAL((size_t)(10*11*12),arr.capacity());
1417 arr.zero();
1418 // check whether all the strides are properly set up
1419 // this is done through bounds checking
1420 // this also tests bounds checking const_iterator
1421 for (int i=0; i<10; ++i)
1422 for (int j=0; j<11; ++j)
1423 {
1425 for (int k=0; k<12; ++k)
1426 CHECK_EQUAL(0,p[k]);
1427 }
1428 }
1429
1430 // check whether explicit space reservation works
1431 TEST_FIXTURE(LongInt6DFixtureExplicitReserve,TestExplicitReserve)
1432 {
1433 arr.zero();
1434 for (int i=0; i<10; ++i)
1435 for (int j=0; j<9; ++j)
1436 for (int k=0; k<8; ++k)
1437 for (int l=0; l<7; ++l)
1438 for (int m=0; m<6; ++m)
1439 for (int n=0; n<5; ++n)
1440 CHECK_EQUAL(0,arr[i][j][k][l][m][n]);
1441 // it is not safe to call reserve without clearing first
1442 CHECK_THROW(arr.reserve(2),bad_assert);
1443 }
1444
1445 // check whether the variant form for allocating works correctly
1446 // this also tests p_iterator in bounds-checking mode
1447 TEST_FIXTURE(TestAllocFixture,TestVariantAlloc)
1448 {
1449 CHECK_EQUAL(0,mytest());
1450 }
1451
1452 // check whether the data() method yields valid pointer
1453 // for both ARPA_TYPE and C_TYPE arrays
1454 TEST_FIXTURE(LongInt3DFixture,TestData)
1455 {
1456 CHECK_EQUAL(&arr[0][0][0],arr.data());
1457 arr[0][0][0] = 1234;
1458 CHECK_EQUAL(1234,*arr.data());
1459 const multi_arr<long,3,ARPA_TYPE,false>* carr = &arr;
1460 CHECK_EQUAL(&arr[0][0][0],carr->data());
1461 }
1462 TEST_FIXTURE(LongInt3DFixtureCType,TestDataCType)
1463 {
1464 CHECK_EQUAL(&arr[0][0][0],arr.data());
1465 arr[0][0][0] = 1234;
1466 CHECK_EQUAL(1234,*arr.data());
1467 const multi_arr<long,3,C_TYPE,false>* carr = &arr;
1468 CHECK_EQUAL(&arr[0][0][0],carr->data());
1469 }
1470
1471 TEST_FIXTURE(LongInt6DFixture,TestCopyOperator)
1472 {
1473 multi_arr<long,6,ARPA_TYPE,false> arr2(1,2,3,4,5,6);
1474 CHECK( arr.size() != arr2.size() );
1475 arr2.zero();
1476 CHECK_EQUAL(0,arr2[0][1][2][3][4][5]);
1477 arr2 = arr;
1478 CHECK( arr.size() == arr2.size() );
1479 // check that the copies are distinct
1480 CHECK( &arr[0][1][2][3][4][5] != &arr2[0][1][2][3][4][5] );
1481 for (int i=0; i<10; ++i)
1482 for (int j=0; j<9; ++j)
1483 for (int k=0; k<8; ++k)
1484 for (int l=0; l<7; ++l)
1485 for (int m=0; m<6; ++m)
1486 for (int n=0; n<5; ++n)
1487 {
1488 long z = i*100000+j*10000+k*1000+l*100+m*10+n;
1489 CHECK_EQUAL(z,arr2[i][j][k][l][m][n]);
1490 }
1491
1492 // is it safe to copy to oneself?
1493 arr2 = arr2;
1494 // have the contents been preserved?
1495 CHECK_EQUAL(712344,arr2[7][1][2][3][4][4]);
1496
1497 // now copy using the constructor
1499 CHECK( arr.size() == arr3.size() );
1500 // check that the copies are distinct
1501 CHECK( &arr[7][1][2][3][4][4] != &arr3[7][1][2][3][4][4] );
1502 CHECK_EQUAL(arr[7][1][2][3][4][4],arr3[7][1][2][3][4][4]);
1503
1504 arr.clear();
1505 // copying an empty arr should clear arr2
1506 arr2 = arr;
1507 CHECK(arr2.empty());
1508 // also check the copy constructor
1510 CHECK(arr4.empty());
1511 }
1512
1513 TEST_FIXTURE(LongInt6DFixtureBC,TestCopyOperatorBC)
1514 {
1515 multi_arr<long,6,ARPA_TYPE,true> arr2(1,2,3,4,5,6);
1516 CHECK( arr.size() != arr2.size() );
1517 arr2.zero();
1518 CHECK_EQUAL(0,arr2[0][1][2][3][4][5]);
1519 arr2 = arr;
1520 CHECK( arr.size() == arr2.size() );
1521 for (int i=0; i<10; ++i)
1522 for (int j=0; j<9; ++j)
1523 for (int k=0; k<8; ++k)
1524 for (int l=0; l<7; ++l)
1525 for (int m=0; m<6; ++m)
1526 for (int n=0; n<5; ++n)
1527 {
1528 long z = i*100000+j*10000+k*1000+l*100+m*10+n;
1529 CHECK_EQUAL(z,arr2[i][j][k][l][m][n]);
1530 }
1531
1532 CHECK_THROW(arr2[m1][1][2][3][4][0],out_of_range);
1533 CHECK_THROW(arr2[10][1][2][3][4][0],out_of_range);
1534 CHECK_THROW(arr2[7][m1][3][2][4][1],out_of_range);
1535 CHECK_THROW(arr2[7][9][3][2][4][1],out_of_range);
1536 CHECK_THROW(arr2[7][3][m1][1][0][2],out_of_range);
1537 CHECK_THROW(arr2[7][3][8][1][0][2],out_of_range);
1538 CHECK_THROW(arr2[7][3][1][m1][2][0],out_of_range);
1539 CHECK_THROW(arr2[7][3][1][7][2][0],out_of_range);
1540 CHECK_THROW(arr2[7][4][1][2][m1][3],out_of_range);
1541 CHECK_THROW(arr2[7][4][1][2][6][3],out_of_range);
1542 CHECK_THROW(arr2[7][4][1][2][3][m1],out_of_range);
1543 CHECK_THROW(arr2[7][4][1][2][3][5],out_of_range);
1544
1545 // is it safe to copy to oneself?
1546 arr2 = arr2;
1547 // have the contents been preserved?
1548 CHECK_EQUAL(712344,arr2[7][1][2][3][4][4]);
1549
1550 arr.clear();
1551 arr2 = arr;
1552 CHECK(arr2.empty());
1553 // also check the copy constructor
1555 CHECK(arr4.empty());
1556 }
1557
1558 TEST_FIXTURE(LongInt6DFixtureCType,TestCopyOperatorCType)
1559 {
1560 multi_arr<long,6,C_TYPE,false> arr2(1,2,3,4,5,6);
1561 CHECK( arr.size() != arr2.size() );
1562 arr2.zero();
1563 CHECK_EQUAL(0,arr2[0][1][2][3][4][5]);
1564 arr2 = arr;
1565 CHECK( arr.size() == arr2.size() );
1566 for (int i=0; i<10; ++i)
1567 for (int j=0; j<9; ++j)
1568 for (int k=0; k<8; ++k)
1569 for (int l=0; l<7; ++l)
1570 for (int m=0; m<6; ++m)
1571 for (int n=0; n<5; ++n)
1572 {
1573 long z = i*100000+j*10000+k*1000+l*100+m*10+n;
1574 CHECK_EQUAL(z,arr2[i][j][k][l][m][n]);
1575 }
1576
1577 // is it safe to copy to oneself?
1578 arr2 = arr2;
1579 // have the contents been preserved?
1580 CHECK_EQUAL(712344,arr2[7][1][2][3][4][4]);
1581
1582 arr.clear();
1583 arr2 = arr;
1584 CHECK(arr2.empty());
1585 // also check the copy constructor
1587 CHECK(arr4.empty());
1588 }
1589
1590 TEST_FIXTURE(LongInt6DFixtureCTypeBC,TestCopyOperatorCTypeBC)
1591 {
1592 multi_arr<long,6,C_TYPE,true> arr2(1,2,3,4,5,6);
1593 CHECK( arr.size() != arr2.size() );
1594 arr2.zero();
1595 CHECK_EQUAL(0,arr2[0][1][2][3][4][5]);
1596 arr2 = arr;
1597 CHECK( arr.size() == arr2.size() );
1598 for (int i=0; i<10; ++i)
1599 for (int j=0; j<9; ++j)
1600 for (int k=0; k<8; ++k)
1601 for (int l=0; l<7; ++l)
1602 for (int m=0; m<6; ++m)
1603 for (int n=0; n<5; ++n)
1604 {
1605 long z = i*100000+j*10000+k*1000+l*100+m*10+n;
1606 CHECK_EQUAL(z,arr2[i][j][k][l][m][n]);
1607 }
1608
1609 CHECK_THROW(arr2[m1][1][2][3][4][0],out_of_range);
1610 CHECK_THROW(arr2[10][1][2][3][4][0],out_of_range);
1611 CHECK_THROW(arr2[7][m1][3][2][4][1],out_of_range);
1612 CHECK_THROW(arr2[7][9][3][2][4][1],out_of_range);
1613 CHECK_THROW(arr2[7][3][m1][1][0][2],out_of_range);
1614 CHECK_THROW(arr2[7][3][8][1][0][2],out_of_range);
1615 CHECK_THROW(arr2[7][3][1][m1][2][0],out_of_range);
1616 CHECK_THROW(arr2[7][3][1][7][2][0],out_of_range);
1617 CHECK_THROW(arr2[7][4][1][2][m1][3],out_of_range);
1618 CHECK_THROW(arr2[7][4][1][2][6][3],out_of_range);
1619 CHECK_THROW(arr2[7][4][1][2][3][m1],out_of_range);
1620 CHECK_THROW(arr2[7][4][1][2][3][5],out_of_range);
1621
1622 // is it safe to copy to oneself?
1623 arr2 = arr2;
1624 // have the contents been preserved?
1625 CHECK_EQUAL(712344,arr2[7][1][2][3][4][4]);
1626
1627 arr.clear();
1628 arr2 = arr;
1629 CHECK(arr2.empty());
1630 // also check the copy constructor
1632 CHECK(arr4.empty());
1633 }
1634
1635 // check that C_TYPE actually has standard C layout
1636 TEST_FIXTURE(LongInt3DCLayoutFixture,TestCLayout)
1637 {
1638 CHECK_EQUAL(0L,mytest((long(*)[10][10])arr.data()));
1639 }
1640
1641 // test that the geometry of cloned arrays is OK
1642 TEST_FIXTURE(LongInt3DCloneFixture,TestCloning)
1643 {
1644 // the types of arr and dolly need not match!
1646 CHECK_THROW(dolly[10][0][0],out_of_range);
1647 for (int i=0; i<10; ++i)
1648 {
1649 CHECK_THROW(dolly[i][i+1][0],out_of_range);
1650 for (int j=0; j<i+1; ++j)
1651 CHECK_THROW(dolly[i][j][j+1],out_of_range);
1652 }
1653 // check that cloning and destroying an uninitialized multi_arr is safe
1656 CHECK(dolly2.empty());
1657 // check that cloning oneself is safe (not very useful though...)
1658 multi_arr<long,5,ARPA_TYPE,false> arr3(3,3,3,3,3);
1659 arr3.alloc( arr3.clone() );
1660 // check that the array was not cleared
1661 CHECK_EQUAL(243UL,arr3.size());
1662 }
1663
1664 // same as above, but for C_TYPE arrays
1665 TEST_FIXTURE(LongInt3DCloneFixtureCType,TestCloningCType)
1666 {
1667 // the types of arr and dolly need not match!
1668 multi_arr<bool,3,C_TYPE,true> dolly( arr.clone() );
1669 CHECK_THROW(dolly[10][0][0],out_of_range);
1670 for (int i=0; i<10; ++i)
1671 {
1672 CHECK_THROW(dolly[i][i+1][0],out_of_range);
1673 for (int j=0; j<i+1; ++j)
1674 CHECK_THROW(dolly[i][j][j+1],out_of_range);
1675 }
1676 // check that cloning and destroying an uninitialized multi_arr is safe
1678 multi_arr<bool,4,C_TYPE,false> dolly2( arr2.clone() );
1679 CHECK(dolly2.empty());
1680 // check that cloning oneself is safe (not very useful though...)
1681 multi_arr<long,5,ARPA_TYPE,false> arr3(3,3,3,3,3);
1682 arr3.alloc( arr3.clone() );
1683 // check that the array was not cleared
1684 CHECK_EQUAL(243UL,arr3.size());
1685 }
1686
1687 TEST_FIXTURE(LongInt2DFixture,Test2DBeginEnd)
1688 {
1689 CHECK( arr.begin(2) == arr.ptr(2,0) );
1690 CHECK( arr.end(2) == arr.ptr(2,9) );
1691 CHECK_EQUAL(20L,arr.front(2));
1692 CHECK_EQUAL(28L,arr.back(2));
1693 const multi_arr<long,2,ARPA_TYPE,false>* carr = &arr;
1694 CHECK( carr->begin(2) == carr->ptr(2,0) );
1695 CHECK( carr->end(2) == carr->ptr(2,9) );
1696 CHECK_EQUAL(20L,carr->front(2));
1697 CHECK_EQUAL(28L,carr->back(2));
1698 }
1699 TEST_FIXTURE(LongInt3DFixture,Test3DBeginEnd)
1700 {
1701 CHECK( arr.begin(2,4) == arr.ptr(2,4,0) );
1702 CHECK( arr.end(2,4) == arr.ptr(2,4,8) );
1703 CHECK_EQUAL(240L,arr.front(2,4));
1704 CHECK_EQUAL(247L,arr.back(2,4));
1705 const multi_arr<long,3,ARPA_TYPE,false>* carr = &arr;
1706 CHECK( carr->begin(2,4) == carr->ptr(2,4,0) );
1707 CHECK( carr->end(2,4) == carr->ptr(2,4,8) );
1708 CHECK_EQUAL(240L,carr->front(2,4));
1709 CHECK_EQUAL(247L,carr->back(2,4));
1710 }
1711 TEST_FIXTURE(LongInt4DFixture,Test4DBeginEnd)
1712 {
1713 CHECK( arr.begin(2,4,7) == arr.ptr(2,4,7,0) );
1714 CHECK( arr.end(2,4,7) == arr.ptr(2,4,7,7) );
1715 CHECK_EQUAL(2470L,arr.front(2,4,7));
1716 CHECK_EQUAL(2476L,arr.back(2,4,7));
1717 const multi_arr<long,4,ARPA_TYPE,false>* carr = &arr;
1718 CHECK( carr->begin(2,4,7) == carr->ptr(2,4,7,0) );
1719 CHECK( carr->end(2,4,7) == carr->ptr(2,4,7,7) );
1720 CHECK_EQUAL(2470L,carr->front(2,4,7));
1721 CHECK_EQUAL(2476L,carr->back(2,4,7));
1722 }
1723 TEST_FIXTURE(LongInt5DFixture,Test5DBeginEnd)
1724 {
1725 CHECK( arr.begin(2,4,7,5) == arr.ptr(2,4,7,5,0) );
1726 CHECK( arr.end(2,4,7,5) == arr.ptr(2,4,7,5,6) );
1727 CHECK_EQUAL(24750L,arr.front(2,4,7,5));
1728 CHECK_EQUAL(24755L,arr.back(2,4,7,5));
1729 const multi_arr<long,5,ARPA_TYPE,false>* carr = &arr;
1730 CHECK( carr->begin(2,4,7,5) == carr->ptr(2,4,7,5,0) );
1731 CHECK( carr->end(2,4,7,5) == carr->ptr(2,4,7,5,6) );
1732 CHECK_EQUAL(24750L,carr->front(2,4,7,5));
1733 CHECK_EQUAL(24755L,carr->back(2,4,7,5));
1734 }
1735 TEST_FIXTURE(LongInt6DFixture,Test6DBeginEnd)
1736 {
1737 CHECK( arr.begin(2,4,7,5,1) == arr.ptr(2,4,7,5,1,0) );
1738 CHECK( arr.end(2,4,7,5,1) == arr.ptr(2,4,7,5,1,5) );
1739 CHECK_EQUAL(247510L,arr.front(2,4,7,5,1));
1740 CHECK_EQUAL(247514L,arr.back(2,4,7,5,1));
1741 const multi_arr<long,6,ARPA_TYPE,false>* carr = &arr;
1742 CHECK( carr->begin(2,4,7,5,1) == carr->ptr(2,4,7,5,1,0) );
1743 CHECK( carr->end(2,4,7,5,1) == carr->ptr(2,4,7,5,1,5) );
1744 CHECK_EQUAL(247510L,carr->front(2,4,7,5,1));
1745 CHECK_EQUAL(247514L,carr->back(2,4,7,5,1));
1746 }
1747
1748 TEST_FIXTURE(LongInt2DFixtureCTypeBC,Test2DBeginEndCTypeBC)
1749 {
1750 CHECK( arr.begin(2) == arr.ptr(2,0) );
1751 CHECK( arr.end(2) == arr.ptr(2,9) );
1752 CHECK_EQUAL(20L,arr.front(2));
1753 CHECK_EQUAL(28L,arr.back(2));
1754 const multi_arr<long,2,C_TYPE,true>* carr = &arr;
1755 CHECK( carr->begin(2) == carr->ptr(2,0) );
1756 CHECK( carr->end(2) == carr->ptr(2,9) );
1757 CHECK_EQUAL(20L,carr->front(2));
1758 CHECK_EQUAL(28L,carr->back(2));
1759 }
1760 TEST_FIXTURE(LongInt3DFixtureCTypeBC,Test3DBeginEndCTypeBC)
1761 {
1762 CHECK( arr.begin(2,4) == arr.ptr(2,4,0) );
1763 CHECK( arr.end(2,4) == arr.ptr(2,4,8) );
1764 CHECK_EQUAL(240L,arr.front(2,4));
1765 CHECK_EQUAL(247L,arr.back(2,4));
1766 const multi_arr<long,3,C_TYPE,true>* carr = &arr;
1767 CHECK( carr->begin(2,4) == carr->ptr(2,4,0) );
1768 CHECK( carr->end(2,4) == carr->ptr(2,4,8) );
1769 CHECK_EQUAL(240L,carr->front(2,4));
1770 CHECK_EQUAL(247L,carr->back(2,4));
1771 }
1772 TEST_FIXTURE(LongInt4DFixtureCTypeBC,Test4DBeginEndCTypeBC)
1773 {
1774 CHECK( arr.begin(2,4,7) == arr.ptr(2,4,7,0) );
1775 CHECK( arr.end(2,4,7) == arr.ptr(2,4,7,7) );
1776 CHECK_EQUAL(2470L,arr.front(2,4,7));
1777 CHECK_EQUAL(2476L,arr.back(2,4,7));
1778 const multi_arr<long,4,C_TYPE,true>* carr = &arr;
1779 CHECK( carr->begin(2,4,7) == carr->ptr(2,4,7,0) );
1780 CHECK( carr->end(2,4,7) == carr->ptr(2,4,7,7) );
1781 CHECK_EQUAL(2470L,carr->front(2,4,7));
1782 CHECK_EQUAL(2476L,carr->back(2,4,7));
1783 }
1784 TEST_FIXTURE(LongInt5DFixtureCTypeBC,Test5DBeginEndCTypeBC)
1785 {
1786 CHECK( arr.begin(2,4,7,5) == arr.ptr(2,4,7,5,0) );
1787 CHECK( arr.end(2,4,7,5) == arr.ptr(2,4,7,5,6) );
1788 CHECK_EQUAL(24750L,arr.front(2,4,7,5));
1789 CHECK_EQUAL(24755L,arr.back(2,4,7,5));
1790 const multi_arr<long,5,C_TYPE,true>* carr = &arr;
1791 CHECK( carr->begin(2,4,7,5) == carr->ptr(2,4,7,5,0) );
1792 CHECK( carr->end(2,4,7,5) == carr->ptr(2,4,7,5,6) );
1793 CHECK_EQUAL(24750L,carr->front(2,4,7,5));
1794 CHECK_EQUAL(24755L,carr->back(2,4,7,5));
1795 }
1796 TEST_FIXTURE(LongInt6DFixtureCTypeBC,Test6DBeginEndCTypeBC)
1797 {
1798 CHECK( arr.begin(2,4,7,5,1) == arr.ptr(2,4,7,5,1,0) );
1799 CHECK( arr.end(2,4,7,5,1) == arr.ptr(2,4,7,5,1,5) );
1800 CHECK_EQUAL(247510L,arr.front(2,4,7,5,1));
1801 CHECK_EQUAL(247514L,arr.back(2,4,7,5,1));
1802 const multi_arr<long,6,C_TYPE,true>* carr = &arr;
1803 CHECK( carr->begin(2,4,7,5,1) == carr->ptr(2,4,7,5,1,0) );
1804 CHECK( carr->end(2,4,7,5,1) == carr->ptr(2,4,7,5,1,5) );
1805 CHECK_EQUAL(247510L,carr->front(2,4,7,5,1));
1806 CHECK_EQUAL(247514L,carr->back(2,4,7,5,1));
1807 }
1808
1809 // can an indexed array element be used in variable length argument lists?
1810 TEST_FIXTURE(LongInt3DFixture,Test3DVarLengthArgument)
1811 {
1812 char buf[100];
1813 sprintf( buf, "%ld", arr[2][3][4] );
1814 long res;
1815 sscanf( buf, "%ld", &res );
1816 CHECK_EQUAL(234L,res);
1817 }
1818
1819 TEST_FIXTURE(LongInt3DFixtureCType,Test3DVarLengthArgumentCType)
1820 {
1821 char buf[100];
1822 sprintf( buf, "%ld", arr[2][3][4] );
1823 long res;
1824 sscanf( buf, "%ld", &res );
1825 CHECK_EQUAL(234L,res);
1826 }
1827
1828 TEST_FIXTURE(LongInt2DEmptyDim,Test2DEmptyDimIterator)
1829 {
1830 // this should not crash
1832 // bogus test so that variable gets used
1833 CHECK( p == p );
1834 }
1835
1836 TEST_FIXTURE(LongInt3DEmptyDim,Test3DEmptyDimIterator)
1837 {
1838 // this should not crash
1840 // bogus test so that variable gets used
1841 CHECK( p == p );
1842 }
1843
1844 TEST_FIXTURE(LongInt4DEmptyDim,Test4DEmptyDimIterator)
1845 {
1846 // this should not crash
1848 // bogus test so that variable gets used
1849 CHECK( p == p );
1850 }
1851
1852 TEST_FIXTURE(LongInt5DEmptyDim,Test5DEmptyDimIterator)
1853 {
1854 // this should not crash
1856 // bogus test so that variable gets used
1857 CHECK( p == p );
1858 }
1859
1860 TEST_FIXTURE(LongInt6DEmptyDim,Test6DEmptyDimIterator)
1861 {
1862 // this should not crash
1864 // bogus test so that variable gets used
1865 CHECK( p == p );
1866 }
1867
1868 TEST_FIXTURE(LongInt2DEmptyDimCType,Test2DEmptyDimIteratorCType)
1869 {
1870 // this should not crash
1872 // bogus test so that variable gets used
1873 CHECK( p == p );
1874 }
1875
1876 TEST_FIXTURE(LongInt3DEmptyDimCType,Test3DEmptyDimIteratorCType)
1877 {
1878 // this should not crash
1880 // bogus test so that variable gets used
1881 CHECK( p == p );
1882 }
1883
1884 TEST_FIXTURE(LongInt4DEmptyDimCType,Test4DEmptyDimIteratorCType)
1885 {
1886 // this should not crash
1888 // bogus test so that variable gets used
1889 CHECK( p == p );
1890 }
1891
1892 TEST_FIXTURE(LongInt5DEmptyDimCType,Test5DEmptyDimIteratorCType)
1893 {
1894 // this should not crash
1896 // bogus test so that variable gets used
1897 CHECK( p == p );
1898 }
1899
1900 TEST_FIXTURE(LongInt6DEmptyDimCType,Test6DEmptyDimIteratorCType)
1901 {
1902 // this should not crash
1904 // bogus test so that variable gets used
1905 CHECK( p == p );
1906 }
1907}
static double a2[63]
#define isnan
Definition cddefines.h:620
iterator ptr(size_type i1, size_type i2)
void state_do(FILE *io, bool lgGet)
const_pntr< T, lgBC > const_iterator
reference back(size_type i1)
void reserve(size_type i1)
iterator begin(size_type i1)
size_type size() const
pntr< T, lgBC > iterator
bool empty() const
iterator end(size_type i1)
reference front(size_type i1)
reference at(size_type i1, size_type i2)
const multi_geom< d, ALLOC > & clone() const
size_type capacity() const