• 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 // On some compilers hash_value isn't available for arrays, so I test it
7 // separately from the main array tests.
8 
9 #include "./config.hpp"
10 
11 #ifdef BOOST_HASH_TEST_EXTENSIONS
12 #  ifdef BOOST_HASH_TEST_STD_INCLUDES
13 #    include <functional>
14 #  else
15 #    include <boost/container_hash/hash.hpp>
16 #  endif
17 #endif
18 
19 #include <boost/core/lightweight_test.hpp>
20 
21 #ifdef BOOST_HASH_TEST_EXTENSIONS
22 
array_int_test()23 void array_int_test()
24 {
25     const int array1[25] = {
26         26, -43, 32, 65, 45,
27         12, 67, 32, 12, 23,
28         0, 0, 0, 0, 0,
29         8, -12, 23, 65, 45,
30         -1, 93, -54, 987, 3
31     };
32     BOOST_HASH_TEST_NAMESPACE::hash<int[25]> hasher1;
33 
34     int array2[1] = {3};
35     BOOST_HASH_TEST_NAMESPACE::hash<int[1]> hasher2;
36 
37     int array3[2] = {2, 3};
38     BOOST_HASH_TEST_NAMESPACE::hash<int[2]> hasher3;
39 
40     BOOST_TEST(hasher1(array1) == BOOST_HASH_TEST_NAMESPACE::hash_value(array1));
41     BOOST_TEST(hasher2(array2) == BOOST_HASH_TEST_NAMESPACE::hash_value(array2));
42     BOOST_TEST(hasher3(array3) == BOOST_HASH_TEST_NAMESPACE::hash_value(array3));
43 }
44 
two_dimensional_array_test()45 void two_dimensional_array_test()
46 {
47     int array[3][2] = {{-5, 6}, {7, -3}, {26, 1}};
48     BOOST_HASH_TEST_NAMESPACE::hash<int[3][2]> hasher;
49 
50     BOOST_TEST(hasher(array) == BOOST_HASH_TEST_NAMESPACE::hash_value(array));
51 }
52 
53 #endif
54 
main()55 int main()
56 {
57 #ifdef BOOST_HASH_TEST_EXTENSIONS
58     array_int_test();
59     two_dimensional_array_test();
60 #endif
61 
62     return boost::report_errors();
63 }
64 
65