| 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 | #include <cstddef> |
| 9 | |
| 10 | void test( std::size_t n, unsigned char ch ) |
| 11 | { |
| 12 | typedef boost::hash<std::string> hash; |
| 13 | |
| 14 | std::string const v( n, static_cast<char>( ch ) ); |
| 15 | |
| 16 | for( std::size_t i = 0; i < n * 8; ++i ) |
| 17 | { |
| 18 | std::string w( v ); |
| 19 | |
| 20 | unsigned char ch2 = static_cast<unsigned char>( w[ i / 8 ] ); |
| 21 | |
| 22 | ch2 = static_cast<unsigned char>( ch2 ^ ( 1 << ( i % 8 ) ) ); |
| 23 | |
| 24 | w[ i / 8 ] = static_cast<char>( ch2 ); |
| 25 | |
| 26 | BOOST_TEST_NE( hash()( v ), hash()( w ) ); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | int main() |
| 31 | { |
| 32 | for( unsigned ch = 0; ch < 256; ++ch ) |
| 33 | { |
| 34 | for( std::size_t n = 1; n < 32; ++n ) |
| 35 | { |
| 36 | test( n, ch: static_cast<unsigned char>( ch ) ); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | return boost::report_errors(); |
| 41 | } |
| 42 |
