diff options
author | Gael Guennebaud <g.gael@free.fr> | 2018-11-01 15:14:50 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2018-11-01 15:14:50 +0100 |
commit | 9d318b92c6d5487727d3994c733c9d86186f4204 (patch) | |
tree | b562cc9ba03ee9a2d9cafcdb81f299611fbfd7c1 /test/stl_iterators.cpp | |
parent | 8d7a73e48e82b41f8e8b90afb434c98452556990 (diff) |
add unit tests for bug #1619
Diffstat (limited to 'test/stl_iterators.cpp')
-rw-r--r-- | test/stl_iterators.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/test/stl_iterators.cpp b/test/stl_iterators.cpp index 6cc31a3ef..ff89ec6ee 100644 --- a/test/stl_iterators.cpp +++ b/test/stl_iterators.cpp @@ -46,6 +46,50 @@ bool is_pointer_based_stl_iterator(const internal::pointer_based_stl_iterator<Xp template<typename XprType> bool is_generic_randaccess_stl_iterator(const internal::generic_randaccess_stl_iterator<XprType> &) { return true; } +template<typename Xpr> +void check_begin_end_for_loop(Xpr xpr) +{ + const Xpr& cxpr(xpr); + Index i = 0; + + i = 0; + for(typename Xpr::iterator it = xpr.begin(); it!=xpr.end(); ++it) { VERIFY_IS_EQUAL(*it,xpr[i++]); } + + i = 0; + for(typename Xpr::const_iterator it = xpr.cbegin(); it!=xpr.cend(); ++it) { VERIFY_IS_EQUAL(*it,xpr[i++]); } + + i = 0; + for(typename Xpr::const_iterator it = cxpr.begin(); it!=cxpr.end(); ++it) { VERIFY_IS_EQUAL(*it,xpr[i++]); } + + // Needs to be uncommented while fixing bug 1619 + // i = 0; + // for(typename Xpr::const_iterator it = xpr.begin(); it!=xpr.end(); ++it) { VERIFY_IS_EQUAL(*it,xpr[i++]); } + + if(xpr.size()>0) { + VERIFY(xpr.begin() != xpr.end()); + VERIFY(xpr.begin() < xpr.end()); + VERIFY(xpr.begin() <= xpr.end()); + VERIFY(!(xpr.begin() == xpr.end())); + VERIFY(!(xpr.begin() < xpr.end())); + VERIFY(!(xpr.begin() <= xpr.end())); + + // Needs to be uncommented while fixing bug 1619 + // VERIFY(xpr.cbegin() != xpr.end()); + // VERIFY(xpr.cbegin() < xpr.end()); + // VERIFY(xpr.cbegin() <= xpr.end()); + // VERIFY(!(xpr.cbegin() == xpr.end())); + // VERIFY(!(xpr.cbegin() < xpr.end())); + // VERIFY(!(xpr.cbegin() <= xpr.end())); + + // VERIFY(xpr.begin() != xpr.cend()); + // VERIFY(xpr.begin() < xpr.cend()); + // VERIFY(xpr.begin() <= xpr.cend()); + // VERIFY(!(xpr.begin() == xpr.cend())); + // VERIFY(!(xpr.begin() < xpr.cend())); + // VERIFY(!(xpr.begin() <= xpr.cend())); + } +} + template<typename Scalar, int Rows, int Cols> void test_stl_iterators(int rows=Rows, int cols=Cols) { @@ -94,6 +138,12 @@ void test_stl_iterators(int rows=Rows, int cols=Cols) VERIFY( is_generic_randaccess_stl_iterator(A.template reshaped<RowMajor>().end()) ); } + { + check_begin_end_for_loop(v); + check_begin_end_for_loop(v.col(internal::random<Index>(0,A.cols()-1))); + check_begin_end_for_loop(v.row(internal::random<Index>(0,A.rows()-1))); + } + #if EIGEN_HAS_CXX11 // check swappable { |