From c08521ea6b1a5b239c22771f7735d7f4904b4854 Mon Sep 17 00:00:00 2001 From: Hauke Heibel Date: Wed, 7 Mar 2012 16:18:35 +0100 Subject: [PATCH] Improved the unit tests for setLinSpaced. Provide a default constructed step size as opposed to an int when the size is 1. --- Eigen/src/Core/Functors.h | 2 +- test/nullary.cpp | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Eigen/src/Core/Functors.h b/Eigen/src/Core/Functors.h index 1d641b19f..440eeb8e3 100644 --- a/Eigen/src/Core/Functors.h +++ b/Eigen/src/Core/Functors.h @@ -628,7 +628,7 @@ template struct functor_traits< linspaced_o template struct linspaced_op { typedef typename packet_traits::type Packet; - linspaced_op(Scalar low, Scalar high, int num_steps) : impl((num_steps==1 ? high : low), (num_steps==1 ? 1 : (high-low)/(num_steps-1))) {} + linspaced_op(Scalar low, Scalar high, int num_steps) : impl((num_steps==1 ? high : low), (num_steps==1 ? Scalar() : (high-low)/(num_steps-1))) {} template EIGEN_STRONG_INLINE const Scalar operator() (Index i) const { return impl(i); } diff --git a/test/nullary.cpp b/test/nullary.cpp index 501b579b0..6c9ee5f34 100644 --- a/test/nullary.cpp +++ b/test/nullary.cpp @@ -52,11 +52,14 @@ void testVectorType(const VectorType& base) { typedef typename internal::traits::Index Index; typedef typename internal::traits::Scalar Scalar; - Scalar low = internal::random(-500,500); - Scalar high = internal::random(-500,500); - if (low>high) std::swap(low,high); + const Index size = base.size(); - const Scalar step = (high-low)/(size-1); + + Scalar high = internal::random(-500,500); + Scalar low = (size == 1 ? high : internal::random(-500,500)); + if (low>high) std::swap(low,high); + + const Scalar step = ((size == 1) ? 1 : (high-low)/(size-1)); // check whether the result yields what we expect it to do VectorType m(base); @@ -130,5 +133,6 @@ void test_nullary() CALL_SUBTEST_6( testVectorType(Vector3d()) ); CALL_SUBTEST_7( testVectorType(VectorXf(internal::random(1,300))) ); CALL_SUBTEST_8( testVectorType(Vector3f()) ); + CALL_SUBTEST_8( testVectorType(Matrix()) ); } }