Skip to content

Commit

Permalink
test: Fix compile error for clang in unit tests
Browse files Browse the repository at this point in the history
value_diff functions must be defined before they are used in the macros.
  • Loading branch information
Zack Moratto committed May 3, 2012
1 parent ad71c7e commit 6ef8b98
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 85 deletions.
90 changes: 46 additions & 44 deletions src/test/Helpers.h
Expand Up @@ -88,6 +88,52 @@ void mismatch_queue(InputIterator1 first1, InputIterator1 last1, InputIterator2
} }
} }


// Difference calculators
template <typename ElemT, typename Elem2T>
double value_diff(const vw::PixelMathBase<ElemT>& a, const vw::PixelMathBase<Elem2T>& b) {
BOOST_STATIC_ASSERT((boost::is_same<ElemT, Elem2T>::value));
typedef typename CompoundChannelType<ElemT>::type channel_type;
double acc = 0.0;
for( size_t c=0; c < PixelNumChannels<ElemT>::value; ++c ) {
channel_type const& a_x = compound_select_channel<channel_type const&>(a.impl(),c);
channel_type const& b_x = compound_select_channel<channel_type const&>(b.impl(),c);
double diff = double(a_x) - double(b_x);
acc += diff*diff;
}
return ::sqrt(acc);
}

template <typename Vec1T, typename Vec2T>
double value_diff(const vw::VectorBase<Vec1T>& a, const vw::VectorBase<Vec2T>& b) {
BOOST_STATIC_ASSERT((boost::is_same<typename Vec1T::value_type,typename Vec2T::value_type>::value));
double acc = 0.0;
typename Vec2T::const_iterator it2 = b.impl().begin();
for (typename Vec1T::const_iterator it1 = a.impl().begin();
it1 != a.impl().end(); it1++ ) {
double diff = double(*it1) - double(*it2);
acc += diff*diff;
it2++;
}
return ::sqrt(acc);
}

template <typename T1, typename T2>
double value_diff(const std::complex<T1>& a, const std::complex<T2>& b) {
return std::abs(std::complex<double>(a) - std::complex<double>(b));
}

template <typename T1, typename T2>
struct both_are_arithmetic : boost::mpl::and_<boost::is_arithmetic<T1>, boost::is_arithmetic<T2> > {};

template <typename T1, typename T2>
typename boost::enable_if<both_are_arithmetic<T1,T2>, double>::type
value_diff(const T1& a, const T2& b) {
BOOST_STATIC_ASSERT(boost::is_arithmetic<T1>::value);
BOOST_STATIC_ASSERT(boost::is_arithmetic<T2>::value);
return ::fabs(double(a) - double(b));
}

