1// Copyright 2021, 2022 Peter Dimov.
2// Distributed under the Boost Software License, Version 1.0.
3// https://www.boost.org/LICENSE_1_0.txt
4
5#include <boost/container_hash/hash.hpp>
6#include <boost/core/lightweight_test.hpp>
7#include <string>
8
9void test( unsigned char ch )
10{
11 typedef boost::hash<std::string> hash;
12
13 int const N = 32;
14
15 std::size_t h[ N ];
16
17 std::string v;
18
19 for( int i = 0; i < N; ++i )
20 {
21 h[ i ] = hash()( v );
22
23 BOOST_TEST_EQ( h[ i ], hash()( v ) );
24
25 for( int j = 0; j < i; ++j )
26 {
27 BOOST_TEST_NE( h[ j ], h[ i ] );
28 }
29
30 v.push_back( c: static_cast<char>( ch ) );
31 }
32}
33
34int main()
35{
36 for( unsigned ch = 0; ch < 256; ++ch )
37 {
38 test( ch: static_cast<unsigned char>( ch ) );
39 }
40
41 return boost::report_errors();
42}
43

source code of boost/libs/container_hash/test/hash_string_test3.cpp