From 37e29fc89389ff1514315b1cf96a8253e0b5c69d Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 2 Oct 2018 13:29:32 +0200 Subject: Use Index instead of ptrdiff_t or int, fix random-accessors. --- test/stl_iterators.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'test/stl_iterators.cpp') diff --git a/test/stl_iterators.cpp b/test/stl_iterators.cpp index 1ed52b354..f56209f07 100644 --- a/test/stl_iterators.cpp +++ b/test/stl_iterators.cpp @@ -59,6 +59,16 @@ void test_range_for_loop(int rows=Rows, int cols=Cols) VERIFY_IS_EQUAL(v,w); #endif + if(rows>=3) { + VERIFY_IS_EQUAL((v.begin()+rows/2)[1], v(rows/2+1)); + + VERIFY_IS_EQUAL((A.allRows().begin()+rows/2)[1], A.row(rows/2+1)); + } + + if(cols>=3) { + VERIFY_IS_EQUAL((A.allCols().begin()+cols/2)[1], A.col(cols/2+1)); + } + if(rows>=2) { v(1) = v(0)-Scalar(1); @@ -84,11 +94,27 @@ void test_range_for_loop(int rows=Rows, int cols=Cols) j = internal::random(0,A.cols()-1); typename ColMatrixType::ColXpr Acol = A.col(j); std::partial_sum(begin(Acol), end(Acol), begin(v)); - VERIFY_IS_APPROX(v(seq(1,last)), v(seq(0,last-1))+Acol(seq(1,last))); + VERIFY_IS_EQUAL(v(seq(1,last)), v(seq(0,last-1))+Acol(seq(1,last))); // inplace std::partial_sum(begin(Acol), end(Acol), begin(Acol)); - VERIFY_IS_APPROX(v, Acol); + VERIFY_IS_EQUAL(v, Acol); + } + + if(rows>=3) + { + // stress random access + v.setRandom(); + VectorType v1 = v; + std::sort(begin(v1),end(v1)); + std::nth_element(v.begin(), v.begin()+rows/2, v.end()); + VERIFY_IS_APPROX(v1(rows/2), v(rows/2)); + + v.setRandom(); + v1 = v; + std::sort(begin(v1)+rows/2,end(v1)); + std::nth_element(v.begin()+rows/2, v.begin()+rows/4, v.end()); + VERIFY_IS_APPROX(v1(rows/4), v(rows/4)); } #if EIGEN_HAS_CXX11 -- cgit v1.2.3