// Comparison classes
template <typename ImplT> template <typename ImplT>
class CmpWorker { class CmpWorker {
public: public:
Expand Down Expand Up @@ -416,50 +462,6 @@ _CheckNDRange<CmpT> check_nd_range(const CmpT& cmp) {
#define EXPECT_MATRIX_NEAR(e, a, delta) EXPECT_SEQ_NEAR(e,a,delta) #define EXPECT_MATRIX_NEAR(e, a, delta) EXPECT_SEQ_NEAR(e,a,delta)
#define ASSERT_MATRIX_NEAR(e, a, delta) ASSERT_SEQ_NEAR(e,a,delta) #define ASSERT_MATRIX_NEAR(e, a, delta) ASSERT_SEQ_NEAR(e,a,delta)


template <typename ElemT, typename Elem2T>
double value_diff(const vw::PixelMathBase<ElemT>& a, const vw::PixelMathBase<Elem2T>& b) {
BOOST_STATIC_ASSERT((boost::is_same<ElemT, Elem2T>::value));
typedef typename CompoundChannelType<ElemT>::type channel_type;
double acc = 0.0;
for( size_t c=0; c < PixelNumChannels<ElemT>::value; ++c ) {
channel_type const& a_x = compound_select_channel<channel_type const&>(a.impl(),c);
channel_type const& b_x = compound_select_channel<channel_type const&>(b.impl(),c);
double diff = double(a_x) - double(b_x);
acc += diff*diff;
}
return ::sqrt(acc);
}

template <typename Vec1T, typename Vec2T>
double value_diff(const vw::VectorBase<Vec1T>& a, const vw::VectorBase<Vec2T>& b) {
BOOST_STATIC_ASSERT((boost::is_same<typename Vec1T::value_type,typename Vec2T::value_type>::value));
double acc = 0.0;
typename Vec2T::const_iterator it2 = b.impl().begin();
for (typename Vec1T::const_iterator it1 = a.impl().begin();
it1 != a.impl().end(); it1++ ) {
double diff = double(*it1) - double(*it2);
acc += diff*diff;
it2++;
}
return ::sqrt(acc);
}

template <typename T1, typename T2>
double value_diff(const std::complex<T1>& a, const std::complex<T2>& b) {
return std::abs(std::complex<double>(a) - std::complex<double>(b));
}

template <typename T1, typename T2>
struct both_are_arithmetic : boost::mpl::and_<boost::is_arithmetic<T1>, boost::is_arithmetic<T2> > {};

template <typename T1, typename T2>
typename boost::enable_if<both_are_arithmetic<T1,T2>, double>::type
value_diff(const T1& a, const T2& b) {
BOOST_STATIC_ASSERT(boost::is_arithmetic<T1>::value);
BOOST_STATIC_ASSERT(boost::is_arithmetic<T2>::value);
return ::fabs(double(a) - double(b));
}

}} // namespace t }} // namespace t


#endif #endif
2 changes: 0 additions & 2 deletions src/vw/Core/tests/TestExceptions.cxx
Expand Up @@ -5,8 +5,6 @@
// __END_LICENSE__ // __END_LICENSE__




#include <gtest/gtest_VW.h>

#include <vw/Core/Exception.h> #include <vw/Core/Exception.h>
#include <test/Helpers.h> #include <test/Helpers.h>


Expand Down
1 change: 0 additions & 1 deletion src/vw/Core/tests/TestSettings.cxx
Expand Up @@ -9,7 +9,6 @@
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>


#include <gtest/gtest_VW.h>
#include <vw/Core/Settings.h> #include <vw/Core/Settings.h>
#include <vw/Core/ConfigParser.h> #include <vw/Core/ConfigParser.h>
#include <test/Helpers.h> #include <test/Helpers.h>
Expand Down
2 changes: 0 additions & 2 deletions src/vw/Core/tests/TestTypeDeduction.cxx
Expand Up @@ -4,8 +4,6 @@
// All Rights Reserved. // All Rights Reserved.
// __END_LICENSE__ // __END_LICENSE__



#include <gtest/gtest_VW.h>
#include <test/Helpers.h> #include <test/Helpers.h>
#include <vw/Core/TypeDeduction.h> #include <vw/Core/TypeDeduction.h>


Expand Down
2 changes: 0 additions & 2 deletions src/vw/Image/tests/TestBlockRasterize.cxx
Expand Up @@ -4,8 +4,6 @@
// All Rights Reserved. // All Rights Reserved.
// __END_LICENSE__ // __END_LICENSE__



#include <gtest/gtest_VW.h>
#include <test/Helpers.h> #include <test/Helpers.h>
#include <vw/Image/BlockRasterize.h> #include <vw/Image/BlockRasterize.h>


Expand Down
2 changes: 0 additions & 2 deletions src/vw/Image/tests/TestImageView.cxx
Expand Up @@ -4,8 +4,6 @@
// All Rights Reserved. // All Rights Reserved.
// __END_LICENSE__ // __END_LICENSE__



#include <gtest/gtest_VW.h>
#include <test/Helpers.h> #include <test/Helpers.h>


#include <vw/Image/ImageView.h> #include <vw/Image/ImageView.h>
Expand Down
2 changes: 0 additions & 2 deletions src/vw/Image/tests/TestImageViewMemory.cxx
Expand Up @@ -4,8 +4,6 @@
// All Rights Reserved. // All Rights Reserved.
// __END_LICENSE__ // __END_LICENSE__



#include <gtest/gtest_VW.h>
#include <test/Helpers.h> #include <test/Helpers.h>
#include <vw/Image/ImageView.h> #include <vw/Image/ImageView.h>


Expand Down
10 changes: 4 additions & 6 deletions src/vw/Image/tests/TestMaskViews.cxx
Expand Up @@ -98,10 +98,9 @@ TYPED_TEST( MaskedViewTest, copy_mask ) {


// Test a copy mask where the input is a different channel type // Test a copy mask where the input is a different channel type
ImageView< PixelRGB<uint8> > in_rgbu8(2,2); ImageView< PixelRGB<uint8> > in_rgbu8(2,2);
in(0,0) = PixelRGB<uint8>(9); in(1,0) = PixelRGB<uint8>(8); in_rgbu8(0,0) = PixelRGB<uint8>(9); in_rgbu8(1,0) = PixelRGB<uint8>(8);
in(0,1) = PixelRGB<uint8>(1); in(1,1) = PixelRGB<uint8>(4); in_rgbu8(0,1) = PixelRGB<uint8>(1); in_rgbu8(1,1) = PixelRGB<uint8>(4);
ImageView<PixelMask<PixelRGB<uint8> > > out_rgbu8 = ImageView<PixelMask<PixelRGB<uint8> > > out_rgbu8 = copy_mask( in_rgbu8, this->a );
copy_mask( in_rgbu8, this->a );
EXPECT_EQ( 2, out_rgbu8.cols() ); EXPECT_EQ( 2, out_rgbu8.rows() ); EXPECT_EQ( 2, out_rgbu8.cols() ); EXPECT_EQ( 2, out_rgbu8.rows() );
EXPECT_TRUE( is_valid(out_rgbu8(0,0)) ); EXPECT_TRUE( is_valid(out_rgbu8(0,0)) );
EXPECT_TRUE( is_valid(out_rgbu8(1,0)) ); EXPECT_TRUE( is_valid(out_rgbu8(1,0)) );
Expand All @@ -115,7 +114,7 @@ TYPED_TEST( MaskedViewTest, copy_mask ) {
mask(0,1) = PixelMask<uint8>(255); mask(1,1) = PixelMask<uint8>(); mask(0,1) = PixelMask<uint8>(255); mask(1,1) = PixelMask<uint8>();
c = copy_mask(in, mask); c = copy_mask(in, mask);
EXPECT_EQ( 2, c.cols() ); EXPECT_EQ( 2, c.rows() ); EXPECT_EQ( 2, c.cols() ); EXPECT_EQ( 2, c.rows() );
EXPECT_FALSE is_valid(c(0,0)) ); EXPECT_FALSE( is_valid(c(0,0)) );
EXPECT_TRUE( is_valid(c(1,0)) ); EXPECT_TRUE( is_valid(c(1,0)) );
EXPECT_TRUE( is_valid(c(0,1)) ); EXPECT_TRUE( is_valid(c(0,1)) );
EXPECT_FALSE(is_valid(c(1,1)) ); EXPECT_FALSE(is_valid(c(1,1)) );
Expand Down Expand Up @@ -253,5 +252,4 @@ TYPED_TEST( MaskedViewTest, create_apply_mask ) {
EXPECT_EQ( typename TestFixture::Px(2), e(1,0) ); EXPECT_EQ( typename TestFixture::Px(2), e(1,0) );
EXPECT_EQ( typename TestFixture::Px(3), e(0,1) ); EXPECT_EQ( typename TestFixture::Px(3), e(0,1) );
EXPECT_EQ( typename TestFixture::Px(4), e(1,1) ); EXPECT_EQ( typename TestFixture::Px(4), e(1,1) );

} }
24 changes: 12 additions & 12 deletions src/vw/Image/tests/TestPixelMath.cxx
Expand Up @@ -125,29 +125,29 @@ TEST( PixelMath, SelfAssignment ) {
typedef PixelRGB<uint8> Px; typedef PixelRGB<uint8> Px;
Px a(1,2,3), b(2,3,4); Px a(1,2,3), b(2,3,4);
a += 2; a += 2;
ASSERT_PIXEL_EQ( a, Px(3,4,5) ); EXPECT_VW_EQ( a, Px(3,4,5) );
a -= 2; a -= 2;
ASSERT_PIXEL_EQ( a, Px(1,2,3) ); EXPECT_VW_EQ( a, Px(1,2,3) );
a *= 2; a *= 2;
ASSERT_PIXEL_EQ( a, Px(2,4,6) ); EXPECT_VW_EQ( a, Px(2,4,6) );
a /= 2; a /= 2;
ASSERT_PIXEL_EQ( a, Px(1,2,3) ); EXPECT_VW_EQ( a, Px(1,2,3) );
a += b; a += b;
ASSERT_PIXEL_EQ( a, Px(3,5,7) ); EXPECT_VW_EQ( a, Px(3,5,7) );
a -= b; a -= b;
ASSERT_PIXEL_EQ( a, Px(1,2,3) ); EXPECT_VW_EQ( a, Px(1,2,3) );
a *= b; a *= b;
ASSERT_PIXEL_EQ( a, Px(2,6,12) ); EXPECT_VW_EQ( a, Px(2,6,12) );
a /= b; a /= b;
ASSERT_PIXEL_EQ( a, Px(1,2,3) ); EXPECT_VW_EQ( a, Px(1,2,3) );
(a += 2) += 2; (a += 2) += 2;
ASSERT_PIXEL_EQ( a, Px(5,6,7) ); EXPECT_VW_EQ( a, Px(5,6,7) );
(a -= 2) -= 2; (a -= 2) -= 2;
ASSERT_PIXEL_EQ( a, Px(1,2,3) ); EXPECT_VW_EQ( a, Px(1,2,3) );
(a *= 2) *= 2; (a *= 2) *= 2;
ASSERT_PIXEL_EQ( a, Px(4,8,12) ); EXPECT_VW_EQ( a, Px(4,8,12) );
(a /= 2) /= 2; (a /= 2) /= 2;
ASSERT_PIXEL_EQ( a, Px(1,2,3) ); EXPECT_VW_EQ( a, Px(1,2,3) );
} }


