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