57 template<
class V,
class I>
58 void test_access( V* _v, I begin, I end, std::ostream*
out,
bool* success ) {
66 *out <<
"\nbegin + i == v[i] == v(i+1), for i = 0,1,...,v.dim()\n";
71 *out <<
"\n i, *(begin + i) == v[i] == v(i+1) == ? "
72 <<
"\n--, ------------ ------ ------ ------\n";
73 for( itr = begin, i = 0; itr != end; ++itr, ++i ) {
74 result =
update_success( *itr == v[i] && v[i] == v(i+1), success );
76 *out << setw(2) << i <<
','
82 if(out) *out << std::endl;
87 template<
class V,
class VS>
89 , std::ostream* out,
bool* success )
99 *out <<
"\nv.begin() + i1 == vs.begin() + i2 == vs[i2] == vs(i2+1)"
100 <<
", for i1 = lb-1,..,ub-1, for i2 = 0,..,rng.size()-1\n";
102 typename V::const_iterator itr1;
103 typename VS::const_iterator itr2;
106 *out <<
"\ni1, i2, *(v.begin() + i1) == *(vs.begin() + i2) == vs[i2] == vs(i2+1) == ? "
107 <<
"\n--, --, ----------------- ------------------ ------ -------- ------\n";
108 for( i1 = rng.
lbound()-1, itr1 = v.begin() + i1, i2 = 0, itr2 = vs.begin();
110 ++i1, ++itr1, ++i2, ++itr2 )
112 result =
update_success( *itr1 == *itr2 && *itr2 == vs[i2] && *itr2 == vs(i2+1), success );
114 *out << setw(2) << i1 <<
','
115 << setw(3) << i2 <<
','
118 << setw(12) << vs[i2]
119 << setw(14) << vs(i2+1)
122 if(out) *out << std::endl;
131 return "SOME_OVERLAP";
135 return "Invalid value for EOverLap";
147 bool result, result1, result2;
150 *out <<
"\n**********************************************"
151 <<
"\n*** Testing DVector and DVectorSlice classes ***"
152 <<
"\n**********************************************\n"
158 *out <<
"\nLet vvz[i-1] = i + 0.1*i, for i = 1...,n\n";
162 std::vector<DVector::value_type> vvz(6);
163 {
for(
int i = 1; i <= n; ++i)
164 vvz[i-1] = i + 0.1 * i;
167 if(out) *out <<
"\nLet alpha1 = 22.5\n";
174 *out <<
"\n***\n*** Testing constructors\n***\n";
178 if(out) *out <<
"\nVectorSlice vs1\n";
180 if(out) *out <<
"vs1 =\n" << vs1;
182 if(out) *out <<
"\nVectorSlice vs2(vvz.begin(),n)\n";
184 if(out) *out <<
"vs2 =\n" << vs2;
186 if(out) *out <<
"\nVectorSlice vs3(vvz.begin(),n,Range1D())\n";
188 if(out) *out <<
"vs3 =\n" << vs3;
190 if(out) *out <<
"\nVectorSlice vs4(vs3,Range1D())\n";
192 if(out) *out <<
"vs4 =\n" << vs4;
196 if(out) *out <<
"\nVector v1\n";
198 if(out) *out <<
"v1 =\n" << v1;
200 if(out) *out <<
"\nVector v2(alpha1,n)\n";
202 if(out) *out <<
"v2 =\n" << v2;
204 if(out) *out <<
"\nVector v3(vvz.begin(),n)\n";
206 if(out) *out <<
"v3 =\n" << v3;
208 if(out) *out <<
"\nVector v4(vs4)\n";
210 if(out) *out <<
"v4 =\n" << v4;
216 *out <<
"\n***\n*** Testing DVectorSlice binding and "
217 "conversion from DVector -> DVectorSlice\n***\n"
218 <<
"\nvs1.bind(v2());\n";
220 if(out) *out <<
"vs1 =\n" << vs1;
226 *out <<
"\n***\n*** Testing DVector resizing\n***\n"
229 if(out) *out <<
"v2.dim() == 0 : " <<
update_success( v2.dim() == 0, &success ) << std::endl;
232 *out <<
"\nv2.resize(n,2*alpha1);\n";
233 v2.resize(n,2*alpha1);
237 *out <<
"( (v2.dim() -> " << v2.dim() <<
") == n && "
238 <<
"(comp(v2,2*alpha1) -> " << result2 <<
") ) : " << (result1 && result2) << std::endl
244 if(out) *out <<
"\n***\n*** Testing Iterator Access, Subscriping and Reverse VectorSlices\n***\n";
247 *out <<
"\nLet v == v3, begin = v.begin()";
248 test_access(&v3,v3.begin(),v3.end(),
out,&success);
251 *out <<
"\nLet v == const_cast<const DVector&>(v3), begin = v.begin()";
252 test_access(&const_cast<const DVector&>(v3),const_cast<const DVector&>(v3).begin()
253 ,const_cast<const DVector&>(v3).end(),out,&success);
256 *out <<
"\nLet v == vs3, begin = v.begin()";
257 test_access(&vs3,vs3.begin(),vs3.end(),
out,&success);
260 *out <<
"\nLet v == const_cast<const DVectorSlice&>(vs3), begin = v.begin()";
261 test_access(&const_cast<const DVectorSlice&>(vs3),const_cast<const DVectorSlice&>(vs3).begin()
262 ,const_cast<const DVectorSlice&>(vs3).end(),out,&success);
265 *out <<
"\nLet v == v3.rev(), begin = v3.rbegin()";
266 test_access(&v3.rev(),v3.rbegin(),v3.rend(),
out,&success);
269 *out <<
"\nLet v == const_cast<const DVector&>(v3).rev(), begin = const_cast<const DVector&>(v3).rbegin()";
270 test_access(&const_cast<const DVector&>(v3).rev(),const_cast<const DVector&>(v3).rbegin()
271 ,const_cast<const DVector&>(v3).rend(),out,&success);
274 *out <<
"\nLet v == vs3.rev(), begin = vs3.rbegin()";
275 test_access(&vs3.rev(),vs3.rbegin(),vs3.rend(),
out,&success);
278 *out <<
"\nLet v == const_cast<const DVectorSlice&>(vs3).rev()"
279 ", begin = const_cast<const DVectorSlice&>(vs3).rbegin()";
280 test_access(&const_cast<const DVectorSlice&>(vs3).rev(),const_cast<const DVectorSlice&>(vs3).rbegin()
281 ,const_cast<const DVectorSlice&>(vs3).rend(),out,&success);
283 #ifdef LINALGPACK_CHECK_RANGE
285 if(out) *out <<
"\n*** Test subscriping out of bounds\n";
287 if(out) *out <<
"\nv3(0); (should throw std::out_of_range)\n";
292 catch(
const std::out_of_range&) {
295 if(out) *out <<
"v3(0) threw std::out_of_range : " << result << std::endl;
298 if(out) *out <<
"\nv3(n+1); (should throw std::out_of_range)\n";
303 catch(
const std::out_of_range&) {
306 if(out) *out <<
"v3(n+1) threw std::out_of_range : " << result << std::endl;
309 if(out) *out <<
"\nvs3(0); (should throw std::out_of_range)\n";
314 catch(
const std::out_of_range &) {
317 if(out) *out <<
"vs3(0) threw std::out_of_range : " << result << std::endl;
320 if(out) *out <<
"\nvs3(n+1); (should throw std::out_of_range)\n";
325 catch(
const std::out_of_range&) {
328 if(out) *out <<
"vs3(n+1) threw std::out_of_range : " << result << std::endl;
336 if(out) *out <<
"\n***\n*** Testing Subregion Access\n***\n";
341 if(out) *out <<
"\nv = v3, rng = [1,n/2], vs = v(rng)";
343 test_subregion_access( &v3, &v3(rng), rng, out, &success );
345 if(out) *out <<
"\nv = v3, rng = [n/3,2*n/3], vs = v(rng)";
347 test_subregion_access( &v3, &v3(rng), rng, out, &success );
349 if(out) *out <<
"\nv = v3, rng = [n/2,n], vs = v(rng)";
351 test_subregion_access( &v3, &v3(rng), rng, out, &success );
353 if(out) *out <<
"\nv = const_cast<const DVector&>(v3), rng = [n/2,n], vs = v(rng)";
355 test_subregion_access( &v3, &const_cast<const DVector&>(v3)(rng), rng, out, &success );
357 if(out) *out <<
"\nv = v3, rng = [1,n/2], vs = v(1,n/2)";
359 test_subregion_access( &v3, &v3(1,n/2), rng, out, &success );
361 if(out) *out <<
"\nv = const_cast<const DVector&>(v3), rng = [n/2,n], vs = v(n/2,n)";
363 test_subregion_access( &v3, &const_cast<const DVector&>(v3)(n/2,n), rng, out, &success );
367 if(out) *out <<
"\nv = vs3, rng = [1,n/2], vs = v(rng)";
369 test_subregion_access( &vs3, &vs3(rng), rng, out, &success );
371 if(out) *out <<
"\nv = vs3, rng = [n/3,2*n/3], vs = v(rng)";
373 test_subregion_access( &vs3, &vs3(rng), rng, out, &success );
375 if(out) *out <<
"\nv = vs3, rng = [n/2,n], vs = v(rng)";
377 test_subregion_access( &vs3, &vs3(rng), rng, out, &success );
379 if(out) *out <<
"\nv = const_cast<const DVectorSlice&>(vs3), rng = [n/2,n], vs = v(rng)";
381 test_subregion_access( &vs3, &const_cast<const DVectorSlice&>(vs3)(rng), rng, out, &success );
383 if(out) *out <<
"\nv = vs3, rng = [1,n/2], vs = v(1,n/2)";
385 test_subregion_access( &vs3, &vs3(1,n/2), rng, out, &success );
387 if(out) *out <<
"\nv = const_cast<const DVectorSlice&>(vs3), rng = [n/2,n], vs = v(n/2,n)";
389 test_subregion_access( &vs3, &const_cast<const DVectorSlice&>(vs3)(n/2,n), rng, out, &success );
394 if(out) *out <<
"\n***\n*** Testing assignment operators\n***\n";
398 if(out) *out <<
"\nv1.resize(n); v1 = 0.0;\n";
403 *out <<
"v1 =\n" << v1
404 <<
"v1 == 0.0 : " << result << std::endl;
406 if(out) *out <<
"\nv1 = 0.0; v1 = vs3;\n";
411 *out <<
"v1 =\n" << v1
412 <<
"v1 == vs3 : " << result << std::endl;
414 if(out) *out <<
"\nv1 = 0.0; v1 = v3;\n";
419 *out <<
"v1 =\n" << v1
420 <<
"v1 == v3 : " << result << std::endl;
424 if(out) *out <<
"\nv1.resize(n); v1 = 0.0; vs1.bind(v1());\n";
429 if(out) *out <<
"\nvs1 = alpha1;\n";
433 *out <<
"vs1 =\n" << v1
434 <<
"vs1 == alpha1 : " << result << std::endl;
436 if(out) *out <<
"\nvs1 = 0.0; vs1 = vs3;\n";
441 *out <<
"vs1 =\n" << vs1
442 <<
"vs1 == vs3 : " << result << std::endl;
447 if(out) *out <<
"\n***\n*** Testing overlap\n***\n";
453 if(out) *out <<
"\n*** DVector overlap\n";
455 if(out) *out <<
"(v1.overlap(v3) -> ";
456 ovlap = v1.overlap(v3);
458 if(out) *out << overlap_str(ovlap) <<
") == NO_OVERLAP : " << result << std::endl;
460 if(out) *out <<
"(v3.overlap(v3) -> ";
461 ovlap = v3.overlap(v3);
463 if(out) *out << overlap_str(ovlap) <<
") == SAME_MEM : " << result << std::endl;
465 if(out) *out <<
"(v3.overlap(v3(1,n-1)) -> ";
466 ovlap = v3.overlap(v3(1,n-1));
468 if(out) *out << overlap_str(ovlap) <<
") == SOME_OVERLAP : " << result << std::endl;
470 if(out) *out <<
"(v3.overlap(v3(2,n-1)) -> ";
471 ovlap = v3.overlap(v3(2,n-1));
473 if(out) *out << overlap_str(ovlap) <<
") == SOME_OVERLAP : " << result << std::endl;
477 if(out) *out <<
"\n*** DVectorSlice overlap\n"
478 <<
"vs1.bind(v3());\n";
482 if(out) *out <<
"(vs1.overlap(v2) -> ";
483 ovlap = vs1.overlap(v2);
485 if(out) *out << overlap_str(ovlap) <<
") == NO_OVERLAP : " << result << std::endl;
487 if(out) *out <<
"(vs1.overlap(vs1) -> ";
488 ovlap = vs1.overlap(vs1);
490 if(out) *out << overlap_str(ovlap) <<
") == SAME_MEM : " << result << std::endl;
492 if(out) *out <<
"(vs1(1,n/2).overlap(vs1(n/2+1,n)) -> ";
493 ovlap = vs1(1,n/2).overlap(vs1(n/2+1,n));
495 if(out) *out << overlap_str(ovlap) <<
") == NO_OVERLAP : " << result << std::endl;
497 if(out) *out <<
"(vs1(1,n/2).overlap(vs1(n/3,2*n/3)) -> ";
498 ovlap = vs1(1,n/2).overlap(vs1(n/3,2*n/3));
500 if(out) *out << overlap_str(ovlap) <<
") == SOME_OVERLAP : " << result << std::endl;
502 if(out) *out <<
"(vs1(n/3,2*n/3).overlap(vs1(n/2+1,n)) -> ";
503 ovlap = vs1(n/3,2*n/3).overlap(vs1(n/2+1,n));
505 if(out) *out << overlap_str(ovlap) <<
") == SOME_OVERLAP : " << result << std::endl;
507 if(out) *out <<
"(vs1(n/3,2*n/3).overlap(vs1(n/3,2*n/3)) -> ";
508 ovlap = vs1(n/3,2*n/3).overlap(vs1(n/3,2*n/3));
510 if(out) *out << overlap_str(ovlap) <<
") == SAME_MEM : " << result << std::endl;
513 catch(
const std::exception& excpt ) {
516 (*out) <<
"\nError, a standard exception was thrown: "
518 << excpt.what() << std::endl;
523 (*out) <<
"\nError, an unknown exception was thrown\n";
529 <<
"\n*** Congradulations, DVector and DVectorSlice seem to check out. ***\n";
532 <<
"\n*** Oops, all of the tests for DVector and DVectorSlice "
533 "where not successful. ***\n";
std::string typeName(const T &t)
Index size() const
Return the size of the range (ubound() - lbound() + 1)
. One-based subregion index range class.
const value_type sqrt_eps
EOverLap
Enumeration for returning the amount of overlap between two objects.
DenseLinAlgPack::size_type size_type
Index lbound() const
Return lower bound of the range.
FortranTypes::f_dbl_prec value_type
Typedef for the value type of elements that is used for the library.
bool update_success(bool result_check, bool *success)
Helper function for updating a flag for if an operation returned false.
bool comp(const DVectorSlice &vs1, const DVectorSlice &vs2)
bool TestVectorClass(std::ostream *out)
RangePack::Range1D Range1D