summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/multiprecision/test/test_hash.cpp
blob: 2572d1ba99b7b9d13454bb3b1f33f915a6b5345f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright John Maddock 2015.

// Use, modification and distribution are subject to 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)

#ifdef _MSC_VER
#define _SCL_SECURE_NO_WARNINGS
#endif

#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_bin_float.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/debug_adaptor.hpp>
#include <boost/multiprecision/logged_adaptor.hpp>

#ifdef TEST_FLOAT128
#include <boost/multiprecision/float128.hpp>
#endif
#ifdef TEST_GMP
#include <boost/multiprecision/gmp.hpp>
#endif
#ifdef TEST_MPFR
#include <boost/multiprecision/mpfr.hpp>
#endif
#ifdef TEST_MPFI
#include <boost/multiprecision/mpfi.hpp>
#endif
#ifdef TEST_TOMMATH
#include <boost/multiprecision/tommath.hpp>
#endif

#include <boost/functional/hash.hpp>

#include "test.hpp"
#include <iostream>
#include <iomanip>

template <class T>
void test()
{
   T           val = 23;
   std::size_t t1  = boost::hash<T>()(val);
   BOOST_CHECK(t1);

#ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL
   std::size_t t2 = std::hash<T>()(val);
   BOOST_CHECK_EQUAL(t1, t2);
#endif
   val            = -23;
   std::size_t t3 = boost::hash<T>()(val);
   BOOST_CHECK_NE(t1, t3);
#ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL
   t2 = std::hash<T>()(val);
   BOOST_CHECK_EQUAL(t3, t2);
#endif
}

int main()
{
   test<boost::multiprecision::cpp_int>();
   test<boost::multiprecision::checked_int1024_t>();
   //test<boost::multiprecision::checked_uint512_t >();
   test<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<64, 64, boost::multiprecision::signed_magnitude, boost::multiprecision::checked, void> > >();

   test<boost::multiprecision::cpp_bin_float_100>();
   test<boost::multiprecision::cpp_dec_float_100>();

   test<boost::multiprecision::cpp_rational>();

   test<boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::cpp_int::backend_type> > >();

   test<boost::multiprecision::number<boost::multiprecision::logged_adaptor<boost::multiprecision::cpp_int::backend_type> > >();

#ifdef TEST_FLOAT128
   test<boost::multiprecision::float128>();
#endif
#ifdef TEST_GMP
   test<boost::multiprecision::mpz_int>();
   test<boost::multiprecision::mpq_rational>();
   test<boost::multiprecision::mpf_float>();
#endif

#ifdef TEST_MPFR
   test<boost::multiprecision::mpfr_float_50>();
#endif
#ifdef TEST_MPFI
   test<boost::multiprecision::mpfi_float_50>();
#endif

#ifdef TEST_TOMMATH
   test<boost::multiprecision::tom_int>();
   test<boost::multiprecision::tom_rational>();
#endif

   return boost::report_errors();
}