2007-10-13 18:34:25 +00:00
|
|
|
|
2009-03-09 20:56:23 +00:00
|
|
|
// Copyright 2005-2009 Daniel James.
|
2007-10-13 18:34:25 +00:00
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
|
|
|
#include "./config.hpp"
|
|
|
|
|
2009-06-21 09:42:40 +00:00
|
|
|
#if !defined(TEST_EXTENSIONS)
|
|
|
|
|
|
|
|
int main() {}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#ifdef TEST_STD_INCLUDES
|
|
|
|
# include <functional>
|
|
|
|
#else
|
|
|
|
# include <boost/functional/hash.hpp>
|
2007-10-13 18:34:25 +00:00
|
|
|
#endif
|
|
|
|
|
2008-07-18 12:31:18 +00:00
|
|
|
#include <boost/detail/lightweight_test.hpp>
|
2007-10-13 18:34:25 +00:00
|
|
|
|
|
|
|
#if defined(BOOST_MSVC)
|
2010-01-04 22:49:39 +00:00
|
|
|
#pragma warning(disable:4244) // conversion from 'unsigned long' to
|
|
|
|
// 'unsigned short', possible loss of data
|
|
|
|
#pragma warning(disable:4245) // conversion from 'int' to
|
|
|
|
// 'const unsigned short',
|
|
|
|
// signed/unsigned mismatch
|
|
|
|
#pragma warning(disable:4305) // truncation from 'double' to
|
|
|
|
// 'const std::complex<float>::_Ty'
|
|
|
|
#pragma warning(disable:4309) // truncation of constant value
|
|
|
|
#pragma warning(disable:4512) // assignment operator could not be generated
|
2009-11-27 19:43:26 +00:00
|
|
|
#if BOOST_MSVC < 1400
|
2010-01-04 22:49:39 +00:00
|
|
|
#pragma warning(disable:4267) // conversion from 'size_t' to 'unsigned int',
|
|
|
|
// possible loss of data
|
2009-11-27 19:43:26 +00:00
|
|
|
#endif
|
2007-10-13 18:34:25 +00:00
|
|
|
#endif
|
|
|
|
|
2009-11-21 19:40:54 +00:00
|
|
|
#include <complex>
|
|
|
|
#include <sstream>
|
|
|
|
#include <boost/limits.hpp>
|
2007-10-13 18:34:25 +00:00
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void generic_complex_tests(std::complex<T> v)
|
|
|
|
{
|
|
|
|
HASH_NAMESPACE::hash<std::complex<T> > complex_hasher;
|
|
|
|
|
2008-07-18 12:31:18 +00:00
|
|
|
BOOST_TEST(complex_hasher(v) == complex_hasher(v));
|
2007-10-13 18:34:25 +00:00
|
|
|
|
|
|
|
HASH_NAMESPACE::hash<T> real_hasher;
|
|
|
|
T real = v.real();
|
|
|
|
T imag = v.imag();
|
|
|
|
|
2008-07-18 12:31:18 +00:00
|
|
|
BOOST_TEST(real_hasher(real) == complex_hasher(std::complex<T>(real)));
|
2007-10-13 18:34:25 +00:00
|
|
|
|
|
|
|
if(imag != 0 && real_hasher(real) == complex_hasher(v)) {
|
|
|
|
std::ostringstream os;
|
|
|
|
os<<"real_hasher("<<real<<") == complex_hasher("
|
|
|
|
<<v.real()<<" + "<<v.imag()<<"i) == "
|
|
|
|
<<real_hasher(real)<<" (This might not be a bug).";
|
|
|
|
BOOST_ERROR(os.str().c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Float>
|
|
|
|
void complex_float_tests(Float*)
|
|
|
|
{
|
2009-06-15 07:37:42 +00:00
|
|
|
typedef std::complex<Float> complex;
|
|
|
|
generic_complex_tests(complex(0,0));
|
|
|
|
generic_complex_tests(complex(0.5,0));
|
|
|
|
generic_complex_tests(complex(25,0));
|
|
|
|
generic_complex_tests(complex(25,0));
|
2010-12-11 14:43:00 +00:00
|
|
|
generic_complex_tests(complex(static_cast<Float>(-67.5324535),static_cast<Float>(56.23578678)));
|
2007-10-13 18:34:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class Integer>
|
|
|
|
void complex_integral_tests(Integer*)
|
|
|
|
{
|
2009-06-15 07:37:42 +00:00
|
|
|
typedef std::complex<Integer> complex;
|
|
|
|
generic_complex_tests(complex(0,0));
|
|
|
|
generic_complex_tests(complex(15342,124));
|
|
|
|
generic_complex_tests(complex(25,54356));
|
|
|
|
generic_complex_tests(complex(5325,2346));
|
|
|
|
generic_complex_tests(complex(-243897,-49923874));
|
|
|
|
generic_complex_tests(complex(-543,763));
|
2007-10-13 18:34:25 +00:00
|
|
|
}
|
|
|
|
|
2008-07-18 12:31:18 +00:00
|
|
|
int main()
|
2007-10-13 18:34:25 +00:00
|
|
|
{
|
2009-11-16 23:56:56 +00:00
|
|
|
// I've comments out the short and unsigned short tests
|
|
|
|
// as they cause warnings and don't really test
|
|
|
|
// anything that the other tests already deal with.
|
|
|
|
|
2007-10-13 18:34:25 +00:00
|
|
|
complex_float_tests((float*) 0);
|
|
|
|
complex_float_tests((double*) 0);
|
|
|
|
complex_float_tests((long double*) 0);
|
2009-11-16 23:56:56 +00:00
|
|
|
//complex_integral_tests((short*) 0);
|
2007-10-13 18:34:25 +00:00
|
|
|
complex_integral_tests((int*) 0);
|
|
|
|
complex_integral_tests((long*) 0);
|
2009-11-16 23:56:56 +00:00
|
|
|
//complex_integral_tests((unsigned short*) 0);
|
2007-10-13 18:34:25 +00:00
|
|
|
complex_integral_tests((unsigned int*) 0);
|
|
|
|
complex_integral_tests((unsigned long*) 0);
|
|
|
|
|
2008-07-18 12:31:18 +00:00
|
|
|
return boost::report_errors();
|
2007-10-13 18:34:25 +00:00
|
|
|
}
|
|
|
|
|
2009-06-21 09:42:40 +00:00
|
|
|
#endif // TEST_EXTENSIONS
|