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
|
#include "testsuite.h"
#include <blitz/array.h>
#ifdef BZ_HAVE_STL
#include <iterator>
#include <algorithm>
using namespace std;
#endif
using namespace blitz;
void check(const Array<int,2>& A, const Array<int,1>& b)
{
int i = 0;
Array<int,2>::const_iterator beg = A.begin(), end = A.end();
Array<int,2>::const_iterator iter = beg;
while (iter != end) {
BZTEST((*iter++) == b(i++));
}
BZTEST(i == A.numElements());
while (iter!=beg) {
BZTEST((*--iter) == b(--i));
}
BZTEST(i == 0);
}
#ifdef BZ_HAVE_STL
template <typename _Iter>
void checkInterface(_Iter iter)
{
typedef typename iterator_traits<_Iter>::value_type value_type;
typedef typename iterator_traits<_Iter>::reference reference;
typedef typename iterator_traits<_Iter>::pointer pointer;
value_type x = *iter;
BZTEST(*iter == x);
reference y(x);
pointer p = &(*iter);
BZTEST(*p == y);
}
#endif // BZ_HAVE_STL
int main()
{
{
Array<int,2> A(2,3);
A = 0, 1, 2,
3, 4, 5;
Array<int,1> b(6);
b = 0, 1, 2, 3, 4, 5;
check(A, b);
}
{
Array<int,2> A(2,3,FortranArray<2>());
A = tensor::i * 3 + tensor::j;
Array<int,1> b(6);
b = 4, 7, 5, 8, 6, 9;
check(A,b);
}
#if 0
{
Array<int,2> B(5,5,FortranArray<2>());
B = tensor::i + 5 * tensor::j;
B.reverseSelf(1);
check(B);
}
#endif
{
Array<int,2> B(6,6,FortranArray<2>());
B = tensor::i * 6 + tensor::j;
Array<int,1> b(12);
b = 7, 13, 19, 8, 14, 20, 9, 15, 21, 10, 16, 22;
check(B(Range(1,3),Range(1,4)), b);
}
{
Array<int,2> B;
Array<int,2>::iterator iter = B.begin(), end = B.end();
BZTEST(iter == end);
}
#ifdef BZ_HAVE_STL
{
Array<int,2> A(3,3);
A = 1, 2, 3,
3, 2, 1,
4, 3, 2;
replace(A.begin(), A.end(), 3, 0); // replace each 3 with 0
Array<int,1> b(9);
b = 1, 2, 0, 0, 2, 1, 4, 0, 2;
check(A,b);
Array<int,2>::iterator iter;
iter = adjacent_find(A.begin(),A.end());
TinyVector<int,2> pos = iter.position(), ans(0,2);
BZTEST(pos[0] == ans[0] && pos[1] == ans[1]);
checkInterface(iter);
const Array<int,2>& B(A);
Array<int,2>::const_iterator citer = B.begin();
checkInterface(citer);
}
#endif // BZ_HAVE_STL
}
|