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