1 /*=============================================================================
2 Copyright (c) 2010 Tim Blechmann
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 =============================================================================*/
9 #include <boost/foreach.hpp>
10 #include "common_heap_tests.hpp"
14 q_tester(int i = 0, int j = 0):
18 bool operator< (q_tester const & rhs) const
20 return value < rhs.value;
23 bool operator> (q_tester const & rhs) const
25 return value > rhs.value;
28 bool operator== (q_tester const & rhs) const
30 return (value == rhs.value) && (id == rhs.id);
37 std::ostream& operator<< (std::ostream& out, q_tester const & t)
39 out << "[" << t.value << " " << t.id << "]";
43 typedef std::vector<q_tester> stable_test_data;
45 stable_test_data make_stable_test_data(int size, int same_count = 3,
46 int offset = 0, int strive = 1)
50 for (int i = 0; i != size; ++i)
51 for (int j = 0; j != same_count; ++j)
52 ret.push_back(q_tester(i * strive + offset, j));
58 bool operator()(q_tester const & lhs, q_tester const & rhs)
60 return lhs.id > rhs.id;
64 template <typename pri_queue>
65 void pri_queue_stable_test_sequential_push(void)
67 stable_test_data data = make_stable_test_data(test_size);
71 std::stable_sort(data.begin(), data.end(), compare_by_id());
72 std::stable_sort(data.begin(), data.end(), std::less<q_tester>());
76 template <typename pri_queue>
77 void pri_queue_stable_test_sequential_reverse_push(void)
79 stable_test_data data = make_stable_test_data(test_size);
81 stable_test_data push_data(data);
83 std::stable_sort(push_data.begin(), push_data.end(), std::greater<q_tester>());
87 std::stable_sort(data.begin(), data.end(), compare_by_id());
88 std::stable_sort(data.begin(), data.end(), std::less<q_tester>());
94 template <typename pri_queue>
95 void run_stable_heap_tests(void)
97 pri_queue_stable_test_sequential_push<pri_queue>();
98 pri_queue_stable_test_sequential_reverse_push<pri_queue>();