File size: 25,233 Bytes
68ce2fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-    */
/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */

/*
  
  Author(s):	Anton Deguet
  Created on:	2007-02-06
  
  (C) Copyright 2007-2026 Johns Hopkins University (JHU), All Rights
  Reserved.

--- begin cisst license - do not edit ---

This software is provided "as is" under an open source license, with
no warranty.  The complete license can be found in license.txt and
http://www.cisst.org/cisst/license.txt.

--- end cisst license ---
*/


#include "vctDynamicNArrayRefTest.h"

#include <cisstVector/vctDynamicVector.h>
#include <cisstVector/vctDynamicNArray.h>
#include <cisstVector/vctDynamicConstNArrayRef.h>
#include <cisstVector/vctDynamicNArrayRef.h>
#include <cisstVector/vctRandomDynamicNArray.h>
#include <cisstVector/vctRandomFixedSizeVector.h>
#include "vctGenericNArrayTest.h"


template <class _elementType>
void vctDynamicNArrayRefTest::TestRefOnArray(void)
{
    typedef _elementType value_type;

    enum {DIMENSION = 4};
    typedef vctDynamicNArray<value_type, DIMENSION> ArrayType;
    typedef vctDynamicNArrayRef<value_type, DIMENSION> ArrayRefType;
    typedef vctDynamicConstNArrayRef<value_type, DIMENSION> ConstArrayRefType;

    typedef typename ArrayType::index_type index_type;
    typedef typename ArrayType::nsize_type SizesType;
    typedef typename ArrayType::nsize_type IndicesType;

    SizesType sizes;
    vctRandom(sizes, static_cast<index_type>(MIN_SIZE), static_cast<index_type>(MAX_SIZE));

    ArrayType nArray1(sizes);
    vctRandom(nArray1, static_cast<value_type>(-10), static_cast<value_type>(10));

    ArrayRefType nArray1Ref1(nArray1);
    ArrayRefType nArray1Ref2;
    nArray1Ref2.SetRef(nArray1);
    
    ConstArrayRefType nArray1ConstRef1(nArray1);
    ConstArrayRefType nArray1ConstRef2;
    nArray1ConstRef2.SetRef(nArray1);
    
    CPPUNIT_ASSERT(nArray1.sizes() == nArray1Ref1.sizes());
    CPPUNIT_ASSERT(nArray1.strides() == nArray1Ref1.strides());

    CPPUNIT_ASSERT(nArray1.sizes() == nArray1Ref2.sizes());
    CPPUNIT_ASSERT(nArray1.strides() == nArray1Ref2.strides());

    CPPUNIT_ASSERT(nArray1.sizes() == nArray1ConstRef1.sizes());
    CPPUNIT_ASSERT(nArray1.strides() == nArray1ConstRef1.strides());

    CPPUNIT_ASSERT(nArray1.sizes() == nArray1ConstRef2.sizes());
    CPPUNIT_ASSERT(nArray1.strides() == nArray1ConstRef2.strides());

    index_type i, j, k, l;
    IndicesType indices;
    for (i = 0; i < nArray1.size(0); i++) {
        for (j = 0; j < nArray1.size(1); j++) {
            for (k = 0; k < nArray1.size(2); k++) {
                for (l = 0; l < nArray1.size(3); l++) {
                    indices.Assign(i, j, k, l);
                    CPPUNIT_ASSERT(nArray1(indices)         == nArray1Ref1(indices));
                    CPPUNIT_ASSERT(nArray1.at(indices)      == nArray1Ref1.at(indices));
                    CPPUNIT_ASSERT(nArray1.Element(indices) == nArray1Ref1.Element(indices));
                    CPPUNIT_ASSERT(nArray1.Pointer(indices) == nArray1Ref1.Pointer(indices));
                    CPPUNIT_ASSERT(nArray1[i][j][k][l]      == nArray1Ref1[i][j][k][l]);

                    CPPUNIT_ASSERT(nArray1(indices)         == nArray1Ref2(indices));
                    CPPUNIT_ASSERT(nArray1.at(indices)      == nArray1Ref2.at(indices));
                    CPPUNIT_ASSERT(nArray1.Element(indices) == nArray1Ref2.Element(indices));
                    CPPUNIT_ASSERT(nArray1.Pointer(indices) == nArray1Ref2.Pointer(indices));
                    CPPUNIT_ASSERT(nArray1[i][j][k][l]      == nArray1Ref2[i][j][k][l]);

                    CPPUNIT_ASSERT(nArray1(indices)         == nArray1ConstRef1(indices));
                    CPPUNIT_ASSERT(nArray1.at(indices)      == nArray1ConstRef1.at(indices));
                    CPPUNIT_ASSERT(nArray1.Element(indices) == nArray1ConstRef1.Element(indices));
                    CPPUNIT_ASSERT(nArray1.Pointer(indices) == nArray1ConstRef1.Pointer(indices));
                    CPPUNIT_ASSERT(nArray1[i][j][k][l]      == nArray1ConstRef1[i][j][k][l]);

                    CPPUNIT_ASSERT(nArray1(indices)         == nArray1ConstRef2(indices));
                    CPPUNIT_ASSERT(nArray1.at(indices)      == nArray1ConstRef2.at(indices));
                    CPPUNIT_ASSERT(nArray1.Element(indices) == nArray1ConstRef2.Element(indices));
                    CPPUNIT_ASSERT(nArray1.Pointer(indices) == nArray1ConstRef2.Pointer(indices));
                }
            }
        }
    }
    
}

