Skip to content

Commit

Permalink
Add unit tests for bug 981: valid and invalid usage of ternary operator
Browse files Browse the repository at this point in the history
  • Loading branch information
ggael committed Sep 9, 2015
1 parent 5da9d90 commit 0a2526c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions failtest/CMakeLists.txt
Expand Up @@ -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")
Expand Down
13 changes: 13 additions & 0 deletions 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
}
13 changes: 13 additions & 0 deletions 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
}
14 changes: 14 additions & 0 deletions test/basicstuff.cpp
Expand Up @@ -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)
Expand Down

0 comments on commit 0a2526c

Please sign in to comment.