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 #ifdef BOOST_HASH_TEST_EXTENSIONS
9 # ifdef BOOST_HASH_TEST_STD_INCLUDES
10 # include <functional>
11 # else
12 # include <boost/container_hash/hash.hpp>
13 # endif
14 #endif
15
16 #include <boost/core/lightweight_test.hpp>
17
18 #ifdef BOOST_HASH_TEST_EXTENSIONS
19
array_int_test()20 void array_int_test()
21 {
22 const int length1 = 25;
23 int array1[25] = {
24 26, -43, 32, 65, 45,
25 12, 67, 32, 12, 23,
26 0, 0, 0, 0, 0,
27 8, -12, 23, 65, 45,
28 -1, 93, -54, 987, 3
29 };
30 BOOST_HASH_TEST_NAMESPACE::hash<int[25]> hasher1;
31
32 const int length2 = 1;
33 int array2[1] = {3};
34 BOOST_HASH_TEST_NAMESPACE::hash<int[1]> hasher2;
35
36 const int length3 = 2;
37 int array3[2] = {2, 3};
38 BOOST_HASH_TEST_NAMESPACE::hash<int[2]> hasher3;
39
40 BOOST_TEST(hasher1(array1)
41 == BOOST_HASH_TEST_NAMESPACE::hash_range(array1, array1 + length1));
42 BOOST_TEST(hasher2(array2)
43 == BOOST_HASH_TEST_NAMESPACE::hash_range(array2, array2 + length2));
44 BOOST_TEST(hasher3(array3)
45 == BOOST_HASH_TEST_NAMESPACE::hash_range(array3, array3 + length3));
46 }
47
two_dimensional_array_test()48 void two_dimensional_array_test()
49 {
50 int array[3][2] = {{-5, 6}, {7, -3}, {26, 1}};
51 BOOST_HASH_TEST_NAMESPACE::hash<int[3][2]> hasher;
52
53 std::size_t seed1 = 0;
54 for(int i = 0; i < 3; ++i)
55 {
56 std::size_t seed2 = 0;
57 for(int j = 0; j < 2; ++j)
58 BOOST_HASH_TEST_NAMESPACE::hash_combine(seed2, array[i][j]);
59 BOOST_HASH_TEST_NAMESPACE::hash_combine(seed1, seed2);
60 }
61
62 BOOST_TEST(hasher(array) == seed1);
63 BOOST_TEST(hasher(array) == BOOST_HASH_TEST_NAMESPACE::hash_range(array, array + 3));
64 }
65
66 #endif // BOOST_HASH_TEST_EXTENSIONS
67
main()68 int main()
69 {
70 #ifdef BOOST_HASH_TEST_EXTENSIONS
71 array_int_test();
72 two_dimensional_array_test();
73 #endif
74 return boost::report_errors();
75 }
76