31 #include <Base/Common/Array2D.hh>
32 #include <Base/Debug/Error.hh>
33 #include <Base/Debug/Exception.hh>
41 const bool verbose =
true;
44 #define SHOULD_THROW(command) \
46 bool has_thrown = false; \
48 catch ( BaseException b ) { has_thrown = true; } \
50 if (verbose) cout << #command << " was expected to throw an exception"\
51 <<", but it has not thrown. Test failed. \n"<<endl; \
62 void TestCompileErrors();
64 int main(
int argc,
char *argv[])
77 const unsigned nrow = 5, ncol = 7;
80 if (!foo.
empty()) { BIASABORT; }
81 if (foo.
nrows() != 0) { BIASABORT; }
82 if (foo.
ncols() != 0) { BIASABORT; }
83 if (foo.
size() != 0) { BIASABORT; }
86 if (foo2.empty()) { BIASABORT; }
87 if (foo2.nrows() != nrow) { BIASABORT; }
88 if (foo2.ncols() != ncol) { BIASABORT; }
89 if (foo2.size() != ncol * nrow) { BIASABORT; }
92 if (cp.empty()) { BIASABORT; }
93 if (cp.nrows() != nrow) { BIASABORT; }
94 if (cp.ncols() != ncol) { BIASABORT; }
97 if (uta.
empty()) { BIASABORT; }
98 if (uta.
nrows() != nrow) { BIASABORT; }
99 if (uta.
ncols() != ncol) { BIASABORT; }
102 if (!foo2.empty()) { BIASABORT; }
103 if (foo2.nrows() != 0) { BIASABORT; }
104 if (foo2.ncols() != 0) { BIASABORT; }
106 foo2.resize(nrow, ncol);
107 if (foo2.empty()) { BIASABORT; }
108 if (foo2.nrows() != nrow) { BIASABORT; }
109 if (foo2.ncols() != ncol) { BIASABORT; }
110 if (foo2.size() != ncol * nrow) { BIASABORT; }
117 const unsigned nrow = 11, ncol = 17;
118 const unsigned prow = nrow-1, pcol = ncol-1;
119 const int val = -1, val2 = 42;
123 foo(prow, pcol) = val2;
124 for (
unsigned r=0; r<nrow; r++){
125 for (
unsigned c=0; c<ncol; c++){
126 if (r==prow && c==pcol){
127 if (foo(r,c) != val2) { BIASABORT; }
129 if (foo(r,c) != val) { BIASABORT; }
134 SHOULD_THROW(foo(nrow, 0));
135 SHOULD_THROW(foo(0, ncol));
136 SHOULD_THROW(foo(nrow, ncol));
137 SHOULD_THROW(foo(nrow+42, 0));
138 SHOULD_THROW(foo(0, ncol+42));
139 SHOULD_THROW(foo(nrow+42, ncol+42));
145 foo[prow][pcol] = val;
146 for (
unsigned r=0; r<nrow; r++){
147 for (
unsigned c=0; c<ncol; c++){
148 if (r==prow && c==pcol){
149 if (foo[r][c] != val) { BIASABORT; }
151 if (foo[r][c] != val2) { BIASABORT; }
160 const unsigned nrow = 3, ncol = 4;
161 const unsigned prow = nrow-1, pcol = ncol-1;
162 const int val = -1, val2 = 42;
165 foo[prow][pcol] = val;
171 for (cit = cfoo.begin(); cit != cfoo.end(); cit++, pos++){
172 if (pos == prow * ncol + pcol){
173 if (*cit != val) { BIASABORT; }
175 if (*cit != val2) { BIASABORT; }
182 for (it = foo.
begin(); it != foo.
end(); it++, ipos++){
185 for (
unsigned r=0; r<nrow; r++){
186 for (
unsigned c=0; c<ncol; c++){
187 if (foo[r][c] != (
int)(r*ncol + c)) { BIASABORT; }
193 const vector<int> vval(1, val2), vval2(1, val);
195 vfoo[prow][pcol] = vval2;
201 for (cvit = cvfoo.
begin(); cvit != cvfoo.
end(); cvit++, pos++){
202 if (pos == prow * ncol + pcol){
203 if (cvit->operator[](0) != val) { BIASABORT; }
205 if (cvit->operator[](0) != val2) { BIASABORT; }
211 for (vit = vfoo.
begin(); vit != vfoo.
end(); vit++, ipos++){
213 vit->operator[](1) = ipos;
215 for (
unsigned r=0; r<nrow; r++){
216 for (
unsigned c=0; c<ncol; c++){
217 if (vfoo[r][c][1] != (
int)(r*ncol + c)) { BIASABORT; }
224 void TestCompileErrors()
226 const unsigned nrow = 11, ncol = 17;
237 #ifdef TEST_COMPILE_TIME_ERROR_ConstIterator
242 #ifdef TEST_COMPILE_TIME_ERROR_TemplateMismatch
for const_iterator access todo: derive from std::iterator class(es)
generic two dimensional rectangular array holding arbitrary data types
for iterator access todo: derive from std::iterator class(es)
void resize(const unsigned nrows, const unsigned ncols)
preserves the content
const_iterator end() const
void fill(const T &val)
fills the array with val
const_iterator begin() const