Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame^] | 1 | |
| 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) |
| 5 | |
| 6 | #include "./config.hpp" |
| 7 | |
| 8 | #if !defined(BOOST_HASH_TEST_EXTENSIONS) |
| 9 | |
| 10 | int main() {} |
| 11 | |
| 12 | #else |
| 13 | |
| 14 | #ifdef BOOST_HASH_TEST_STD_INCLUDES |
| 15 | # include <functional> |
| 16 | #else |
| 17 | # include <boost/functional/hash.hpp> |
| 18 | #endif |
| 19 | |
| 20 | #include <boost/detail/lightweight_test.hpp> |
| 21 | |
| 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 |
| 32 | #if BOOST_MSVC < 1400 |
| 33 | #pragma warning(disable:4267) // conversion from 'size_t' to 'unsigned int', |
| 34 | // possible loss of data |
| 35 | #endif |
| 36 | #endif |
| 37 | |
| 38 | #if defined(__GNUC__) && !defined(BOOST_INTEL_CXX_VERSION) |
| 39 | #pragma GCC diagnostic ignored "-Wfloat-equal" |
| 40 | #endif |
| 41 | |
| 42 | #include <complex> |
| 43 | #include <sstream> |
| 44 | #include <boost/limits.hpp> |
| 45 | |
| 46 | template <class T> |
| 47 | void generic_complex_tests(std::complex<T> v) |
| 48 | { |
| 49 | BOOST_HASH_TEST_NAMESPACE::hash<std::complex<T> > complex_hasher; |
| 50 | |
| 51 | BOOST_TEST(complex_hasher(v) == complex_hasher(v)); |
| 52 | |
| 53 | BOOST_HASH_TEST_NAMESPACE::hash<T> real_hasher; |
| 54 | T real = v.real(); |
| 55 | T imag = v.imag(); |
| 56 | |
| 57 | BOOST_TEST(real_hasher(real) == complex_hasher(std::complex<T>(real))); |
| 58 | |
| 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()); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | template <class Float> |
| 69 | void complex_float_tests(Float*) |
| 70 | { |
| 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))); |
| 77 | } |
| 78 | |
| 79 | template <class Integer> |
| 80 | void complex_integral_tests(Integer*) |
| 81 | { |
| 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(-243897,-49923874)); |
| 88 | generic_complex_tests(complex(-543,763)); |
| 89 | } |
| 90 | |
| 91 | int main() |
| 92 | { |
| 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. |
| 96 | |
| 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); |
| 106 | |
| 107 | return ndnboost::report_errors(); |
| 108 | } |
| 109 | |
| 110 | #endif // BOOST_HASH_TEST_EXTENSIONS |