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 | #include "common_heap_tests.hpp" |
10 | #include <boost/heap/heap_merge.hpp> |
11 | |
12 | #define GENERATE_TEST_DATA(INDEX) \ |
13 | test_data data = make_test_data(test_size, 0, 1); \ |
14 | random_shuffle(data.begin(), data.end()); \ |
15 | \ |
16 | test_data data_q (data.begin(), data.begin() + INDEX); \ |
17 | test_data data_r (data.begin() + INDEX, data.end()); \ |
18 | \ |
19 | std::stable_sort(data.begin(), data.end()); |
20 | |
21 | |
22 | template <typename pri_queue> |
23 | struct pri_queue_test_merge |
24 | { |
25 | static void run(void) |
26 | { |
27 | for (int i = 0; i != test_size; ++i) { |
28 | pri_queue q, r; |
29 | GENERATE_TEST_DATA(i); |
30 | |
31 | fill_q(q, data_q); |
32 | fill_q(r, data_r); |
33 | |
34 | q.merge(r); |
35 | |
36 | BOOST_REQUIRE(r.empty()); |
37 | check_q(q, data); |
38 | } |
39 | } |
40 | }; |
41 | |
42 | |
43 | template <typename pri_queue1, typename pri_queue2> |
44 | struct pri_queue_test_heap_merge |
45 | { |
46 | static void run (void) |
47 | { |
48 | for (int i = 0; i != test_size; ++i) { |
49 | pri_queue1 q; |
50 | pri_queue2 r; |
51 | GENERATE_TEST_DATA(i); |
52 | |
53 | fill_q(q, data_q); |
54 | fill_q(r, data_r); |
55 | |
56 | boost::heap::heap_merge(q, r); |
57 | |
58 | BOOST_REQUIRE(r.empty()); |
59 | check_q(q, data); |
60 | } |
61 | } |
62 | }; |
63 | |
64 | |
65 | |
66 | template <typename pri_queue> |
67 | void run_merge_tests(void) |
68 | { |
69 | boost::conditional<pri_queue::is_mergable, |
70 | pri_queue_test_merge<pri_queue>, |
71 | dummy_run |
72 | >::type::run(); |
73 | |
74 | pri_queue_test_heap_merge<pri_queue, pri_queue>::run(); |
75 | } |
76 | |