]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/container_hash/test/hash_complex_test.cpp
2 // Copyright 2005-2009 Daniel James.
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #include "./config.hpp"
8 #if !defined(BOOST_HASH_TEST_EXTENSIONS)
14 #ifdef BOOST_HASH_TEST_STD_INCLUDES
15 # include <functional>
17 # include <boost/container_hash/hash.hpp>
20 #include <boost/core/lightweight_test.hpp>
22 #if defined(BOOST_MSVC)
23 #pragma warning(disable:4244) // conversion from 'unsigned long' to
24 // 'unsigned short', possible loss of data
25 #pragma warning(disable:4245) // conversion from 'int' to
26 // 'const unsigned short',
27 // signed/unsigned mismatch
28 #pragma warning(disable:4305) // truncation from 'double' to
29 // 'const std::complex<float>::_Ty'
30 #pragma warning(disable:4309) // truncation of constant value
31 #pragma warning(disable:4512) // assignment operator could not be generated
33 #pragma warning(disable:4267) // conversion from 'size_t' to 'unsigned int',
34 // possible loss of data
38 #if defined(__GNUC__) && !defined(BOOST_INTEL_CXX_VERSION)
39 #pragma GCC diagnostic ignored "-Wfloat-equal"
44 #include <boost/limits.hpp>
47 void generic_complex_tests(std::complex<T
> v
)
49 BOOST_HASH_TEST_NAMESPACE::hash
<std::complex<T
> > complex_hasher
;
51 BOOST_TEST(complex_hasher(v
) == complex_hasher(v
));
53 BOOST_HASH_TEST_NAMESPACE::hash
<T
> real_hasher
;
57 BOOST_TEST(real_hasher(real
) == complex_hasher(std::complex<T
>(real
)));
59 if(imag
!= 0 && real_hasher(real
) == complex_hasher(v
)) {
60 std::ostringstream os
;
61 os
<<"real_hasher("<<real
<<") == complex_hasher("
62 <<v
.real()<<" + "<<v
.imag()<<"i) == "
63 <<real_hasher(real
)<<" (This might not be a bug).";
64 BOOST_ERROR(os
.str().c_str());
68 template <class Float
>
69 void complex_float_tests(Float
*)
71 typedef std::complex<Float
> complex;
72 generic_complex_tests(complex(0,0));
73 generic_complex_tests(complex(0.5,0));
74 generic_complex_tests(complex(25,0));
75 generic_complex_tests(complex(25,0));
76 generic_complex_tests(complex(static_cast<Float
>(-67.5324535),static_cast<Float
>(56.23578678)));
79 template <class Integer
>
80 void complex_integral_tests(Integer
*)
82 typedef std::complex<Integer
> complex;
83 generic_complex_tests(complex(0,0));
84 generic_complex_tests(complex(15342,124));
85 generic_complex_tests(complex(25,54356));
86 generic_complex_tests(complex(5325,2346));
87 generic_complex_tests(complex(Integer(-243897),Integer(-49923874)));
88 generic_complex_tests(complex(Integer(-543),Integer(763)));
93 // I've comments out the short and unsigned short tests
94 // as they cause warnings and don't really test
95 // anything that the other tests already deal with.
97 complex_float_tests((float*) 0);
98 complex_float_tests((double*) 0);
99 complex_float_tests((long double*) 0);
100 //complex_integral_tests((short*) 0);
101 complex_integral_tests((int*) 0);
102 complex_integral_tests((long*) 0);
103 //complex_integral_tests((unsigned short*) 0);
104 complex_integral_tests((unsigned int*) 0);
105 complex_integral_tests((unsigned long*) 0);
107 return boost::report_errors();
110 #endif // BOOST_HASH_TEST_EXTENSIONS