4037 |
25 Jan 21 |
peter |
// $Id$ |
4037 |
25 Jan 21 |
peter |
2 |
|
4037 |
25 Jan 21 |
peter |
3 |
/* |
4037 |
25 Jan 21 |
peter |
Copyright (C) 2021 Peter Johansson |
4037 |
25 Jan 21 |
peter |
5 |
|
4037 |
25 Jan 21 |
peter |
The yat library is free software; you can redistribute it and/or |
4037 |
25 Jan 21 |
peter |
modify it under the terms of the GNU General Public License as |
4037 |
25 Jan 21 |
peter |
published by the Free Software Foundation; either version 3 of the |
4037 |
25 Jan 21 |
peter |
License, or (at your option) any later version. |
4037 |
25 Jan 21 |
peter |
10 |
|
4037 |
25 Jan 21 |
peter |
The yat library is distributed in the hope that it will be useful, |
4037 |
25 Jan 21 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4037 |
25 Jan 21 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4037 |
25 Jan 21 |
peter |
General Public License for more details. |
4037 |
25 Jan 21 |
peter |
15 |
|
4037 |
25 Jan 21 |
peter |
You should have received a copy of the GNU General Public License |
4037 |
25 Jan 21 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
4037 |
25 Jan 21 |
peter |
18 |
*/ |
4037 |
25 Jan 21 |
peter |
19 |
|
4072 |
20 Aug 21 |
peter |
20 |
#define YAT_DEBUG_RANKING 1 |
4072 |
20 Aug 21 |
peter |
21 |
|
4037 |
25 Jan 21 |
peter |
22 |
#include <config.h> |
4037 |
25 Jan 21 |
peter |
23 |
|
4037 |
25 Jan 21 |
peter |
24 |
#include "Suite.h" |
4037 |
25 Jan 21 |
peter |
25 |
|
4037 |
25 Jan 21 |
peter |
26 |
#include "yat/utility/Ranking.h" |
4037 |
25 Jan 21 |
peter |
27 |
#include "yat/utility/utility.h" |
4037 |
25 Jan 21 |
peter |
28 |
|
4037 |
25 Jan 21 |
peter |
29 |
#include <algorithm> |
4037 |
25 Jan 21 |
peter |
30 |
|
4037 |
25 Jan 21 |
peter |
31 |
using namespace theplu::yat; |
4037 |
25 Jan 21 |
peter |
32 |
|
4037 |
25 Jan 21 |
peter |
33 |
void test1(test::Suite& suite) |
4037 |
25 Jan 21 |
peter |
34 |
{ |
4069 |
06 Aug 21 |
peter |
35 |
suite.out() << YAT_TEST_PROLOGUE; |
4037 |
25 Jan 21 |
peter |
36 |
suite.out() << "Constructor(0)\n"; |
4037 |
25 Jan 21 |
peter |
37 |
utility::Ranking<double> ranking; |
4037 |
25 Jan 21 |
peter |
38 |
{ |
4037 |
25 Jan 21 |
peter |
39 |
suite.out() << "Constructor(1)\n"; |
4037 |
25 Jan 21 |
peter |
40 |
utility::Ranking<double, std::less<double> > ranking2(ranking.compare()); |
4037 |
25 Jan 21 |
peter |
41 |
test::avoid_compiler_warning(ranking2); |
4037 |
25 Jan 21 |
peter |
42 |
suite.out() << "Constructor(0)\n"; |
4037 |
25 Jan 21 |
peter |
43 |
utility::Ranking<double, std::greater<double> > ranking3; |
4037 |
25 Jan 21 |
peter |
44 |
test::avoid_compiler_warning(ranking3); |
4037 |
25 Jan 21 |
peter |
45 |
std::greater<double> compare; |
4037 |
25 Jan 21 |
peter |
46 |
suite.out() << "Constructor(1)\n"; |
4037 |
25 Jan 21 |
peter |
47 |
utility::Ranking<double, std::greater<double> > ranking4(compare); |
4037 |
25 Jan 21 |
peter |
48 |
test::avoid_compiler_warning(ranking4); |
4037 |
25 Jan 21 |
peter |
49 |
} |
4037 |
25 Jan 21 |
peter |
50 |
|
4072 |
20 Aug 21 |
peter |
51 |
suite.out() << "::insert 0\n"; |
4037 |
25 Jan 21 |
peter |
52 |
ranking.insert(0); |
4072 |
20 Aug 21 |
peter |
53 |
suite.out() << "::insert 1\n"; |
4037 |
25 Jan 21 |
peter |
54 |
ranking.insert(1); |
4072 |
20 Aug 21 |
peter |
55 |
suite.out() << "::insert 2\n"; |
4037 |
25 Jan 21 |
peter |
56 |
ranking.insert(2); |
4072 |
20 Aug 21 |
peter |
57 |
suite.out() << "::insert 1\n"; |
4037 |
25 Jan 21 |
peter |
58 |
ranking.insert(1); |
4037 |
25 Jan 21 |
peter |
59 |
if (ranking.size() != 4) { |
4037 |
25 Jan 21 |
peter |
60 |
suite.add(false); |
4037 |
25 Jan 21 |
peter |
61 |
suite.err() << "error: incorrect size: " << ranking.size() << "\n"; |
4037 |
25 Jan 21 |
peter |
62 |
} |
4037 |
25 Jan 21 |
peter |
63 |
suite.out() << "distance\n"; |
4037 |
25 Jan 21 |
peter |
64 |
int dist = std::distance(ranking.begin(), ranking.end()); |
4037 |
25 Jan 21 |
peter |
65 |
if (dist != 4) { |
4037 |
25 Jan 21 |
peter |
66 |
suite.add(false); |
4037 |
25 Jan 21 |
peter |
67 |
suite.err() << "error: incorrect distance: " << dist << "\n"; |
4037 |
25 Jan 21 |
peter |
68 |
} |
4037 |
25 Jan 21 |
peter |
69 |
int cdist = std::distance(ranking.cbegin(), ranking.cend()); |
4037 |
25 Jan 21 |
peter |
70 |
if (cdist != 4) { |
4037 |
25 Jan 21 |
peter |
71 |
suite.add(false); |
4037 |
25 Jan 21 |
peter |
72 |
suite.err() << "error: incorrect const distance: " << cdist << "\n"; |
4037 |
25 Jan 21 |
peter |
73 |
} |
4037 |
25 Jan 21 |
peter |
74 |
int rdist = std::distance(ranking.rbegin(), ranking.rend()); |
4037 |
25 Jan 21 |
peter |
75 |
if (rdist != 4) { |
4037 |
25 Jan 21 |
peter |
76 |
suite.add(false); |
4037 |
25 Jan 21 |
peter |
77 |
suite.err() << "error: incorrect reverse distance: " << rdist << "\n"; |
4037 |
25 Jan 21 |
peter |
78 |
} |
4037 |
25 Jan 21 |
peter |
79 |
int crdist = std::distance(ranking.crbegin(), ranking.crend()); |
4037 |
25 Jan 21 |
peter |
80 |
if (crdist != 4) { |
4037 |
25 Jan 21 |
peter |
81 |
suite.add(false); |
4037 |
25 Jan 21 |
peter |
82 |
suite.err() << "error: incorrect const reverse distance: " |
4037 |
25 Jan 21 |
peter |
83 |
<< crdist << "\n"; |
4037 |
25 Jan 21 |
peter |
84 |
} |
4037 |
25 Jan 21 |
peter |
85 |
|
4064 |
05 Aug 21 |
peter |
// try to find lower bound for a large value |
4064 |
05 Aug 21 |
peter |
87 |
utility::Ranking<double>::iterator lower = ranking.lower_bound(10000); |
4064 |
05 Aug 21 |
peter |
88 |
if (lower != ranking.end()) { |
4064 |
05 Aug 21 |
peter |
89 |
suite.add(false); |
4064 |
05 Aug 21 |
peter |
90 |
suite.err() << "ranking.lower_bound(10000) expected ranking.end()\n"; |
4064 |
05 Aug 21 |
peter |
91 |
} |
4064 |
05 Aug 21 |
peter |
92 |
lower = ranking.lower_bound(1); |
4037 |
25 Jan 21 |
peter |
93 |
if (*lower != 1) { |
4037 |
25 Jan 21 |
peter |
94 |
suite.add(false); |
4037 |
25 Jan 21 |
peter |
95 |
suite.err() << "error: *lower returned: " << *lower << "\n"; |
4037 |
25 Jan 21 |
peter |
96 |
} |
4064 |
05 Aug 21 |
peter |
97 |
|
4064 |
05 Aug 21 |
peter |
// try to find upper bound for a large value |
4064 |
05 Aug 21 |
peter |
99 |
utility::Ranking<double>::iterator upper = ranking.upper_bound(10000); |
4064 |
05 Aug 21 |
peter |
100 |
if (upper != ranking.end()) { |
4064 |
05 Aug 21 |
peter |
101 |
suite.add(false); |
4064 |
05 Aug 21 |
peter |
102 |
suite.err() << "ranking.upper_bound(10000) expected ranking.end()\n"; |
4064 |
05 Aug 21 |
peter |
103 |
} |
4064 |
05 Aug 21 |
peter |
104 |
upper = ranking.upper_bound(1); |
4037 |
25 Jan 21 |
peter |
105 |
if (*upper != 2) { |
4037 |
25 Jan 21 |
peter |
106 |
suite.add(false); |
4037 |
25 Jan 21 |
peter |
107 |
suite.err() << "error: *upper returned: " << *upper << "\n"; |
4037 |
25 Jan 21 |
peter |
108 |
} |
4064 |
05 Aug 21 |
peter |
109 |
|
4037 |
25 Jan 21 |
peter |
110 |
dist = std::distance(lower, upper); |
4037 |
25 Jan 21 |
peter |
111 |
if (dist != 2) { |
4037 |
25 Jan 21 |
peter |
112 |
suite.add(false); |
4037 |
25 Jan 21 |
peter |
113 |
suite.err() << "error: distance(lower, upper): " << dist << "\n"; |
4037 |
25 Jan 21 |
peter |
114 |
} |
4037 |
25 Jan 21 |
peter |
115 |
|
4037 |
25 Jan 21 |
peter |
116 |
std::vector<int> vec(10); |
4037 |
25 Jan 21 |
peter |
117 |
ranking.insert(vec.begin(), vec.end()); |
4037 |
25 Jan 21 |
peter |
118 |
} |
4037 |
25 Jan 21 |
peter |
119 |
|
4037 |
25 Jan 21 |
peter |
120 |
|
4037 |
25 Jan 21 |
peter |
121 |
void test2(test::Suite& suite) |
4037 |
25 Jan 21 |
peter |
122 |
{ |
4069 |
06 Aug 21 |
peter |
123 |
suite.out() << YAT_TEST_PROLOGUE; |
4064 |
05 Aug 21 |
peter |
// mimick how Ranking is used in Kendall::score |
4037 |
25 Jan 21 |
peter |
125 |
utility::Ranking<double> ranking; |
4037 |
25 Jan 21 |
peter |
126 |
auto lower = ranking.lower_bound(2); |
4037 |
25 Jan 21 |
peter |
127 |
int r = ranking.ranking(lower); |
4037 |
25 Jan 21 |
peter |
128 |
suite.out() << "ranking: " << r << "\n"; |
4037 |
25 Jan 21 |
peter |
129 |
if (r != 0) { |
4037 |
25 Jan 21 |
peter |
130 |
suite.add(false); |
4037 |
25 Jan 21 |
peter |
131 |
suite.err() << "error: incorrect; expected 0\n"; |
4037 |
25 Jan 21 |
peter |
132 |
} |
4037 |
25 Jan 21 |
peter |
133 |
ranking.insert(lower, 2); |
4037 |
25 Jan 21 |
peter |
134 |
|
4037 |
25 Jan 21 |
peter |
135 |
lower = ranking.lower_bound(1); |
4037 |
25 Jan 21 |
peter |
136 |
r = ranking.ranking(lower); |
4037 |
25 Jan 21 |
peter |
137 |
suite.out() << "ranking: " << r << "\n"; |
4037 |
25 Jan 21 |
peter |
138 |
if (r != 0) { |
4037 |
25 Jan 21 |
peter |
139 |
suite.add(false); |
4037 |
25 Jan 21 |
peter |
140 |
suite.err() << "error: incorrect; expected 0\n"; |
4037 |
25 Jan 21 |
peter |
141 |
} |
4037 |
25 Jan 21 |
peter |
142 |
ranking.insert(lower, 1); |
4037 |
25 Jan 21 |
peter |
143 |
|
4037 |
25 Jan 21 |
peter |
144 |
lower = ranking.lower_bound(3); |
4064 |
05 Aug 21 |
peter |
145 |
if (lower != ranking.cend()) { |
4064 |
05 Aug 21 |
peter |
146 |
suite.add(false); |
4064 |
05 Aug 21 |
peter |
147 |
suite.err() << "error: expected ranking.lower_bound(3) to return end()\n"; |
4064 |
05 Aug 21 |
peter |
148 |
} |
4064 |
05 Aug 21 |
peter |
149 |
suite.out() << "values in ranking object:\n"; |
4064 |
05 Aug 21 |
peter |
150 |
for (auto it=ranking.cbegin(); it!=ranking.cend(); ++it) |
4064 |
05 Aug 21 |
peter |
151 |
suite.out() << "value: " << *it << "\n"; |
4064 |
05 Aug 21 |
peter |
152 |
size_t n = ranking.size(); |
4064 |
05 Aug 21 |
peter |
153 |
if (n != 2) { |
4064 |
05 Aug 21 |
peter |
154 |
suite.add(false); |
4064 |
05 Aug 21 |
peter |
155 |
suite.err() << "::size() returns " << n << "; expected 2\n"; |
4064 |
05 Aug 21 |
peter |
156 |
} |
4064 |
05 Aug 21 |
peter |
157 |
n = std::distance(ranking.cbegin(), ranking.cend()); |
4064 |
05 Aug 21 |
peter |
158 |
if (n!=2) { |
4064 |
05 Aug 21 |
peter |
159 |
suite.add(false); |
4064 |
05 Aug 21 |
peter |
160 |
suite.err() << "distance(begin, end) returns " << n << "; expected 2\n"; |
4064 |
05 Aug 21 |
peter |
161 |
} |
4064 |
05 Aug 21 |
peter |
162 |
|
4037 |
25 Jan 21 |
peter |
163 |
r = ranking.ranking(lower); |
4037 |
25 Jan 21 |
peter |
164 |
suite.out() << "ranking: " << r << "\n"; |
4037 |
25 Jan 21 |
peter |
165 |
if (r != 2) { |
4037 |
25 Jan 21 |
peter |
166 |
suite.add(false); |
4037 |
25 Jan 21 |
peter |
167 |
suite.err() << "error: incorrect; expected 2\n"; |
4037 |
25 Jan 21 |
peter |
168 |
} |
4037 |
25 Jan 21 |
peter |
169 |
} |
4037 |
25 Jan 21 |
peter |
170 |
|
4037 |
25 Jan 21 |
peter |
171 |
|
4069 |
06 Aug 21 |
peter |
172 |
void test_copy(test::Suite& suite) |
4069 |
06 Aug 21 |
peter |
173 |
{ |
4069 |
06 Aug 21 |
peter |
174 |
suite.out() << YAT_TEST_PROLOGUE; |
4069 |
06 Aug 21 |
peter |
175 |
utility::Ranking<double> ranking; |
4069 |
06 Aug 21 |
peter |
176 |
ranking.insert(0); |
4069 |
06 Aug 21 |
peter |
177 |
ranking.insert(1); |
4069 |
06 Aug 21 |
peter |
178 |
ranking.insert(-1); |
4069 |
06 Aug 21 |
peter |
179 |
|
4069 |
06 Aug 21 |
peter |
180 |
suite.out() << "test copy constructor\n"; |
4069 |
06 Aug 21 |
peter |
181 |
utility::Ranking<double> ranking2(ranking); |
4069 |
06 Aug 21 |
peter |
182 |
int n = std::distance(ranking.begin(), ranking.end()); |
4069 |
06 Aug 21 |
peter |
183 |
if (n != 3) { |
4069 |
06 Aug 21 |
peter |
184 |
suite.add(false); |
4069 |
06 Aug 21 |
peter |
185 |
suite.err() << "ranking distance: " << n << "\n"; |
4069 |
06 Aug 21 |
peter |
186 |
} |
4069 |
06 Aug 21 |
peter |
187 |
|
4069 |
06 Aug 21 |
peter |
188 |
n = std::distance(ranking2.begin(), ranking2.end()); |
4069 |
06 Aug 21 |
peter |
189 |
if (n != 3) { |
4069 |
06 Aug 21 |
peter |
190 |
suite.add(false); |
4069 |
06 Aug 21 |
peter |
191 |
suite.err() << "error: copy constructor failed\n"; |
4069 |
06 Aug 21 |
peter |
192 |
suite.err() << "ranking2 distance: " << n << "\n"; |
4069 |
06 Aug 21 |
peter |
193 |
for (auto it = ranking2.cbegin(); it!=ranking2.cend(); ++it) |
4069 |
06 Aug 21 |
peter |
194 |
suite.err() << "value: " << *it << "\n"; |
4069 |
06 Aug 21 |
peter |
195 |
} |
4069 |
06 Aug 21 |
peter |
196 |
|
4069 |
06 Aug 21 |
peter |
197 |
utility::Ranking<double> ranking3; |
4069 |
06 Aug 21 |
peter |
198 |
ranking3.insert(10); |
4069 |
06 Aug 21 |
peter |
199 |
suite.out() << "test copy assignment\n"; |
4069 |
06 Aug 21 |
peter |
200 |
ranking3 = ranking2; |
4069 |
06 Aug 21 |
peter |
201 |
n = std::distance(ranking3.begin(), ranking3.end()); |
4069 |
06 Aug 21 |
peter |
202 |
if (n != 3) { |
4069 |
06 Aug 21 |
peter |
203 |
suite.add(false); |
4069 |
06 Aug 21 |
peter |
204 |
suite.err() << "error: assignment failed\n"; |
4069 |
06 Aug 21 |
peter |
205 |
suite.err() << "ranking3 distance: " << n << "\n"; |
4069 |
06 Aug 21 |
peter |
206 |
} |
4069 |
06 Aug 21 |
peter |
207 |
|
4069 |
06 Aug 21 |
peter |
208 |
suite.out() << "test move constructor\n"; |
4069 |
06 Aug 21 |
peter |
209 |
utility::Ranking<double> ranking4(std::move(ranking3)); |
4069 |
06 Aug 21 |
peter |
210 |
n = std::distance(ranking4.begin(), ranking4.end()); |
4069 |
06 Aug 21 |
peter |
211 |
if (n != 3) { |
4069 |
06 Aug 21 |
peter |
212 |
suite.add(false); |
4069 |
06 Aug 21 |
peter |
213 |
suite.err() << "error: move constructor failed\n"; |
4069 |
06 Aug 21 |
peter |
214 |
suite.err() << "ranking4 distance: " << n << "\n"; |
4069 |
06 Aug 21 |
peter |
215 |
} |
4069 |
06 Aug 21 |
peter |
216 |
|
4069 |
06 Aug 21 |
peter |
217 |
suite.out() << "test move assignment\n"; |
4069 |
06 Aug 21 |
peter |
218 |
ranking4 = std::move(ranking2); |
4069 |
06 Aug 21 |
peter |
219 |
n = std::distance(ranking4.begin(), ranking4.end()); |
4069 |
06 Aug 21 |
peter |
220 |
if (n != 3) { |
4069 |
06 Aug 21 |
peter |
221 |
suite.add(false); |
4069 |
06 Aug 21 |
peter |
222 |
suite.err() << "error: move assignment failed\n"; |
4069 |
06 Aug 21 |
peter |
223 |
suite.err() << "ranking4 distance: " << n << "\n"; |
4069 |
06 Aug 21 |
peter |
224 |
} |
4069 |
06 Aug 21 |
peter |
225 |
} |
4069 |
06 Aug 21 |
peter |
226 |
|
4069 |
06 Aug 21 |
peter |
227 |
|
4070 |
09 Aug 21 |
peter |
228 |
void test_erase(test::Suite& suite) |
4070 |
09 Aug 21 |
peter |
229 |
{ |
4070 |
09 Aug 21 |
peter |
230 |
suite.out() << YAT_TEST_PROLOGUE; |
4070 |
09 Aug 21 |
peter |
231 |
|
4070 |
09 Aug 21 |
peter |
232 |
utility::Ranking<double> ranking; |
4070 |
09 Aug 21 |
peter |
233 |
ranking.insert(1); |
4070 |
09 Aug 21 |
peter |
234 |
ranking.insert(2); |
4070 |
09 Aug 21 |
peter |
235 |
ranking.insert(3); |
4070 |
09 Aug 21 |
peter |
236 |
auto it = ranking.find(2); |
4070 |
09 Aug 21 |
peter |
237 |
suite.out() << "test erase(iterator)\n"; |
4070 |
09 Aug 21 |
peter |
238 |
ranking.erase(it); |
4070 |
09 Aug 21 |
peter |
239 |
int n = ranking.size(); |
4070 |
09 Aug 21 |
peter |
240 |
if (n != 2) { |
4070 |
09 Aug 21 |
peter |
241 |
suite.add(false); |
4070 |
09 Aug 21 |
peter |
242 |
suite.err() << "error: size() = " << n << "; expected 2\n"; |
4070 |
09 Aug 21 |
peter |
243 |
} |
4070 |
09 Aug 21 |
peter |
244 |
n = std::distance(ranking.begin(), ranking.end()); |
4070 |
09 Aug 21 |
peter |
245 |
if (n != 2) { |
4070 |
09 Aug 21 |
peter |
246 |
suite.add(false); |
4070 |
09 Aug 21 |
peter |
247 |
suite.err() << "error: distance = " << n << "; expected 2\n"; |
4070 |
09 Aug 21 |
peter |
248 |
} |
4070 |
09 Aug 21 |
peter |
249 |
|
4070 |
09 Aug 21 |
peter |
250 |
suite.out() << "test erase(value)\n"; |
4070 |
09 Aug 21 |
peter |
251 |
ranking.insert(2); |
4070 |
09 Aug 21 |
peter |
252 |
ranking.erase(2); |
4070 |
09 Aug 21 |
peter |
253 |
n = ranking.size(); |
4070 |
09 Aug 21 |
peter |
254 |
if (n != 2) { |
4070 |
09 Aug 21 |
peter |
255 |
suite.add(false); |
4070 |
09 Aug 21 |
peter |
256 |
suite.err() << "error: size() = " << n << "; expected 2\n"; |
4070 |
09 Aug 21 |
peter |
257 |
} |
4070 |
09 Aug 21 |
peter |
258 |
n = std::distance(ranking.begin(), ranking.end()); |
4070 |
09 Aug 21 |
peter |
259 |
if (n != 2) { |
4070 |
09 Aug 21 |
peter |
260 |
suite.add(false); |
4070 |
09 Aug 21 |
peter |
261 |
suite.err() << "error: distance = " << n << "; expected 2\n"; |
4070 |
09 Aug 21 |
peter |
262 |
} |
4070 |
09 Aug 21 |
peter |
263 |
|
4070 |
09 Aug 21 |
peter |
264 |
suite.out() << "test erase(iterator, iterator)\n"; |
4070 |
09 Aug 21 |
peter |
265 |
ranking.insert(2); |
4070 |
09 Aug 21 |
peter |
266 |
ranking.insert(4); |
4070 |
09 Aug 21 |
peter |
267 |
ranking.insert(0); |
4070 |
09 Aug 21 |
peter |
268 |
auto lower = ranking.lower_bound(1); |
4070 |
09 Aug 21 |
peter |
269 |
auto upper = ranking.find(3); |
4070 |
09 Aug 21 |
peter |
// erase { 1, 2} |
4070 |
09 Aug 21 |
peter |
271 |
ranking.erase(lower, upper); |
4070 |
09 Aug 21 |
peter |
272 |
n = ranking.size(); |
4070 |
09 Aug 21 |
peter |
273 |
if (n != 3) { |
4070 |
09 Aug 21 |
peter |
274 |
suite.add(false); |
4070 |
09 Aug 21 |
peter |
275 |
suite.err() << "error: size() = " << n << "; expected 3\n"; |
4070 |
09 Aug 21 |
peter |
276 |
} |
4070 |
09 Aug 21 |
peter |
277 |
n = std::distance(ranking.begin(), ranking.end()); |
4070 |
09 Aug 21 |
peter |
278 |
if (n != 3) { |
4070 |
09 Aug 21 |
peter |
279 |
suite.add(false); |
4070 |
09 Aug 21 |
peter |
280 |
suite.err() << "error: distance = " << n << "; expected 3\n"; |
4070 |
09 Aug 21 |
peter |
281 |
} |
4070 |
09 Aug 21 |
peter |
282 |
} |
4070 |
09 Aug 21 |
peter |
283 |
|
4070 |
09 Aug 21 |
peter |
284 |
|
4077 |
26 Aug 21 |
peter |
285 |
void test_insert_hint(test::Suite& suite) |
4077 |
26 Aug 21 |
peter |
286 |
{ |
4077 |
26 Aug 21 |
peter |
287 |
suite.out() << YAT_TEST_PROLOGUE; |
4077 |
26 Aug 21 |
peter |
288 |
|
4077 |
26 Aug 21 |
peter |
289 |
utility::Ranking<double> ranking; |
4077 |
26 Aug 21 |
peter |
290 |
ranking.insert(1); |
4077 |
26 Aug 21 |
peter |
291 |
ranking.insert(2); |
4077 |
26 Aug 21 |
peter |
292 |
ranking.insert(3); |
4077 |
26 Aug 21 |
peter |
293 |
|
4077 |
26 Aug 21 |
peter |
294 |
auto hint = ranking.lower_bound(2); |
4077 |
26 Aug 21 |
peter |
295 |
ranking.insert(hint, 2); |
4077 |
26 Aug 21 |
peter |
296 |
ranking.insert(hint, 1); |
4077 |
26 Aug 21 |
peter |
297 |
ranking.insert(hint, 0); |
4077 |
26 Aug 21 |
peter |
298 |
ranking.insert(hint, 3); |
4077 |
26 Aug 21 |
peter |
299 |
ranking.insert(hint, 4); |
4077 |
26 Aug 21 |
peter |
300 |
hint = ranking.lower_bound(4); |
4077 |
26 Aug 21 |
peter |
301 |
ranking.insert(hint, 5); |
4077 |
26 Aug 21 |
peter |
302 |
|
4077 |
26 Aug 21 |
peter |
303 |
hint = ranking.lower_bound(4); |
4077 |
26 Aug 21 |
peter |
304 |
ranking.insert(hint, 4.1); |
4077 |
26 Aug 21 |
peter |
305 |
} |
4077 |
26 Aug 21 |
peter |
306 |
|
4077 |
26 Aug 21 |
peter |
307 |
|
4037 |
25 Jan 21 |
peter |
308 |
int main(int argc, char* argv[]) |
4037 |
25 Jan 21 |
peter |
309 |
{ |
4037 |
25 Jan 21 |
peter |
310 |
test::Suite suite(argc, argv); |
4037 |
25 Jan 21 |
peter |
311 |
try { |
4037 |
25 Jan 21 |
peter |
312 |
test1(suite); |
4037 |
25 Jan 21 |
peter |
313 |
test2(suite); |
4069 |
06 Aug 21 |
peter |
314 |
test_copy(suite); |
4070 |
09 Aug 21 |
peter |
315 |
test_erase(suite); |
4077 |
26 Aug 21 |
peter |
316 |
test_insert_hint(suite); |
4037 |
25 Jan 21 |
peter |
317 |
} |
4037 |
25 Jan 21 |
peter |
318 |
catch (std::exception& e) { |
4037 |
25 Jan 21 |
peter |
319 |
suite.add(false); |
4037 |
25 Jan 21 |
peter |
320 |
suite.err() << "error: exception caught: what(): "; |
4037 |
25 Jan 21 |
peter |
321 |
utility::print_what(e, suite.err()); |
4037 |
25 Jan 21 |
peter |
322 |
} |
4037 |
25 Jan 21 |
peter |
323 |
return suite.return_value(); |
4037 |
25 Jan 21 |
peter |
324 |
} |