mutable_heap_test.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. #define BOOST_TEST_MAIN
  8. #include <boost/test/unit_test.hpp>
  9. #include <boost/heap/d_ary_heap.hpp>
  10. #include <boost/heap/fibonacci_heap.hpp>
  11. #include <boost/heap/pairing_heap.hpp>
  12. #include <boost/heap/binomial_heap.hpp>
  13. #include <boost/heap/skew_heap.hpp>
  14. using namespace boost::heap;
  15. typedef fibonacci_heap<struct fwd_declared_struct_1>::handle_type handle_type_1;
  16. typedef d_ary_heap<struct fwd_declared_struct_2, arity<4>, mutable_<true> >::handle_type handle_type_2;
  17. typedef pairing_heap<struct fwd_declared_struct_3>::handle_type handle_type_3;
  18. typedef binomial_heap<struct fwd_declared_struct_4>::handle_type handle_type_4;
  19. typedef skew_heap<struct fwd_declared_struct_5, mutable_<true> >::handle_type handle_type_5;
  20. template <typename HeapType>
  21. void run_handle_as_member_test(void)
  22. {
  23. typedef typename HeapType::value_type value_type;
  24. HeapType heap;
  25. value_type f(2);
  26. typename value_type::handle_type handle = heap.push(f);
  27. value_type & fInHeap = *handle;
  28. fInHeap.handle = handle;
  29. }
  30. struct fibonacci_heap_data
  31. {
  32. typedef fibonacci_heap<fibonacci_heap_data>::handle_type handle_type;
  33. handle_type handle;
  34. int i;
  35. fibonacci_heap_data(int i):i(i) {}
  36. bool operator<(fibonacci_heap_data const & rhs) const
  37. {
  38. return i < rhs.i;
  39. }
  40. };
  41. BOOST_AUTO_TEST_CASE( fibonacci_heap_handle_as_member )
  42. {
  43. run_handle_as_member_test<fibonacci_heap<fibonacci_heap_data> >();
  44. }
  45. struct d_heap_data
  46. {
  47. typedef d_ary_heap<d_heap_data, arity<4>, mutable_<true> >::handle_type handle_type;
  48. handle_type handle;
  49. int i;
  50. d_heap_data(int i):i(i) {}
  51. bool operator<(d_heap_data const & rhs) const
  52. {
  53. return i < rhs.i;
  54. }
  55. };
  56. BOOST_AUTO_TEST_CASE( d_heap_handle_as_member )
  57. {
  58. run_handle_as_member_test<d_ary_heap<d_heap_data, arity<4>, mutable_<true> > >();
  59. }
  60. struct pairing_heap_data
  61. {
  62. typedef pairing_heap<pairing_heap_data>::handle_type handle_type;
  63. handle_type handle;
  64. int i;
  65. pairing_heap_data(int i):i(i) {}
  66. bool operator<(pairing_heap_data const & rhs) const
  67. {
  68. return i < rhs.i;
  69. }
  70. };
  71. BOOST_AUTO_TEST_CASE( pairing_heap_handle_as_member )
  72. {
  73. run_handle_as_member_test<pairing_heap<pairing_heap_data> >();
  74. }
  75. struct binomial_heap_data
  76. {
  77. typedef binomial_heap<binomial_heap_data>::handle_type handle_type;
  78. handle_type handle;
  79. int i;
  80. binomial_heap_data(int i):i(i) {}
  81. bool operator<(binomial_heap_data const & rhs) const
  82. {
  83. return i < rhs.i;
  84. }
  85. };
  86. BOOST_AUTO_TEST_CASE( binomial_heap_handle_as_member )
  87. {
  88. run_handle_as_member_test<binomial_heap<binomial_heap_data> >();
  89. }
  90. struct skew_heap_data
  91. {
  92. typedef skew_heap<skew_heap_data, mutable_<true> >::handle_type handle_type;
  93. handle_type handle;
  94. int i;
  95. skew_heap_data(int i):i(i) {}
  96. bool operator<(skew_heap_data const & rhs) const
  97. {
  98. return i < rhs.i;
  99. }
  100. };
  101. BOOST_AUTO_TEST_CASE( skew_heap_handle_as_member )
  102. {
  103. run_handle_as_member_test<skew_heap<skew_heap_data, mutable_<true> > >();
  104. }