• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2010 Tim Blechmann
3 
4     Use, modification and distribution is subject to the Boost Software
5     License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6     http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
8 
9 #define BOOST_TEST_MAIN
10 #ifdef BOOST_HEAP_INCLUDE_TESTS
11 #include <boost/test/included/unit_test.hpp>
12 #else
13 #include <boost/test/unit_test.hpp>
14 #endif
15 
16 #include <algorithm>
17 
18 #include <boost/heap/d_ary_heap.hpp>
19 
20 #include "common_heap_tests.hpp"
21 #include "stable_heap_tests.hpp"
22 #include "mutable_heap_tests.hpp"
23 #include "merge_heap_tests.hpp"
24 
25 
26 template <int D, bool stable>
run_d_ary_heap_test(void)27 void run_d_ary_heap_test(void)
28 {
29     typedef boost::heap::d_ary_heap<int, boost::heap::arity<D>,
30                                          boost::heap::stable<stable>,
31                                          boost::heap::compare<std::less<int> >,
32                                          boost::heap::allocator<std::allocator<int> > > pri_queue;
33 
34     BOOST_CONCEPT_ASSERT((boost::heap::PriorityQueue<pri_queue>));
35 
36     run_concept_check<pri_queue>();
37     run_common_heap_tests<pri_queue>();
38     run_iterator_heap_tests<pri_queue>();
39     run_copyable_heap_tests<pri_queue>();
40     run_moveable_heap_tests<pri_queue>();
41     run_reserve_heap_tests<pri_queue>();
42     run_merge_tests<pri_queue>();
43 
44     run_ordered_iterator_tests<pri_queue>();
45 
46     if (stable) {
47         typedef boost::heap::d_ary_heap<q_tester, boost::heap::arity<D>,
48                                                   boost::heap::stable<stable>
49                                        > stable_pri_queue;
50 
51         run_stable_heap_tests<stable_pri_queue>();
52     }
53 
54 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
55     cmpthings ord;
56     boost::heap::d_ary_heap<thing, boost::heap::arity<D>, boost::heap::compare<cmpthings>, boost::heap::stable<stable> > vpq(ord);
57     vpq.emplace(5, 6, 7);
58 #endif
59 }
60 
61 
BOOST_AUTO_TEST_CASE(d_ary_heap_test)62 BOOST_AUTO_TEST_CASE( d_ary_heap_test )
63 {
64     run_d_ary_heap_test<2, false>();
65     run_d_ary_heap_test<3, false>();
66     run_d_ary_heap_test<4, false>();
67     run_d_ary_heap_test<5, false>();
68 }
69 
BOOST_AUTO_TEST_CASE(d_ary_heap_stable_test)70 BOOST_AUTO_TEST_CASE( d_ary_heap_stable_test )
71 {
72     run_d_ary_heap_test<2, true>();
73     run_d_ary_heap_test<3, true>();
74     run_d_ary_heap_test<4, true>();
75     run_d_ary_heap_test<5, true>();
76 }
77 
78 template <int D, bool stable>
run_d_ary_heap_mutable_test(void)79 void run_d_ary_heap_mutable_test(void)
80 {
81     typedef boost::heap::d_ary_heap<int, boost::heap::mutable_<true>,
82                                             boost::heap::arity<D>,
83                                             boost::heap::stable<stable>
84                                            > pri_queue;
85 
86     BOOST_CONCEPT_ASSERT((boost::heap::MutablePriorityQueue<pri_queue>));
87 
88     run_common_heap_tests<pri_queue>();
89     run_moveable_heap_tests<pri_queue>();
90     run_reserve_heap_tests<pri_queue>();
91     run_mutable_heap_tests<pri_queue>();
92 
93     run_merge_tests<pri_queue>();
94 
95     run_ordered_iterator_tests<pri_queue>();
96 
97     if (stable) {
98         typedef boost::heap::d_ary_heap<q_tester, boost::heap::mutable_<true>,
99                                                 boost::heap::arity<D>,
100                                                 boost::heap::stable<stable>
101                                                > stable_pri_queue;
102         run_stable_heap_tests<stable_pri_queue>();
103     }
104 }
105 
BOOST_AUTO_TEST_CASE(d_ary_heap_mutable_test)106 BOOST_AUTO_TEST_CASE( d_ary_heap_mutable_test )
107 {
108     run_d_ary_heap_mutable_test<2, false>();
109     run_d_ary_heap_mutable_test<3, false>();
110     run_d_ary_heap_mutable_test<4, false>();
111     run_d_ary_heap_mutable_test<5, false>();
112 }
113 
BOOST_AUTO_TEST_CASE(d_ary_heap_mutable_stable_test)114 BOOST_AUTO_TEST_CASE( d_ary_heap_mutable_stable_test )
115 {
116     run_d_ary_heap_mutable_test<2, true>();
117     run_d_ary_heap_mutable_test<3, true>();
118     run_d_ary_heap_mutable_test<4, true>();
119     run_d_ary_heap_mutable_test<5, true>();
120 }
121 
BOOST_AUTO_TEST_CASE(d_ary_heap_compare_lookup_test)122 BOOST_AUTO_TEST_CASE( d_ary_heap_compare_lookup_test )
123 {
124     typedef boost::heap::d_ary_heap<int, boost::heap::arity<2>,
125                                     boost::heap::compare<less_with_T>,
126                                     boost::heap::allocator<std::allocator<int> > > pri_queue;
127     run_common_heap_tests<pri_queue>();
128 }
129 
130 
BOOST_AUTO_TEST_CASE(d_ary_heap_leak_test)131 BOOST_AUTO_TEST_CASE( d_ary_heap_leak_test )
132 {
133     typedef boost::heap::d_ary_heap<boost::shared_ptr<int>, boost::heap::arity<2> > pri_queue;
134     run_leak_check_test<pri_queue>();
135 }
136