hash_map_test.hpp 2.4 KB

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