hash_set_test.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2005-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. #if !defined(CONTAINER_TYPE)
  5. #error "CONTAINER_TYPE not defined"
  6. #else
  7. #if defined(BOOST_MSVC)
  8. #pragma warning(push)
  9. #pragma warning(disable:4245) // signed/unsigned mismatch
  10. #endif
  11. namespace HASH_TEST_CAT(CONTAINER_TYPE, _tests)
  12. {
  13. template <class T>
  14. void integer_tests(T* = 0)
  15. {
  16. typedef typename T::value_type value_type;
  17. const int number_of_containers = 12;
  18. T containers[number_of_containers];
  19. for(int i = 0; i < 5; ++i) {
  20. for(int j = 0; j < i; ++j)
  21. containers[i].insert(0);
  22. }
  23. containers[6].insert(value_type(1));
  24. containers[7].insert(value_type(1));
  25. containers[7].insert(value_type(1));
  26. containers[8].insert(value_type(-1));
  27. containers[9].insert(value_type(-1));
  28. containers[9].insert(value_type(-1));
  29. containers[10].insert(value_type(-1));
  30. containers[10].insert(value_type(1));
  31. containers[11].insert(value_type(1));
  32. containers[11].insert(value_type(2));
  33. containers[11].insert(value_type(3));
  34. containers[11].insert(value_type(4));
  35. containers[11].insert(value_type(5));
  36. BOOST_HASH_TEST_NAMESPACE::hash<T> hasher;
  37. for(int i2 = 0; i2 < number_of_containers; ++i2) {
  38. BOOST_TEST(hasher(containers[i2]) == hasher(containers[i2]));
  39. BOOST_TEST(hasher(containers[i2]) ==
  40. BOOST_HASH_TEST_NAMESPACE::hash_value(containers[i2]));
  41. BOOST_TEST(hasher(containers[i2])
  42. == BOOST_HASH_TEST_NAMESPACE::hash_range(
  43. containers[i2].begin(), containers[i2].end()));
  44. for(int j2 = i2 + 1; j2 < number_of_containers; ++j2) {
  45. BOOST_TEST(
  46. (containers[i2] == containers[j2]) ==
  47. (hasher(containers[i2]) == hasher(containers[j2]))
  48. );
  49. }
  50. }
  51. }
  52. void HASH_TEST_CAT(CONTAINER_TYPE, _hash_integer_tests())
  53. {
  54. integer_tests((CONTAINER_TYPE<char>*) 0);
  55. integer_tests((CONTAINER_TYPE<int>*) 0);
  56. integer_tests((CONTAINER_TYPE<unsigned long>*) 0);
  57. integer_tests((CONTAINER_TYPE<double>*) 0);
  58. }
  59. }
  60. #if defined(BOOST_MSVC)
  61. #pragma warning(pop)
  62. #endif
  63. #undef CONTAINER_TYPE
  64. #endif