merge_heap_tests.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*=============================================================================
  2. Copyright (c) 2010 Tim Blechmann
  3. Use, modification and distribution is subject to the Boost Software
  4. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt)
  6. =============================================================================*/
  7. #include "common_heap_tests.hpp"
  8. #include <boost/heap/heap_merge.hpp>
  9. #define GENERATE_TEST_DATA(INDEX) \
  10. test_data data = make_test_data(test_size, 0, 1); \
  11. random_shuffle(data.begin(), data.end()); \
  12. \
  13. test_data data_q (data.begin(), data.begin() + INDEX); \
  14. test_data data_r (data.begin() + INDEX, data.end()); \
  15. \
  16. std::stable_sort(data.begin(), data.end());
  17. template <typename pri_queue>
  18. struct pri_queue_test_merge
  19. {
  20. static void run(void)
  21. {
  22. for (int i = 0; i != test_size; ++i) {
  23. pri_queue q, r;
  24. GENERATE_TEST_DATA(i);
  25. fill_q(q, data_q);
  26. fill_q(r, data_r);
  27. q.merge(r);
  28. BOOST_REQUIRE(r.empty());
  29. check_q(q, data);
  30. }
  31. }
  32. };
  33. template <typename pri_queue1, typename pri_queue2>
  34. struct pri_queue_test_heap_merge
  35. {
  36. static void run (void)
  37. {
  38. for (int i = 0; i != test_size; ++i) {
  39. pri_queue1 q;
  40. pri_queue2 r;
  41. GENERATE_TEST_DATA(i);
  42. fill_q(q, data_q);
  43. fill_q(r, data_r);
  44. boost::heap::heap_merge(q, r);
  45. BOOST_REQUIRE(r.empty());
  46. check_q(q, data);
  47. }
  48. }
  49. };
  50. template <typename pri_queue>
  51. void run_merge_tests(void)
  52. {
  53. boost::conditional<pri_queue::is_mergable,
  54. pri_queue_test_merge<pri_queue>,
  55. dummy_run
  56. >::type::run();
  57. pri_queue_test_heap_merge<pri_queue, pri_queue>::run();
  58. }