00001 #define BOOST_TEST_DYN_LINK
00002 #define BOOST_TEST_MODULE "ma"
00003
00004 #include <boost/test/unit_test.hpp>
00005
00006 #include <boost/multi_array.hpp>
00007 #include <boost/multi_array/index_gen.hpp>
00008 #include <boost/multi_array/index_range.hpp>
00009 #include <boost/multi_array/types.hpp>
00010
00011 #include <boost/array.hpp>
00012
00013 #include <algorithm>
00014 #include <vector>
00015
00016 typedef boost::detail::multi_array::index index_type;
00017 typedef boost::detail::multi_array::size_type size_type;
00018 typedef boost::detail::multi_array::index_range<index_type,size_type> range;
00019
00020 template <int NumRanges, int NumDims>
00021 void check(const boost::detail::multi_array::index_gen<NumRanges,NumDims>& a) { }
00022
00023 bool operator==(const range& lhs,const range& rhs) {
00024 return lhs.start_ == rhs.start_ &&
00025 lhs.finish_ == rhs.finish_ &&
00026 lhs.stride_ == rhs.stride_ &&
00027 lhs.degenerate_ == rhs.degenerate_;
00028 }
00029
00030 BOOST_AUTO_TEST_SUITE (ma0)
00031
00032 BOOST_AUTO_TEST_CASE(ctr0)
00033 {
00034 using boost::extents;
00035 using boost::indices;
00036 typedef boost::multi_array_types::index_range range;
00037 typedef boost::multi_array<int,3> array3;
00038 typedef boost::multi_array<int,2> array2;
00039
00040 typedef std::vector<array3> array3vec;
00041
00042 int data[] = {
00043 0,1,2,3,
00044 4,5,6,7,
00045 8,9,10,11,
00046
00047 12,13,14,15,
00048 16,17,18,19,
00049 20,21,22,23
00050 };
00051 const int data_size = 24;
00052
00053 int insert[] = {
00054 99,98,
00055 97,96,
00056 };
00057 const int insert_size = 4;
00058 array3 myarray(extents[2][3][4]);
00059 myarray.assign(data,data+data_size);
00060
00061 array3vec myvec(5,myarray);
00062 BOOST_CHECK(myarray == myvec[1]);
00063
00064 array3::array_view<2>::type myview =
00065 myarray[indices[1][range(0,2)][range(1,3)]];
00066
00067 array2 filler(extents[2][2]);
00068 filler.assign(insert,insert+insert_size);
00069
00070
00071 myview = filler;
00072
00073 myvec.push_back(myarray);
00074
00075 BOOST_CHECK(myarray != myvec[1]);
00076 BOOST_CHECK(myarray == myvec[5]);
00077 }
00078
00079 BOOST_AUTO_TEST_CASE(idx0)
00080 {
00081 boost::detail::multi_array::index_gen<0,0> indices;
00082
00083 check<1,1>(indices[range()]);
00084 check<2,2>(indices[range()][range()]);
00085 check<3,3>(indices[range()][range()][range()]);
00086
00087 check<1,0>(indices[0]);
00088 check<2,0>(indices[0][0]);
00089 check<2,1>(indices[range()][0]);
00090 check<2,1>(indices[0][range()]);
00091 check<3,0>(indices[0][0][0]);
00092 check<3,1>(indices[range()][0][0]);
00093 check<3,1>(indices[0][range()][0]);
00094 check<3,1>(indices[0][0][range()]);
00095 check<3,2>(indices[range()][range()][0]);
00096 check<3,2>(indices[range()][0][range()]);
00097 check<3,2>(indices[0][range()][range()]);
00098
00099 {
00100 boost::detail::multi_array::index_gen<3,3> is1 =
00101 indices[range(0,1,2)][range(1,2,3)][range(2,3,4)];
00102 BOOST_CHECK(is1.ranges_[0] == range(0,1,2));
00103 BOOST_CHECK(is1.ranges_[1] == range(1,2,3));
00104 BOOST_CHECK(is1.ranges_[2] == range(2,3,4));
00105 }
00106
00107 {
00108 boost::detail::multi_array::index_gen<3,2> is2 =
00109 indices[range(0,1,2)][2][range(2,3,4)];
00110 BOOST_CHECK(is2.ranges_[0] == range(0,1,2));
00111 BOOST_CHECK(is2.ranges_[1] == range(2));
00112 BOOST_CHECK(is2.ranges_[1].is_degenerate());
00113 BOOST_CHECK(is2.ranges_[2] == range(2,3,4));
00114 }
00115
00116 }
00117
00118 BOOST_AUTO_TEST_CASE(idx1)
00119 {
00120 boost::detail::multi_array::index_gen<0,0> indices;
00121 int rows0, cols0;
00122 rows0 = cols0 = 1;
00123
00124 range a = range();
00125
00126
00127 check<1,1>(indices[range()]);
00128
00129 }
00130
00131 BOOST_AUTO_TEST_SUITE_END()