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

source code of boost/libs/container_hash/test/hash_sequence_test.hpp