void vctDynamicNArrayRefTest::TestRefOnArrayDouble(void) {
    TestRefOnArray<double>();
}
void vctDynamicNArrayRefTest::TestRefOnArrayFloat(void) {
    TestRefOnArray<float>();
}
void vctDynamicNArrayRefTest::TestRefOnArrayInt(void) {
    TestRefOnArray<int>();
}




template <class _elementType>
void vctDynamicNArrayRefTest::TestSubarrayRef(void)
{
    typedef _elementType value_type;

    enum {DIMENSION = 3};
    typedef vctDynamicNArray<value_type, DIMENSION> ArrayType;
    typedef vctDynamicNArrayRef<value_type, DIMENSION> ArrayRefType;
    typedef vctDynamicConstNArrayRef<value_type, DIMENSION> ConstArrayRefType;

    typedef typename ArrayType::size_type size_type;
    typedef typename ArrayType::index_type index_type;
    typedef typename ArrayType::nsize_type SizesType;
    typedef typename ArrayType::nsize_type IndicesType;

    enum {ALL_MIN = 10, ALL_MAX = 12};
    enum {START_MIN = 2, START_MAX = 4};
    enum {LENGTH_MIN = 2, LENGTH_MAX = 4};
    SizesType sizes, starts, lengths;
    vctRandom(sizes, static_cast<size_type>(ALL_MIN), static_cast<size_type>(ALL_MAX));
    vctRandom(starts, static_cast<size_type>(START_MIN), static_cast<size_type>(START_MAX));
    vctRandom(lengths, static_cast<size_type>(LENGTH_MIN), static_cast<size_type>(LENGTH_MAX));

    ArrayType nArray1(sizes);
    vctRandom(nArray1, static_cast<value_type>(-10), static_cast<value_type>(10));

    ArrayRefType subNArray1;
    subNArray1.SubarrayOf(nArray1, starts, lengths);

    ConstArrayRefType subConstNArray1;
    subConstNArray1.SubarrayOf(nArray1, starts, lengths);
    
    index_type i, j, k;
    IndicesType indicesSub, indices;
    
    CPPUNIT_ASSERT(subNArray1.sizes() == lengths);
  
    for (i = 0; i < subNArray1.size(0); i++) {
        for (j = 0; j < subNArray1.size(1); j++) {
            for (k = 0; k < subNArray1.size(2); k++) {
                indicesSub.Assign(i, j, k);
                indices.SumOf(starts, indicesSub);
            
                CPPUNIT_ASSERT(nArray1(indices)         == subNArray1(indicesSub));
                CPPUNIT_ASSERT(nArray1.at(indices)      == subNArray1.at(indicesSub));
                CPPUNIT_ASSERT(nArray1.Element(indices) == subNArray1.Element(indicesSub));
                CPPUNIT_ASSERT(nArray1.Pointer(indices) == subNArray1.Pointer(indicesSub));
                CPPUNIT_ASSERT(nArray1[i + starts.Element(0)][j + starts.Element(1)][k + starts.Element(2)] == subNArray1[i][j][k]);

                CPPUNIT_ASSERT(nArray1(indices)         == subConstNArray1(indicesSub));
                CPPUNIT_ASSERT(nArray1.at(indices)      == subConstNArray1.at(indicesSub));
                CPPUNIT_ASSERT(nArray1.Element(indices) == subConstNArray1.Element(indicesSub));
                CPPUNIT_ASSERT(nArray1.Pointer(indices) == subConstNArray1.Pointer(indicesSub));
                CPPUNIT_ASSERT(nArray1[i + starts.Element(0)][j + starts.Element(1)][k + starts.Element(2)] == subConstNArray1[i][j][k]);
            }
        }
    }
}

