• 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 #if !defined(CONTAINER_TYPE)
7 #error "CONTAINER_TYPE not defined"
8 #else
9 
10 #if defined(BOOST_MSVC)
11 #pragma warning(push)
12 #pragma warning(disable:4245) // signed/unsigned mismatch
13 #endif
14 
15 namespace HASH_TEST_CAT(CONTAINER_TYPE, _tests)
16 {
17     template <class T>
18     void integer_tests(T* = 0)
19     {
20         typedef typename T::value_type value_type;
21 
22         const int number_of_containers = 12;
23         T containers[number_of_containers];
24 
25         for(int i = 0; i < 5; ++i) {
26             for(int j = 0; j < i; ++j)
27                 containers[i].insert(0);
28         }
29 
30         containers[6].insert(value_type(1));
31         containers[7].insert(value_type(1));
32         containers[7].insert(value_type(1));
33         containers[8].insert(value_type(-1));
34         containers[9].insert(value_type(-1));
35         containers[9].insert(value_type(-1));
36         containers[10].insert(value_type(-1));
37         containers[10].insert(value_type(1));
38         containers[11].insert(value_type(1));
39         containers[11].insert(value_type(2));
40         containers[11].insert(value_type(3));
41         containers[11].insert(value_type(4));
42         containers[11].insert(value_type(5));
43 
44         BOOST_HASH_TEST_NAMESPACE::hash<T> hasher;
45 
46         for(int i2 = 0; i2 < number_of_containers; ++i2) {
47             BOOST_TEST(hasher(containers[i2]) == hasher(containers[i2]));
48 
49             BOOST_TEST(hasher(containers[i2]) ==
50                     BOOST_HASH_TEST_NAMESPACE::hash_value(containers[i2]));
51 
52             BOOST_TEST(hasher(containers[i2])
53                     == BOOST_HASH_TEST_NAMESPACE::hash_range(
54                         containers[i2].begin(), containers[i2].end()));
55 
56             for(int j2 = i2 + 1; j2 < number_of_containers; ++j2) {
57                 BOOST_TEST(
58                         (containers[i2] == containers[j2]) ==
59                         (hasher(containers[i2]) == hasher(containers[j2]))
60                         );
61             }
62         }
63     }
64 
65     void HASH_TEST_CAT(CONTAINER_TYPE, _hash_integer_tests())
66     {
67         integer_tests((CONTAINER_TYPE<char>*) 0);
68         integer_tests((CONTAINER_TYPE<int>*) 0);
69         integer_tests((CONTAINER_TYPE<unsigned long>*) 0);
70         integer_tests((CONTAINER_TYPE<double>*) 0);
71     }
72 }
73 
74 #if defined(BOOST_MSVC)
75 #pragma warning(pop)
76 #endif
77 
78 #undef CONTAINER_TYPE
79 #endif
80