diff options
author | Gael Guennebaud <g.gael@free.fr> | 2015-09-09 11:38:25 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2015-09-09 11:38:25 +0200 |
commit | 680d318352d0c740992a7e1d6ee5bac766487bbf (patch) | |
tree | b662ab8ff9503c513869162a50b8d4f8657a4b91 | |
parent | 84e0c27b613d5ab70918272027e807e64272d244 (diff) |
Add unit tests for bug #981: valid and invalid usage of ternary operator
-rw-r--r-- | failtest/CMakeLists.txt | 3 | ||||
-rw-r--r-- | failtest/ternary_1.cpp | 13 | ||||
-rw-r--r-- | failtest/ternary_2.cpp | 13 | ||||
-rw-r--r-- | test/basicstuff.cpp | 14 |
4 files changed, 43 insertions, 0 deletions
diff --git a/failtest/CMakeLists.txt b/failtest/CMakeLists.txt index 8df0a7631..1a73f05e6 100644 --- a/failtest/CMakeLists.txt +++ b/failtest/CMakeLists.txt @@ -41,6 +41,9 @@ ei_add_failtest("ref_5") ei_add_failtest("swap_1") ei_add_failtest("swap_2") +ei_add_failtest("ternary_1") +ei_add_failtest("ternary_2") + ei_add_failtest("sparse_ref_1") ei_add_failtest("sparse_ref_2") ei_add_failtest("sparse_ref_3") diff --git a/failtest/ternary_1.cpp b/failtest/ternary_1.cpp new file mode 100644 index 000000000..b40bcb0cc --- /dev/null +++ b/failtest/ternary_1.cpp @@ -0,0 +1,13 @@ +#include "../Eigen/Core" + +using namespace Eigen; + +int main(int argc,char **) +{ + VectorXf a(10), b(10); +#ifdef EIGEN_SHOULD_FAIL_TO_BUILD + b = argc>1 ? 2*a : -a; +#else + b = argc>1 ? 2*a : VectorXf(-a); +#endif +} diff --git a/failtest/ternary_2.cpp b/failtest/ternary_2.cpp new file mode 100644 index 000000000..a46b12b2b --- /dev/null +++ b/failtest/ternary_2.cpp @@ -0,0 +1,13 @@ +#include "../Eigen/Core" + +using namespace Eigen; + +int main(int argc,char **) +{ + VectorXf a(10), b(10); +#ifdef EIGEN_SHOULD_FAIL_TO_BUILD + b = argc>1 ? 2*a : a+a; +#else + b = argc>1 ? VectorXf(2*a) : VectorXf(a+a); +#endif +} diff --git a/test/basicstuff.cpp b/test/basicstuff.cpp index c6bbf19ee..99d91f9da 100644 --- a/test/basicstuff.cpp +++ b/test/basicstuff.cpp @@ -126,6 +126,20 @@ template<typename MatrixType> void basicStuff(const MatrixType& m) for(typename MatrixType::Index i=0;i<rows;++i) sm2.col(i).noalias() -= sm1.row(i); VERIFY_IS_APPROX(sm2,-sm1.transpose()); + + // check ternary usage + { + bool b = internal::random<int>(0,10)>5; + m3 = b ? m1 : m2; + if(b) VERIFY_IS_APPROX(m3,m1); + else VERIFY_IS_APPROX(m3,m2); + m3 = b ? -m1 : m2; + if(b) VERIFY_IS_APPROX(m3,-m1); + else VERIFY_IS_APPROX(m3,m2); + m3 = b ? m1 : -m2; + if(b) VERIFY_IS_APPROX(m3,m1); + else VERIFY_IS_APPROX(m3,-m2); + } } template<typename MatrixType> void basicStuffComplex(const MatrixType& m) |