void vctDynamicNArrayRefTest::TestSubarrayRefDouble(void) {
    TestSubarrayRef<double>();
}
void vctDynamicNArrayRefTest::TestSubarrayRefFloat(void) {
    TestSubarrayRef<float>();
}
void vctDynamicNArrayRefTest::TestSubarrayRefInt(void) {
    TestSubarrayRef<int>();
}



template <class _elementType>
void vctDynamicNArrayRefTest::TestPermutationRef(void)
{
    typedef _elementType value_type;

    enum {DIMENSION = 4};
    typedef vctDynamicNArray<value_type, DIMENSION> ArrayType;
    typedef vctDynamicNArrayRef<value_type, DIMENSION> ArrayRefType;
    typedef vctDynamicConstNArrayRef<value_type, DIMENSION> ConstArrayRefType;

    typedef typename ArrayType::size_type size_type;
    typedef typename ArrayType::index_type index_type;
    typedef typename ArrayType::nsize_type SizesType;
    typedef typename ArrayType::ndimension_type DimensionsType;
    typedef typename ArrayType::nindex_type IndicesType;
    typedef typename ArrayType::index_type IndexType;

    SizesType sizes;
    vctRandom(sizes, static_cast<size_type>(MIN_SIZE), static_cast<size_type>(MAX_SIZE));
    
    ArrayType nArray1(sizes);
    vctRandom(nArray1, static_cast<value_type>(-10), static_cast<value_type>(10));
    
    DimensionsType permutation;
    IndicesType swaps;
    
    // build a permutation vector
    index_type index;
    for (index = 0; index < permutation.size(); index++) {
        permutation.Element(index) = index;
    }
    vctRandom(swaps, static_cast<IndexType>(0), permutation.size());
    IndexType temp;
    for (index = 0; index < permutation.size(); index++) {
        temp = permutation[0];
        permutation[0] = permutation[swaps[index]];
        permutation[swaps[index]] = temp;
    }
    
    // apply the permutation for both const and non const narray
    ArrayRefType permutedNArray1;
    permutedNArray1.PermutationOf(nArray1, permutation);

    ConstArrayRefType permutedConstNArray1;
    permutedConstNArray1.PermutationOf(nArray1, permutation);

    // check that sizes are permuted
    for (index = 0; index < permutation.size(); index++) {
        CPPUNIT_ASSERT(permutedNArray1.size(index) == nArray1.size(permutation[index]));
        CPPUNIT_ASSERT(permutedConstNArray1.size(index) == nArray1.size(permutation[index]));
    }

    index_type i, j, k, l;
    IndicesType indicesPermuted, indices;
    
    for (i = 0; i < nArray1.size(0); i++) {
        for (j = 0; j < nArray1.size(1); j++) {
            for (k = 0; k < nArray1.size(2); k++) {
                for (l = 0; l < nArray1.size(3); l++) {
                    indices.Assign(i, j, k, l);
                    indicesPermuted.Assign(indices[permutation[0]],
                        indices[permutation[1]],
                        indices[permutation[2]],
                        indices[permutation[3]]);
                    CPPUNIT_ASSERT(nArray1(indices)         == permutedNArray1(indicesPermuted));
                    CPPUNIT_ASSERT(nArray1.at(indices)      == permutedNArray1.at(indicesPermuted));
                    CPPUNIT_ASSERT(nArray1.Element(indices) == permutedNArray1.Element(indicesPermuted));
                    CPPUNIT_ASSERT(nArray1.Pointer(indices) == permutedNArray1.Pointer(indicesPermuted));
                    CPPUNIT_ASSERT(nArray1[i][j][k][l] == permutedNArray1
                                           [indices[permutation[0]]]
                                           [indices[permutation[1]]]
                                           [indices[permutation[2]]]
                                           [indices[permutation[3]]]);
                    CPPUNIT_ASSERT(nArray1(indices)         == permutedConstNArray1(indicesPermuted));
                    CPPUNIT_ASSERT(nArray1.at(indices)      == permutedConstNArray1.at(indicesPermuted));
                    CPPUNIT_ASSERT(nArray1.Element(indices) == permutedConstNArray1.Element(indicesPermuted));
                    CPPUNIT_ASSERT(nArray1.Pointer(indices) == permutedConstNArray1.Pointer(indicesPermuted));
                    CPPUNIT_ASSERT(nArray1[i][j][k][l] == permutedConstNArray1
                                           [indices[permutation[0]]]
                                           [indices[permutation[1]]]
                                           [indices[permutation[2]]]
                                           [indices[permutation[3]]]);
                }
            }
        }
    }
}