TEST( PixelMath, ACOS ) { TEST_UNARY_MATH_FUNCTION(acos,0.5,1.0472); } TEST( PixelMath, ACOS ) { TEST_UNARY_MATH_FUNCTION(acos,0.5,1.0472); }
Expand Down
2 changes: 0 additions & 2 deletions src/vw/Image/tests/TestTransform.cxx
Expand Up @@ -4,8 +4,6 @@
// All Rights Reserved. // All Rights Reserved.
// __END_LICENSE__ // __END_LICENSE__



#include <gtest/gtest_VW.h>
#include <test/Helpers.h> #include <test/Helpers.h>


#include <vw/Image/ImageView.h> #include <vw/Image/ImageView.h>
Expand Down
1 change: 0 additions & 1 deletion src/vw/Math/tests/TestEuler.cxx
Expand Up @@ -6,7 +6,6 @@




#include <cmath> #include <cmath>
#include <gtest/gtest_VW.h>
#include <vw/Math/EulerAngles.h> #include <vw/Math/EulerAngles.h>
#include <test/Helpers.h> #include <test/Helpers.h>


Expand Down
2 changes: 0 additions & 2 deletions src/vw/Math/tests/TestGeometry.cxx
Expand Up @@ -4,8 +4,6 @@
// All Rights Reserved. // All Rights Reserved.
// __END_LICENSE__ // __END_LICENSE__



