diff options
author | Gael Guennebaud <g.gael@free.fr> | 2019-01-22 15:30:50 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2019-01-22 15:30:50 +0100 |
commit | 543529da6a1eabf415f4f8b56495fad76b57ba22 (patch) | |
tree | d02c1d67adaedd9ca25fa096f0b835850dc5df44 | |
parent | 92774f02758d16eff9d6b73611566fd42eb865f4 (diff) |
Add more extensive tests of Array ctors, including {} variants
-rw-r--r-- | test/array_cwise.cpp | 83 | ||||
-rw-r--r-- | test/main.h | 9 |
2 files changed, 77 insertions, 15 deletions
diff --git a/test/array_cwise.cpp b/test/array_cwise.cpp index fbc63a81d..9e4adb701 100644 --- a/test/array_cwise.cpp +++ b/test/array_cwise.cpp @@ -92,15 +92,30 @@ template<typename ArrayType> void array(const ArrayType& m) ArrayType::RowsAtCompileTime==Dynamic?2:ArrayType::RowsAtCompileTime, ArrayType::ColsAtCompileTime==Dynamic?2:ArrayType::ColsAtCompileTime, ArrayType::Options> FixedArrayType; - FixedArrayType f1(s1); - VERIFY_IS_APPROX(f1, FixedArrayType::Constant(s1)); - FixedArrayType f2(numext::real(s1)); - VERIFY_IS_APPROX(f2, FixedArrayType::Constant(numext::real(s1))); - FixedArrayType f3((int)100*numext::real(s1)); - VERIFY_IS_APPROX(f3, FixedArrayType::Constant((int)100*numext::real(s1))); - f1.setRandom(); - FixedArrayType f4(f1.data()); - VERIFY_IS_APPROX(f4, f1); + { + FixedArrayType f1(s1); + VERIFY_IS_APPROX(f1, FixedArrayType::Constant(s1)); + FixedArrayType f2(numext::real(s1)); + VERIFY_IS_APPROX(f2, FixedArrayType::Constant(numext::real(s1))); + FixedArrayType f3((int)100*numext::real(s1)); + VERIFY_IS_APPROX(f3, FixedArrayType::Constant((int)100*numext::real(s1))); + f1.setRandom(); + FixedArrayType f4(f1.data()); + VERIFY_IS_APPROX(f4, f1); + } + #if EIGEN_HAS_CXX11 + { + FixedArrayType f1{s1}; + VERIFY_IS_APPROX(f1, FixedArrayType::Constant(s1)); + FixedArrayType f2{numext::real(s1)}; + VERIFY_IS_APPROX(f2, FixedArrayType::Constant(numext::real(s1))); + FixedArrayType f3{(int)100*numext::real(s1)}; + VERIFY_IS_APPROX(f3, FixedArrayType::Constant((int)100*numext::real(s1))); + f1.setRandom(); + FixedArrayType f4{f1.data()}; + VERIFY_IS_APPROX(f4, f1); + } + #endif // pow VERIFY_IS_APPROX(m1.pow(2), m1.square()); @@ -120,10 +135,51 @@ template<typename ArrayType> void array(const ArrayType& m) // Check possible conflicts with 1D ctor typedef Array<Scalar, Dynamic, 1> OneDArrayType; - OneDArrayType o1(rows); - VERIFY(o1.size()==rows); - OneDArrayType o4((int)rows); - VERIFY(o4.size()==rows); + { + OneDArrayType o1(rows); + VERIFY(o1.size()==rows); + OneDArrayType o2(static_cast<int>(rows)); + VERIFY(o2.size()==rows); + } + #if EIGEN_HAS_CXX11 + { + OneDArrayType o1{rows}; + VERIFY(o1.size()==rows); + OneDArrayType o4{int(rows)}; + VERIFY(o4.size()==rows); + } + #endif + // Check possible conflicts with 2D ctor + typedef Array<Scalar, Dynamic, Dynamic> TwoDArrayType; + typedef Array<Scalar, 2, 1> ArrayType2; + { + TwoDArrayType o1(rows,cols); + VERIFY(o1.rows()==rows); + VERIFY(o1.cols()==cols); + TwoDArrayType o2(static_cast<int>(rows),static_cast<int>(cols)); + VERIFY(o2.rows()==rows); + VERIFY(o2.cols()==cols); + + ArrayType2 o3(rows,cols); + VERIFY(o3(0)==Scalar(rows) && o3(1)==Scalar(cols)); + ArrayType2 o4(static_cast<int>(rows),static_cast<int>(cols)); + VERIFY(o4(0)==Scalar(rows) && o4(1)==Scalar(cols)); + } + #if EIGEN_HAS_CXX11 + { + TwoDArrayType o1{rows,cols}; + VERIFY(o1.rows()==rows); + VERIFY(o1.cols()==cols); + TwoDArrayType o2{int(rows),int(cols)}; + VERIFY(o2.rows()==rows); + VERIFY(o2.cols()==cols); + + ArrayType2 o3{rows,cols}; + VERIFY(o3(0)==Scalar(rows) && o3(1)==Scalar(cols)); + ArrayType2 o4{int(rows),int(cols)}; + VERIFY(o4(0)==Scalar(rows) && o4(1)==Scalar(cols)); + } + #endif } template<typename ArrayType> void comparisons(const ArrayType& m) @@ -467,6 +523,7 @@ EIGEN_DECLARE_TEST(array_cwise) CALL_SUBTEST_4( array(ArrayXXcf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) ); CALL_SUBTEST_5( array(ArrayXXf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) ); CALL_SUBTEST_6( array(ArrayXXi(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) ); + CALL_SUBTEST_6( array(Array<Index,Dynamic,Dynamic>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) ); } for(int i = 0; i < g_repeat; i++) { CALL_SUBTEST_1( comparisons(Array<float, 1, 1>()) ); diff --git a/test/main.h b/test/main.h index a8226ab19..8a68a84ee 100644 --- a/test/main.h +++ b/test/main.h @@ -411,8 +411,6 @@ inline bool test_isApprox(const unsigned short& a, const unsigned short& b) { return internal::isApprox(a, b, test_precision<unsigned short>()); } inline bool test_isApprox(const unsigned int& a, const unsigned int& b) { return internal::isApprox(a, b, test_precision<unsigned int>()); } -inline bool test_isApprox(const long& a, const long& b) -{ return internal::isApprox(a, b, test_precision<long>()); } inline bool test_isApprox(const unsigned long& a, const unsigned long& b) { return internal::isApprox(a, b, test_precision<unsigned long>()); } @@ -423,6 +421,13 @@ inline bool test_isMuchSmallerThan(const int& a, const int& b) inline bool test_isApproxOrLessThan(const int& a, const int& b) { return internal::isApproxOrLessThan(a, b, test_precision<int>()); } +inline bool test_isApprox(const long& a, const long& b) +{ return internal::isApprox(a, b, test_precision<long>()); } +inline bool test_isMuchSmallerThan(const long& a, const long b) +{ return internal::isMuchSmallerThan(a, b, test_precision<long>()); } +inline bool test_isApproxOrLessThan(const long& a, const long& b) +{ return internal::isApproxOrLessThan(a, b, test_precision<long>()); } + inline bool test_isApprox(const float& a, const float& b) { return internal::isApprox(a, b, test_precision<float>()); } inline bool test_isMuchSmallerThan(const float& a, const float& b) |