iterator_range_hash.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Boost.Range library
  2. //
  3. // Copyright Neil Groves 2014. Use, modification and
  4. // distribution is subject to the Boost Software License, Version
  5. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // For more information, see http://www.boost.org/libs/range/
  9. //
  10. #include <boost/range/iterator_range_hash.hpp>
  11. #include <boost/test/test_tools.hpp>
  12. #include <boost/test/unit_test.hpp>
  13. #include <vector>
  14. namespace boost_range_test
  15. {
  16. namespace
  17. {
  18. void test_iterator_range_hash()
  19. {
  20. std::vector<boost::int32_t> v;
  21. for (boost::int32_t i = 0; i < 10; ++i)
  22. {
  23. v.push_back(i);
  24. }
  25. std::size_t ref_output = boost::hash_range(v.begin(), v.end());
  26. boost::iterator_range<std::vector<boost::int32_t>::iterator> rng(v);
  27. std::size_t test_output = boost::hash_value(rng);
  28. BOOST_CHECK_EQUAL(ref_output, test_output);
  29. }
  30. } // anonymous namespace
  31. } // namespace boost_range_test
  32. boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] )
  33. {
  34. boost::unit_test::test_suite* test =
  35. BOOST_TEST_SUITE("Boost.Range iterator_range hash function");
  36. test->add(BOOST_TEST_CASE(&boost_range_test::test_iterator_range_hash));
  37. return test;
  38. }