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