void vctDynamicNArrayRefTest::TestPermutationRefDouble(void) {
    TestPermutationRef<double>();
}
void vctDynamicNArrayRefTest::TestPermutationRefFloat(void) {
    TestPermutationRef<float>();
}
void vctDynamicNArrayRefTest::TestPermutationRefInt(void) {
    TestPermutationRef<int>();
}





// Function used to create a complex ref on a solid array.  It will
// first reslice, then permute and finally resize (windowing).  The
// sizes for windowing are provided so that many refs can be created
// with the same sizes.  The vector indices must contain all indices
// between 0 and _dimension - 1, it is used to compute a permutation.
template <vct::size_type _dimension>
void vctDynamicNArrayRefTestSetWorstArrayRef(vctDynamicNArray<double, _dimension> & baseArray,
                                             const vctFixedSizeVector<vct::size_type, _dimension - 1> & sizes,
                                             vctFixedSizeVector<vct::index_type, _dimension - 1> indices,
                                             vctDynamicNArrayRef<double, _dimension - 1> & array) {
    typedef vct::index_type index_type;

    // reslice
    vctDynamicNArrayRef<double, _dimension - 1> baseSliced;
    index_type sliceDirection;
    index_type sliceIndex;
    
    cmnRandomSequence & randomSequence = cmnRandomSequence::GetInstance();
    randomSequence.ExtractRandomValue(static_cast<index_type>(0), _dimension, sliceDirection);
    randomSequence.ExtractRandomValue(static_cast<index_type>(0), baseArray.size(sliceDirection), sliceIndex);
    baseSliced.SliceOf(baseArray, sliceDirection, sliceIndex);

    // permute
    vctDynamicNArrayRef<double, _dimension - 1> basePermuted;
    vctFixedSizeVector<index_type, _dimension - 1> swaps;
    vctRandom(swaps, static_cast<index_type>(0), indices.size());
    index_type index, temp;
    for (index = 0; index < indices.size(); index++) {
        temp = indices[0];
        indices[0] = indices[swaps[index]];
        indices[swaps[index]] = temp;
    }
    basePermuted.PermutationOf(baseSliced, indices);

    // take a smaller window
    vctFixedSizeVector<index_type, _dimension - 1> starts(static_cast<index_type>(0));
    array.SubarrayOf(basePermuted, starts, sizes);

    // fill with random values
    vctRandom(array, static_cast<double>(-10), static_cast<double>(10));
}



