sl@0
|
1 |
// Copyright 2002 The Trustees of Indiana University.
|
sl@0
|
2 |
|
sl@0
|
3 |
// Use, modification and distribution is subject to the Boost Software
|
sl@0
|
4 |
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
sl@0
|
5 |
// http://www.boost.org/LICENSE_1_0.txt)
|
sl@0
|
6 |
|
sl@0
|
7 |
// Boost.MultiArray Library
|
sl@0
|
8 |
// Authors: Ronald Garcia
|
sl@0
|
9 |
// Jeremy Siek
|
sl@0
|
10 |
// Andrew Lumsdaine
|
sl@0
|
11 |
// See http://www.boost.org/libs/multi_array for documentation.
|
sl@0
|
12 |
|
sl@0
|
13 |
//
|
sl@0
|
14 |
// access.cpp - operator[] and operator() tests with various arrays
|
sl@0
|
15 |
// The tests assume that they are working on an Array of shape 2x3x4
|
sl@0
|
16 |
//
|
sl@0
|
17 |
/*
|
sl@0
|
18 |
* © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
|
sl@0
|
19 |
*/
|
sl@0
|
20 |
|
sl@0
|
21 |
#include "generative_tests.hpp"
|
sl@0
|
22 |
#include "boost/static_assert.hpp"
|
sl@0
|
23 |
|
sl@0
|
24 |
template <typename Array>
|
sl@0
|
25 |
void access(Array& A, const mutable_array_tag&) {
|
sl@0
|
26 |
assign(A);
|
sl@0
|
27 |
access(A,const_array_tag());
|
sl@0
|
28 |
|
sl@0
|
29 |
const Array& CA = A;
|
sl@0
|
30 |
access(CA,const_array_tag());
|
sl@0
|
31 |
}
|
sl@0
|
32 |
|
sl@0
|
33 |
template <typename Array>
|
sl@0
|
34 |
void access(Array& A, const const_array_tag&) {
|
sl@0
|
35 |
const unsigned int ndims = 3;
|
sl@0
|
36 |
BOOST_STATIC_ASSERT((Array::dimensionality == ndims));
|
sl@0
|
37 |
typedef typename Array::index index;
|
sl@0
|
38 |
const index idx0 = A.index_bases()[0];
|
sl@0
|
39 |
const index idx1 = A.index_bases()[1];
|
sl@0
|
40 |
const index idx2 = A.index_bases()[2];
|
sl@0
|
41 |
|
sl@0
|
42 |
// operator[]
|
sl@0
|
43 |
int cnum = 0;
|
sl@0
|
44 |
const Array& CA = A;
|
sl@0
|
45 |
for (index i = idx0; i != idx0+2; ++i)
|
sl@0
|
46 |
for (index j = idx1; j != idx1+3; ++j)
|
sl@0
|
47 |
for (index k = idx2; k != idx2+4; ++k) {
|
sl@0
|
48 |
BOOST_CHECK(A[i][j][k] == cnum++);
|
sl@0
|
49 |
BOOST_CHECK(CA[i][j][k] == A[i][j][k]);
|
sl@0
|
50 |
}
|
sl@0
|
51 |
|
sl@0
|
52 |
// operator()
|
sl@0
|
53 |
for (index i2 = idx0; i2 != idx0+2; ++i2)
|
sl@0
|
54 |
for (index j2 = idx1; j2 != idx1+3; ++j2)
|
sl@0
|
55 |
for (index k2 = idx2; k2 != idx2+4; ++k2) {
|
sl@0
|
56 |
boost::array<index,ndims> indices;
|
sl@0
|
57 |
indices[0] = i2; indices[1] = j2; indices[2] = k2;
|
sl@0
|
58 |
BOOST_CHECK(A(indices) == A[i2][j2][k2]);
|
sl@0
|
59 |
BOOST_CHECK(CA(indices) == A(indices));
|
sl@0
|
60 |
}
|
sl@0
|
61 |
++tests_run;
|
sl@0
|
62 |
}
|
sl@0
|
63 |
|
sl@0
|
64 |
int test_main(int,char*[]) {
|
sl@0
|
65 |
#ifdef __SYMBIAN32__
|
sl@0
|
66 |
if(boost::minimal_test::errors_counter() != 0)
|
sl@0
|
67 |
assert_failed = true;
|
sl@0
|
68 |
testResultXml("access");
|
sl@0
|
69 |
close_log_file();
|
sl@0
|
70 |
#endif
|
sl@0
|
71 |
return run_generative_tests();
|
sl@0
|
72 |
}
|