test_boost_hash.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // Copyright (C) 2019 James E. King III
  3. //
  4. // Permission to copy, use, modify, sell and distribute this software
  5. // is granted provided this copyright notice appears in all copies.
  6. // This software is provided "as is" without express or implied
  7. // warranty, and with no claim as to its suitability for any purpose.
  8. //
  9. // Distributed under the Boost Software License, Version 1.0. (See
  10. // accompanying file LICENSE_1_0.txt or copy at
  11. // http://www.boost.org/LICENSE_1_0.txt)
  12. //
  13. #include <boost/config.hpp>
  14. #include <boost/dynamic_bitset.hpp>
  15. #include <boost/core/lightweight_test.hpp>
  16. #include <set>
  17. int main(int, char*[])
  18. {
  19. typedef boost::dynamic_bitset<unsigned long> bitset_type;
  20. const std::string long_string =
  21. "01001110101110110101011010000000000011110101101111111111";
  22. const std::string long_string_prime_begin =
  23. "11001110101110110101011010000000000011110101101111111111";
  24. const std::string long_string_prime_end =
  25. "01001110101110110101011010000000000011110101101111111110";
  26. bitset_type zeroes(long_string.size(), 0);
  27. bitset_type stuff (long_string);
  28. bitset_type stupb (long_string_prime_begin);
  29. bitset_type stupe (long_string_prime_end);
  30. bitset_type ones (long_string.size(), 1);
  31. boost::hash<bitset_type> bitset_hasher;
  32. std::set<std::size_t> results;
  33. results.insert(bitset_hasher(zeroes));
  34. results.insert(bitset_hasher(stuff));
  35. results.insert(bitset_hasher(stupb));
  36. results.insert(bitset_hasher(stupe));
  37. results.insert(bitset_hasher(ones));
  38. // if any hash is identical to another there will be less than 5
  39. BOOST_TEST_EQ(results.size(), 5);
  40. return boost::report_errors();
  41. }