/Src/Dependencies/Boost/libs/unordered/test/unordered/bucket_tests.cpp

http://hadesmem.googlecode.com/ · C++ · 85 lines · 64 code · 16 blank · 5 comment · 13 complexity · 33c62539c7b1ba069058d78f021d28b3 MD5 · raw file

  1. // Copyright 2006-2009 Daniel James.
  2. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include "../helpers/prefix.hpp"
  5. #include <boost/unordered_set.hpp>
  6. #include <boost/unordered_map.hpp>
  7. #include "../helpers/test.hpp"
  8. #include <algorithm>
  9. #include "../objects/test.hpp"
  10. #include "../helpers/random_values.hpp"
  11. #include "../helpers/helpers.hpp"
  12. #if BOOST_WORKAROUND(BOOST_MSVC, < 1400)
  13. #pragma warning(disable:4267) // conversion from 'size_t' to 'unsigned int',
  14. // possible loss of data.
  15. #endif
  16. namespace bucket_tests {
  17. test::seed_t seed(54635);
  18. template <class X>
  19. void tests(X* = 0, test::random_generator generator = test::default_generator)
  20. {
  21. typedef BOOST_DEDUCED_TYPENAME X::size_type size_type;
  22. typedef BOOST_DEDUCED_TYPENAME X::const_local_iterator const_local_iterator;
  23. test::random_values<X> v(1000, generator);
  24. X x(v.begin(), v.end());
  25. BOOST_TEST(x.bucket_count() < x.max_bucket_count());
  26. std::cerr<<x.bucket_count()<<"<"<<x.max_bucket_count()<<"\n";
  27. for(BOOST_DEDUCED_TYPENAME test::random_values<X>::const_iterator
  28. it = v.begin(), end = v.end(); it != end; ++it)
  29. {
  30. size_type bucket = x.bucket(test::get_key<X>(*it));
  31. BOOST_TEST(bucket < x.bucket_count());
  32. if(bucket < x.max_bucket_count()) {
  33. // lit? lend?? I need a new naming scheme.
  34. const_local_iterator lit = x.begin(bucket), lend = x.end(bucket);
  35. while(lit != lend
  36. && test::get_key<X>(*it) != test::get_key<X>(*lit))
  37. {
  38. ++lit;
  39. }
  40. BOOST_TEST(lit != lend);
  41. }
  42. }
  43. for(size_type i = 0; i < x.bucket_count(); ++i) {
  44. BOOST_TEST(x.bucket_size(i) == static_cast<size_type>(
  45. std::distance(x.begin(i), x.end(i))));
  46. BOOST_TEST(x.bucket_size(i) == static_cast<size_type>(
  47. std::distance(x.cbegin(i), x.cend(i))));
  48. X const& x_ref = x;
  49. BOOST_TEST(x.bucket_size(i) == static_cast<size_type>(
  50. std::distance(x_ref.begin(i), x_ref.end(i))));
  51. BOOST_TEST(x.bucket_size(i) == static_cast<size_type>(
  52. std::distance(x_ref.cbegin(i), x_ref.cend(i))));
  53. }
  54. }
  55. boost::unordered_set<test::object,
  56. test::hash, test::equal_to,
  57. test::allocator<test::object> >* test_set;
  58. boost::unordered_multiset<test::object,
  59. test::hash, test::equal_to,
  60. test::allocator<test::object> >* test_multiset;
  61. boost::unordered_map<test::object, test::object,
  62. test::hash, test::equal_to,
  63. test::allocator<test::object> >* test_map;
  64. boost::unordered_multimap<test::object, test::object,
  65. test::hash, test::equal_to,
  66. test::allocator<test::object> >* test_multimap;
  67. UNORDERED_TEST(tests, ((test_set)(test_multiset)(test_map)(test_multimap)))
  68. }
  69. RUN_TESTS()