void vctDynamicNArrayRefTest::TestEngines(void)
{
    /* define types for engine tests on narrays of doubles */
    enum {DIMENSION = 5};
    typedef double value_type;
    typedef vctDynamicNArray<value_type, DIMENSION> ArrayType;
    typedef vctDynamicNArrayRef<value_type, DIMENSION - 1> ArrayRefType;

    typedef ArrayType::size_type size_type;
    typedef ArrayType::index_type index_type;
    typedef ArrayType::nsize_type larger_nsize_type;
    typedef ArrayType::nindex_type larger_nindex_type;

    typedef ArrayRefType::value_type value_type;
    typedef ArrayRefType::nsize_type nsize_type;
    typedef ArrayRefType::nindex_type nindex_type;
    typedef ArrayRefType::const_iterator const_iterator;
    typedef ArrayRefType::const_reverse_iterator const_reverse_iterator;

    ArrayType baseArray1, baseArray2, baseArray3;
    ArrayRefType array1, array2, array3;

    // build a permutation vector
    nindex_type allIndices;
    index_type index;
    nsize_type sizes;

    // allocate memory for all 3 containers
    baseArray1.SetSize(larger_nsize_type(MAX_SIZE));
    baseArray2.SetSize(larger_nsize_type(MAX_SIZE));
    baseArray3.SetSize(larger_nsize_type(MAX_SIZE));

    // create a list of indices for all permutations
    for (index = 0; index < allIndices.size(); index++) {
        allIndices.Element(index) = index;
    }

    // first test that the set worst array ref doesn't break everything
    vctRandom(sizes, static_cast<size_type>(MIN_SIZE), static_cast<size_type>(MAX_SIZE));
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray1, sizes, allIndices, array1);
    for (index = 0; index < array1.dimension(); index++) {
        CPPUNIT_ASSERT(array1.size(index) <= MAX_SIZE);
    }

    // test address of elements accessed via iterators
    const value_type * first = baseArray1.Pointer();
    const value_type * last = baseArray1.Pointer(larger_nindex_type(MAX_SIZE));
    const const_iterator begin = array1.begin();
    const const_iterator end = array1.end();
    const_iterator iter;
    for (iter = begin; iter != end; ++iter) {
        CPPUNIT_ASSERT(&(*iter) <= last);
        CPPUNIT_ASSERT(&(*iter) >= first);
        CPPUNIT_ASSERT(*iter >= static_cast<double>(-10));
        CPPUNIT_ASSERT(*iter <= static_cast<double>(10));
    }
    const const_reverse_iterator rbegin = array1.rbegin();
    const const_reverse_iterator rend = array1.rend();
    const_reverse_iterator riter;
    for (riter = rbegin; riter != rend; ++riter) {
        CPPUNIT_ASSERT(&(*riter) <= last);
        CPPUNIT_ASSERT(&(*riter) >= first);
    }
    
    // test address of elements accessed directly
    index_type i, j, k, l;
    value_type * currentPointer;
    nindex_type currentIndices;
    for (i = 0; i < array1.size(0); i++) {
        for (j = 0; j < array1.size(1); j++) {
            for (k = 0; k < array1.size(2); k++) {
                for (l = 0; l < array1.size(3); l++) {
                    currentPointer = &(array1[i][j][k][l]);
                    CPPUNIT_ASSERT(currentPointer <= last);
                    CPPUNIT_ASSERT(currentPointer >= first);
                    currentIndices.Assign(i, j, k, l);
                    CPPUNIT_ASSERT(array1.Pointer(currentIndices) <= last);
                    CPPUNIT_ASSERT(array1.Pointer(currentIndices) >= first);
                }
            }
        }
    }

    // scalar and random sequence used for all tests
    double scalar;
    cmnRandomSequence & randomSequence = cmnRandomSequence::GetInstance();

    // tests per engine, new size and new content everytime
    vctRandom(sizes, static_cast<size_type>(MIN_SIZE), static_cast<size_type>(MAX_SIZE));
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray1, sizes, allIndices, array1);
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray2, sizes, allIndices, array2);
    vctGenericNArrayTest::TestAssignment(array1, array2);

    // test SoNi
    vctRandom(sizes, static_cast<size_type>(MIN_SIZE), static_cast<size_type>(MAX_SIZE));
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray1, sizes, allIndices, array1);
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray2, sizes, allIndices, array2);
    vctGenericContainerTest::TestSoCiOperations(array1, array2);
    
    // test SoNiNi
    vctRandom(sizes, static_cast<size_type>(MIN_SIZE), static_cast<size_type>(MAX_SIZE));
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray1, sizes, allIndices, array1);
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray2, sizes, allIndices, array2);
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray3, sizes, allIndices, array3);
    vctGenericContainerTest::TestSoCiCiOperations(array1, array2, array3);

    // test NioNi
    vctRandom(sizes, static_cast<size_type>(MIN_SIZE), static_cast<size_type>(MAX_SIZE));
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray1, sizes, allIndices, array1);
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray2, sizes, allIndices, array2);
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray3, sizes, allIndices, array3);
    RemoveQuasiZero(array2);
    vctGenericContainerTest::TestCioCiOperations(array1, array2, array3);

    // test NioSiNi
    vctRandom(sizes, static_cast<size_type>(MIN_SIZE), static_cast<size_type>(MAX_SIZE));
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray1, sizes, allIndices, array1);
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray2, sizes, allIndices, array2);
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray3, sizes, allIndices, array3);
    RemoveQuasiZero(array2);
    randomSequence.ExtractRandomValue(-5.0, 5.0, scalar);
    if ((scalar < 1.0)
        && (scalar > -1.0)) {
        scalar = 3.0;
    }
    vctGenericContainerTest::TestCioSiCiOperations(array1, scalar, array2, array3);

    // test NoNiNi
    vctRandom(sizes, static_cast<size_type>(MIN_SIZE), static_cast<size_type>(MAX_SIZE));
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray1, sizes, allIndices, array1);
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray2, sizes, allIndices, array2);
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray3, sizes, allIndices, array3);
    RemoveQuasiZero(array2);
    vctGenericContainerTest::TestCoCiCiOperations(array1, array2, array3);

    // test NoNi
    vctRandom(sizes, static_cast<size_type>(MIN_SIZE), static_cast<size_type>(MAX_SIZE));
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray1, sizes, allIndices, array1);
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray2, sizes, allIndices, array2);
    vctGenericContainerTest::TestCoCiOperations(array1, array2);

    // test NoNiSi
    vctRandom(sizes, static_cast<size_type>(MIN_SIZE), static_cast<size_type>(MAX_SIZE));
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray1, sizes, allIndices, array1);
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray2, sizes, allIndices, array2);
    randomSequence.ExtractRandomValue(-5.0, 5.0, scalar);
    if ((scalar < 1.0)
        && (scalar > -1.0)) {
        scalar = 3.0;
    }
    vctGenericContainerTest::TestCoCiSiOperations(array1, scalar, array2);

    // test NoSiNi
    vctRandom(sizes, static_cast<size_type>(MIN_SIZE), static_cast<size_type>(MAX_SIZE));
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray1, sizes, allIndices, array1);
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray2, sizes, allIndices, array2);
    RemoveQuasiZero(array1);
    randomSequence.ExtractRandomValue(-5.0, 5.0, scalar);
    vctGenericContainerTest::TestCoSiCiOperations(scalar, array1, array2);

    // test NioSi
    vctRandom(sizes, static_cast<size_type>(MIN_SIZE), static_cast<size_type>(MAX_SIZE));
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray1, sizes, allIndices, array1);
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray2, sizes, allIndices, array2);
    randomSequence.ExtractRandomValue(-5.0, 5.0, scalar);
    if ((scalar < 1.0)
        && (scalar > -1.0)) {
        scalar = 3.0;
    }
    vctGenericContainerTest::TestCioSiOperations(array1, scalar, array2);

    // test Nio
    vctRandom(sizes, static_cast<size_type>(MIN_SIZE), static_cast<size_type>(MAX_SIZE));
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray1, sizes, allIndices, array1);
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray2, sizes, allIndices, array2);
    vctGenericContainerTest::TestCioOperations(array1, array2);

    // test SoNiSi
    vctRandom(sizes, static_cast<size_type>(MIN_SIZE), static_cast<size_type>(MAX_SIZE));
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray1, sizes, allIndices, array1);
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray2, sizes, allIndices, array2);
    randomSequence.ExtractRandomValue(-5.0, 5.0, scalar);
    vctGenericContainerTest::TestSoCiSiOperations(array1, scalar, array2);

    // test MinAndMax
    vctRandom(sizes, static_cast<size_type>(MIN_SIZE), static_cast<size_type>(MAX_SIZE));
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray1, sizes, allIndices, array1);
    vctGenericContainerTest::TestMinAndMax(array1);

    // test iterators
    vctRandom(sizes, static_cast<size_type>(MIN_SIZE), static_cast<size_type>(MAX_SIZE));
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray1, sizes, allIndices, array1);
    vctGenericContainerTest::TestIterators(array1);

    // test STL functions
    vctRandom(sizes, static_cast<size_type>(MIN_SIZE), static_cast<size_type>(MAX_SIZE));
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray1, sizes, allIndices, array1);
    vctDynamicNArrayRefTestSetWorstArrayRef<DIMENSION>(baseArray2, sizes, allIndices, array2);
    vctGenericContainerTest::TestSTLFunctions(array1, array2);
}

template <class _elementType>
void vctDynamicNArrayRefTest::TestRandomTemporaryRef(void)
{
    typedef _elementType value_type;

    enum {DIMENSION = 3};
    typedef vctDynamicNArray<value_type, DIMENSION> ArrayType;
    typedef vctDynamicNArrayRef<value_type, DIMENSION> ArrayRefType;
    typedef typename ArrayType::nsize_type SizesType;

    SizesType sizes;
    sizes.Assign(3, 4, 5);

    ArrayType nArray(sizes);
    nArray.SetAll(value_type(100));

    vctRandom(ArrayRefType(nArray),
              value_type(-10), value_type(10));

    vctGenericContainerTest::TestElementsInRange(nArray, value_type(-10), value_type(10));
}

void vctDynamicNArrayRefTest::TestRandomTemporaryRefDouble(void) {
    TestRandomTemporaryRef<double>();
}
void vctDynamicNArrayRefTest::TestRandomTemporaryRefFloat(void) {
    TestRandomTemporaryRef<float>();
}
void vctDynamicNArrayRefTest::TestRandomTemporaryRefInt(void) {
    TestRandomTemporaryRef<int>();
}


CPPUNIT_TEST_SUITE_REGISTRATION(vctDynamicNArrayRefTest);