From 9d318b92c6d5487727d3994c733c9d86186f4204 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Thu, 1 Nov 2018 15:14:50 +0100 Subject: add unit tests for bug #1619 --- test/stl_iterators.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'test/stl_iterators.cpp') 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 bool is_generic_randaccess_stl_iterator(const internal::generic_randaccess_stl_iterator &) { return true; } +template +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 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().end()) ); } + { + check_begin_end_for_loop(v); + check_begin_end_for_loop(v.col(internal::random(0,A.cols()-1))); + check_begin_end_for_loop(v.row(internal::random(0,A.rows()-1))); + } + #if EIGEN_HAS_CXX11 // check swappable { -- cgit v1.2.3