• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
main()10 int main() {}
11 
12 #else
13 
14 #ifdef BOOST_HASH_TEST_STD_INCLUDES
15 #  include <functional>
16 #else
17 #  include <boost/container_hash/hash.hpp>
18 #endif
19 
20 #include <boost/core/lightweight_test.hpp>
21 #include <boost/limits.hpp>
22 #include <vector>
23 
hash_range_tests()24 void hash_range_tests()
25 {
26     std::vector<int> empty, values1, values2, values3, values4, values5;
27     values1.push_back(0);
28     values2.push_back(10);
29     values3.push_back(10);
30     values3.push_back(20);
31     values4.push_back(15);
32     values4.push_back(75);
33     values5.push_back(10);
34     values5.push_back(20);
35     values5.push_back(15);
36     values5.push_back(75);
37     values5.push_back(10);
38     values5.push_back(20);
39 
40     std::vector<int> x;
41 
42     std::size_t x_seed = 0;
43     BOOST_TEST(x_seed == BOOST_HASH_TEST_NAMESPACE::hash_range(x.begin(), x.end()));
44 
45     BOOST_TEST(BOOST_HASH_TEST_NAMESPACE::hash_range(empty.begin(), empty.end())
46         == BOOST_HASH_TEST_NAMESPACE::hash_range(x.begin(), x.end()));
47     BOOST_TEST(BOOST_HASH_TEST_NAMESPACE::hash_range(empty.begin(), empty.end())
48         != BOOST_HASH_TEST_NAMESPACE::hash_range(values1.begin(), values1.end()));
49 
50     x.push_back(10);
51     BOOST_HASH_TEST_NAMESPACE::hash_combine(x_seed, 10);
52     BOOST_TEST(x_seed == BOOST_HASH_TEST_NAMESPACE::hash_range(x.begin(), x.end()));
53 
54     BOOST_TEST(BOOST_HASH_TEST_NAMESPACE::hash_range(empty.begin(), empty.end())
55         != BOOST_HASH_TEST_NAMESPACE::hash_range(x.begin(), x.end()));
56     BOOST_TEST(BOOST_HASH_TEST_NAMESPACE::hash_range(values2.begin(), values2.end())
57         == BOOST_HASH_TEST_NAMESPACE::hash_range(x.begin(), x.end()));
58 
59     x.push_back(20);
60     BOOST_HASH_TEST_NAMESPACE::hash_combine(x_seed, 20);
61     BOOST_TEST(x_seed == BOOST_HASH_TEST_NAMESPACE::hash_range(x.begin(), x.end()));
62 
63     BOOST_TEST(BOOST_HASH_TEST_NAMESPACE::hash_range(empty.begin(), empty.end())
64         != BOOST_HASH_TEST_NAMESPACE::hash_range(x.begin(), x.end()));
65     BOOST_TEST(BOOST_HASH_TEST_NAMESPACE::hash_range(values2.begin(), values2.end())
66         != BOOST_HASH_TEST_NAMESPACE::hash_range(x.begin(), x.end()));
67     BOOST_TEST(BOOST_HASH_TEST_NAMESPACE::hash_range(values3.begin(), values3.end())
68         == BOOST_HASH_TEST_NAMESPACE::hash_range(x.begin(), x.end()));
69 
70     std::size_t seed =
71         BOOST_HASH_TEST_NAMESPACE::hash_range(values3.begin(), values3.end());
72     BOOST_HASH_TEST_NAMESPACE::hash_range(seed, values4.begin(), values4.end());
73     BOOST_HASH_TEST_NAMESPACE::hash_range(seed, x.begin(), x.end());
74     BOOST_TEST(seed ==
75         BOOST_HASH_TEST_NAMESPACE::hash_range(values5.begin(), values5.end()));
76 }
77 
main()78 int main()
79 {
80     hash_range_tests();
81 
82     return boost::report_errors();
83 }
84 
85 #endif // TEST_EXTESNIONS
86