hash_sequence_test.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 = 11;
  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].push_back(0);
  22. }
  23. containers[5].push_back(value_type(1));
  24. containers[6].push_back(value_type(1));
  25. containers[6].push_back(value_type(1));
  26. containers[7].push_back(value_type(-1));
  27. containers[8].push_back(value_type(-1));
  28. containers[8].push_back(value_type(-1));
  29. containers[9].push_back(value_type(1));
  30. containers[9].push_back(value_type(-1));
  31. containers[10].push_back(value_type(-1));
  32. containers[10].push_back(value_type(1));
  33. BOOST_HASH_TEST_NAMESPACE::hash<T> hasher;
  34. for(int i2 = 0; i2 < number_of_containers; ++i2) {
  35. BOOST_TEST(hasher(containers[i2]) == hasher(containers[i2]));
  36. BOOST_TEST(hasher(containers[i2]) ==
  37. BOOST_HASH_TEST_NAMESPACE::hash_value(containers[i2]));
  38. BOOST_TEST(hasher(containers[i2])
  39. == BOOST_HASH_TEST_NAMESPACE::hash_range(
  40. containers[i2].begin(), containers[i2].end()));
  41. for(int j2 = i2 + 1; j2 < number_of_containers; ++j2) {
  42. BOOST_TEST(
  43. (containers[i2] == containers[j2]) ==
  44. (hasher(containers[i2]) == hasher(containers[j2]))
  45. );
  46. }
  47. }
  48. }
  49. void HASH_TEST_CAT(CONTAINER_TYPE, _hash_integer_tests())
  50. {
  51. integer_tests((CONTAINER_TYPE<char>*) 0);
  52. integer_tests((CONTAINER_TYPE<int>*) 0);
  53. integer_tests((CONTAINER_TYPE<unsigned long>*) 0);
  54. integer_tests((CONTAINER_TYPE<double>*) 0);
  55. }
  56. }
  57. #if defined(BOOST_MSVC)
  58. #pragma warning(pop)
  59. #endif
  60. #undef CONTAINER_TYPE
  61. #endif