32 #include <Base/Common/SparseArray2D.hh>
33 #include <Base/Debug/Error.hh>
34 #include <Base/Debug/Exception.hh>
40 const bool verbose =
true;
43 #define SHOULD_THROW(command) \
45 bool has_thrown = false; \
47 catch ( BaseException b ) { has_thrown = true; } \
49 if (verbose) cout << #command << " was expected to throw an exception"\
50 <<", but it has not thrown. Test failed. \n"<<endl; \
61 void TestCompileErrors();
66 int main(
int argc,
char *argv[])
79 const unsigned nrow = 5, ncol = 7;
82 if (!foo.
empty()) { BIASABORT; }
83 if (foo.
nrows() != 0) { BIASABORT; }
84 if (foo.
ncols() != 0) { BIASABORT; }
85 if (foo.
size() != 0) { BIASABORT; }
88 if (foo2.empty()) { BIASABORT; }
89 if (foo2.nrows() != nrow) { BIASABORT; }
90 if (foo2.ncols() != ncol) { BIASABORT; }
91 if (foo2.size() != ncol * nrow) { BIASABORT; }
94 if (cp.empty()) { BIASABORT; }
95 if (cp.nrows() != nrow) { BIASABORT; }
96 if (cp.ncols() != ncol) { BIASABORT; }
99 if (uta.
empty()) { BIASABORT; }
100 if (uta.
nrows() != nrow) { BIASABORT; }
101 if (uta.
ncols() != ncol) { BIASABORT; }
104 if (!foo2.empty()) { BIASABORT; }
105 if (foo2.nrows() != 0) { BIASABORT; }
106 if (foo2.ncols() != 0) { BIASABORT; }
108 foo2.resize(nrow, ncol);
109 if (foo2.empty()) { BIASABORT; }
110 if (foo2.nrows() != nrow) { BIASABORT; }
111 if (foo2.ncols() != ncol) { BIASABORT; }
112 if (foo2.size() != ncol * nrow) { BIASABORT; }
119 const unsigned nrow = 11, ncol = 17;
120 const unsigned prow = nrow-1, pcol = ncol-1;
121 const int val = -1, val2 = 42;
125 foo(prow, pcol) = val2;
126 for (
unsigned r=0; r<nrow; r++){
127 for (
unsigned c=0; c<ncol; c++){
128 if (r==prow && c==pcol){
129 if (foo(r,c) != val2) { BIASABORT; }
131 if (foo(r,c) != val) { BIASABORT; }
136 SHOULD_THROW(foo(nrow, 0));
137 SHOULD_THROW(foo(0, ncol));
138 SHOULD_THROW(foo(nrow, ncol));
139 SHOULD_THROW(foo(nrow+42, 0));
140 SHOULD_THROW(foo(0, ncol+42));
141 SHOULD_THROW(foo(nrow+42, ncol+42));
147 const unsigned nrow = 3, ncol = 4;
148 const unsigned prow = nrow-1, pcol = ncol-1;
149 const int val = -1, val2 = 42;
152 foo(prow, pcol) = val;
158 for (cit = cfoo.begin(); cit != cfoo.end(); cit++, pos++){
159 if (pos == prow * ncol + pcol){
160 if (*cit != val) { BIASABORT; }
162 if (*cit != val2) { BIASABORT; }
169 for (it = foo.
begin(); it != foo.
end(); it++, ipos++){
172 for (
unsigned r=0; r<nrow; r++){
173 for (
unsigned c=0; c<ncol; c++){
174 if (foo(r,c) != (int)(r*ncol + c)) { BIASABORT; }
180 void TestCompileErrors()
182 const unsigned nrow = 11, ncol = 17;
192 #ifdef TEST_COMPILE_TIME_ERROR_ConstIterator
196 #ifdef TEST_COMPILE_TIME_ERROR_TemplateMismatch
206 const unsigned nr=arg.
nrows(), nc=arg.
ncols();
208 for (r=0; r<nr; r++){
209 for (c=0; c<nc; c++){
const_iterator begin() const
for iterator access todo: derive from std::iterator class(es)
generic two dimensional psarsly populated rectangular array holding arbitrary data types ...
for const_iterator access todo: derive from std::iterator class(es)
const_iterator end() const