basedOpinionated utility library |
git clone git://git.dimitrijedobrota.com/based.git |
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING |
min_test.cpp (7953B)
0 #define CATCH_CONFIG_RUNTIME_STATIC_REQUIRE
2 #include "based/algorithms/min.hpp"
4 #include <catch2/catch_test_macros.hpp>
6 #include "based/utility/move.hpp"
8 // NOLINTBEGIN(*const-arg*,*const-correctness*,*after-move, *access-moved)
10 TEST_CASE("min(literal, literal) = left", "[algorithm/min]")
11 {
12 using res_t = decltype(based::min(3, 4));
14 STATIC_REQUIRE(based::SameAs<int&&, res_t>);
15 REQUIRE(based::min(3, 4) == 3);
16 }
18 TEST_CASE("min(literal, literal) = right", "[algorithm/min]")
19 {
20 using res_t = decltype(based::min(4, 3));
22 STATIC_REQUIRE(based::SameAs<int&&, res_t>);
23 REQUIRE(based::min(4, 3) == 3);
24 }
26 TEST_CASE("min(value, literal) = left", "[algorithm/min]")
27 {
28 int a = 3;
30 using res_t = decltype(based::min(a, 4));
32 STATIC_REQUIRE(based::SameAs<int, res_t>);
33 REQUIRE(based::min(a, 4) == 3);
34 }
36 TEST_CASE("min(value, literal) = right", "[algorithm/min]")
37 {
38 int a = 4;
40 using res_t = decltype(based::min(a, 3));
42 STATIC_REQUIRE(based::SameAs<int, res_t>);
43 REQUIRE(based::min(a, 3) == 3);
44 }
46 TEST_CASE("min(literal, value) = left", "[algorithm/min]")
47 {
48 int b = 4;
50 using res_t = decltype(based::min(3, b));
52 STATIC_REQUIRE(based::SameAs<int, res_t>);
53 REQUIRE(based::min(3, b) == 3);
54 }
56 TEST_CASE("min(literal, value) = right", "[algorithm/min]")
57 {
58 int b = 3;
60 using res_t = decltype(based::min(4, b));
62 STATIC_REQUIRE(based::SameAs<int, res_t>);
63 REQUIRE(based::min(4, b) == 3);
64 }
66 TEST_CASE("min(value, value) = left", "[algorithm/min]")
67 {
68 int a = 3;
69 int b = 4;
71 using res_t = decltype(based::min(a, b));
73 STATIC_REQUIRE(based::SameAs<int&, res_t>);
74 REQUIRE(based::min(a, b) == 3);
75 }
77 TEST_CASE("min(value, value) = right", "[algorithm/min]")
78 {
79 int a = 4;
80 int b = 3;
82 using res_t = decltype(based::min(a, b));
84 STATIC_REQUIRE(based::SameAs<int&, res_t>);
85 REQUIRE(based::min(a, b) == 3);
86 }
88 TEST_CASE("min(const value, literal) = left", "[algorithm/min]")
89 {
90 const int a = 3;
92 using res_t = decltype(based::min(a, 4));
94 STATIC_REQUIRE(based::SameAs<int, res_t>);
95 REQUIRE(based::min(a, 4) == 3);
96 }
98 TEST_CASE("min(const value, literal) = right", "[algorithm/min]")
99 {
100 const int a = 4;
102 using res_t = decltype(based::min(a, 3));
104 STATIC_REQUIRE(based::SameAs<int, res_t>);
105 REQUIRE(based::min(a, 3) == 3);
106 }
108 TEST_CASE("min(literal, const value) = left", "[algorithm/min]")
109 {
110 const int b = 4;
112 using res_t = decltype(based::min(3, b));
114 STATIC_REQUIRE(based::SameAs<int, res_t>);
115 REQUIRE(based::min(3, b) == 3);
116 }
118 TEST_CASE("min(literal, const value) = right", "[algorithm/min]")
119 {
120 const int b = 3;
122 using res_t = decltype(based::min(4, b));
124 STATIC_REQUIRE(based::SameAs<int, res_t>);
125 REQUIRE(based::min(4, b) == 3);
126 }
128 TEST_CASE("min(const value, const value) = left", "[algorithm/min]")
129 {
130 const int a = 3;
131 const int b = 4;
133 using res_t = decltype(based::min(a, b));
135 STATIC_REQUIRE(based::SameAs<const int&, res_t>);
136 REQUIRE(based::min(a, b) == 3);
137 }
139 TEST_CASE("min(const value, const value) = right", "[algorithm/min]")
140 {
141 const int a = 4;
142 const int b = 3;
144 using res_t = decltype(based::min(a, b));
146 STATIC_REQUIRE(based::SameAs<const int&, res_t>);
147 REQUIRE(based::min(a, b) == 3);
148 }
150 TEST_CASE("min(value, const value) = left", "[algorithm/min]")
151 {
152 int a = 3;
153 const int b = 4;
155 using res_t = decltype(based::min(a, b));
157 STATIC_REQUIRE(based::SameAs<const int&, res_t>);
158 REQUIRE(based::min(a, b) == 3);
159 }
161 TEST_CASE("min(value, const value) = right", "[algorithm/min]")
162 {
163 int a = 4;
164 const int b = 3;
166 using res_t = decltype(based::min(a, b));
168 STATIC_REQUIRE(based::SameAs<const int&, res_t>);
169 REQUIRE(based::min(a, b) == 3);
170 }
172 TEST_CASE("min(const value, value) = left", "[algorithm/min]")
173 {
174 const int a = 3;
175 int b = 4;
177 using res_t = decltype(based::min(a, b));
179 STATIC_REQUIRE(based::SameAs<const int&, res_t>);
180 REQUIRE(based::min(a, b) == 3);
181 }
183 TEST_CASE("min(const value, value) = right", "[algorithm/min]")
184 {
185 const int a = 4;
186 int b = 3;
188 using res_t = decltype(based::min(a, b));
190 STATIC_REQUIRE(based::SameAs<const int&, res_t>);
191 REQUIRE(based::min(a, b) == 3);
192 }
194 TEST_CASE("min(move, literal) = left", "[algorithm/min]")
195 {
196 int a = 3;
198 using res_t = decltype(based::min(based::move(a), 4));
200 STATIC_REQUIRE(based::SameAs<int&&, res_t>);
201 REQUIRE(based::min(based::move(a), 4) == 3);
202 }
204 TEST_CASE("min(move, literal) = right", "[algorithm/min]")
205 {
206 int a = 4;
208 using res_t = decltype(based::min(based::move(a), 3));
210 STATIC_REQUIRE(based::SameAs<int&&, res_t>);
211 REQUIRE(based::min(based::move(a), 3) == 3);
212 }
214 TEST_CASE("min(move, value) = left", "[algorithm/min]")
215 {
216 int a = 3;
217 int b = 4;
219 using res_t = decltype(based::min(based::move(a), b));
221 STATIC_REQUIRE(based::SameAs<int, res_t>);
222 REQUIRE(based::min(based::move(a), b) == 3);
223 }
225 TEST_CASE("min(move, value) = right", "[algorithm/min]")
226 {
227 int a = 4;
228 int b = 3;
230 using res_t = decltype(based::min(based::move(a), b));
232 STATIC_REQUIRE(based::SameAs<int, res_t>);
233 REQUIRE(based::min(based::move(a), b) == 3);
234 }
236 TEST_CASE("min(move, const value) = left", "[algorithm/min]")
237 {
238 int a = 3;
239 const int b = 4;
241 using res_t = decltype(based::min(based::move(a), b));
243 STATIC_REQUIRE(based::SameAs<int, res_t>);
244 REQUIRE(based::min(based::move(a), b) == 3);
245 }
247 TEST_CASE("min(move, const value) = right", "[algorithm/min]")
248 {
249 int a = 4;
250 const int b = 3;
252 using res_t = decltype(based::min(based::move(a), b));
254 STATIC_REQUIRE(based::SameAs<int, res_t>);
255 REQUIRE(based::min(based::move(a), b) == 3);
256 }
258 TEST_CASE("min(literal, move) = left", "[algorithm/min]")
259 {
260 int b = 4;
262 using res_t = decltype(based::min(3, based::move(b)));
264 STATIC_REQUIRE(based::SameAs<int&&, res_t>);
265 REQUIRE(based::min(3, based::move(b)) == 3);
266 }
268 TEST_CASE("min(literal, move) = right", "[algorithm/min]")
269 {
270 int b = 3;
272 using res_t = decltype(based::min(4, based::move(b)));
274 STATIC_REQUIRE(based::SameAs<int&&, res_t>);
275 REQUIRE(based::min(4, based::move(b)) == 3);
276 }
278 TEST_CASE("min(value, move) = left", "[algorithm/min]")
279 {
280 int a = 3;
281 int b = 4;
283 using res_t = decltype(based::min(a, based::move(b)));
285 STATIC_REQUIRE(based::SameAs<int, res_t>);
286 REQUIRE(based::min(a, based::move(b)) == 3);
287 }
289 TEST_CASE("min(value, move) = right", "[algorithm/min]")
290 {
291 int a = 4;
292 int b = 3;
294 using res_t = decltype(based::min(a, based::move(b)));
296 STATIC_REQUIRE(based::SameAs<int, res_t>);
297 REQUIRE(based::min(a, based::move(b)) == 3);
298 }
300 TEST_CASE("min(const value, move) = left", "[algorithm/min]")
301 {
302 const int a = 3;
303 int b = 4;
305 using res_t = decltype(based::min(a, based::move(b)));
307 STATIC_REQUIRE(based::SameAs<int, res_t>);
308 REQUIRE(based::min(a, based::move(b)) == 3);
309 }
311 TEST_CASE("min(const value, move) = right", "[algorithm/min]")
312 {
313 const int a = 4;
314 int b = 3;
316 using res_t = decltype(based::min(a, based::move(b)));
318 STATIC_REQUIRE(based::SameAs<int, res_t>);
319 REQUIRE(based::min(a, based::move(b)) == 3);
320 }
322 TEST_CASE("min(move, move) = left", "[algorithm/min]")
323 {
324 int a = 3;
325 int b = 4;
327 using res_t = decltype(based::min(based::move(a), based::move(b)));
329 STATIC_REQUIRE(based::SameAs<int&&, res_t>);
330 REQUIRE(based::min(based::move(a), based::move(b)) == 3);
331 }
333 TEST_CASE("min(move, move) = right", "[algorithm/min]")
334 {
335 int a = 4;
336 int b = 3;
338 using res_t = decltype(based::min(based::move(a), based::move(b)));
340 STATIC_REQUIRE(based::SameAs<int&&, res_t>);
341 REQUIRE(based::min(based::move(a), based::move(b)) == 3);
342 }
344 // NOLINTEND(*const-arg*,*const-correctness*,*after-move, *access-moved)
346 TEST_CASE("min-stability", "[algorithm/min]")
347 {
348 using type_t = std::pair<int, int>;
350 static const auto cmp = [](const type_t& x, const type_t& y)
351 {
352 return x.first < y.first;
353 };
355 const type_t a = {3, 4};
356 const type_t b = {3, 5};
358 REQUIRE(based::min(a, b, cmp).second == 4);
359 REQUIRE(based::min(b, a, cmp).second == 5);
360 }