#include <gtest/gtest_VW.h>
#include <test/Helpers.h> #include <test/Helpers.h>
#include <vw/Math/Vector.h> #include <vw/Math/Vector.h>
#include <vw/Math/Matrix.h> #include <vw/Math/Matrix.h>
Expand Down
2 changes: 0 additions & 2 deletions src/vw/Math/tests/TestLevenbergMarquardt.cxx
Expand Up @@ -4,8 +4,6 @@
// All Rights Reserved. // All Rights Reserved.
// __END_LICENSE__ // __END_LICENSE__



#include <gtest/gtest_VW.h>
#include <test/Helpers.h> #include <test/Helpers.h>
#include <vw/Math/Matrix.h> #include <vw/Math/Matrix.h>
#include <vw/Math/Vector.h> #include <vw/Math/Vector.h>
Expand Down
2 changes: 0 additions & 2 deletions src/vw/Math/tests/TestLinearAlgebra.cxx
Expand Up @@ -4,8 +4,6 @@
// All Rights Reserved. // All Rights Reserved.
// __END_LICENSE__ // __END_LICENSE__



#include <gtest/gtest_VW.h>
#include <test/Helpers.h> #include <test/Helpers.h>
#include <vw/Core/Log.h> #include <vw/Core/Log.h>
#include <vw/Math/Vector.h> #include <vw/Math/Vector.h>
Expand Down
2 changes: 0 additions & 2 deletions src/vw/Math/tests/TestParticleSwarmOptimization.cxx
Expand Up @@ -4,8 +4,6 @@
// All Rights Reserved. // All Rights Reserved.
// __END_LICENSE__ // __END_LICENSE__



#include <gtest/gtest_VW.h>
#include <test/Helpers.h> #include <test/Helpers.h>
#include <vw/Math/ParticleSwarmOptimization.h> #include <vw/Math/ParticleSwarmOptimization.h>


Expand Down
1 change: 0 additions & 1 deletion src/vw/Math/tests/TestVector.cxx
Expand Up @@ -6,7 +6,6 @@




// TestVector.h // TestVector.h
#include <gtest/gtest_VW.h>
#include <test/Helpers.h> #include <test/Helpers.h>
#include <vw/Math/Vector.h> #include <vw/Math/Vector.h>


Expand Down

0 comments on commit 6ef8b98

Please sign in to comment.