based

Opinionated utility library
git clone git://git.dimitrijedobrota.com/based.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING

min_test.cpp (8107B)


0 #define CATCH_CONFIG_RUNTIME_STATIC_REQUIRE
2 #include "based/algorithm/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 ResT = decltype(based::min(3, 4));
14 STATIC_REQUIRE(based::trait::IsSame<int&&, ResT>);
15 REQUIRE(based::min(3, 4) == 3);
16 }
18 TEST_CASE("min(literal, literal) = right", "[algorithm/min]")
19 {
20 using ResT = decltype(based::min(4, 3));
22 STATIC_REQUIRE(based::trait::IsSame<int&&, ResT>);
23 REQUIRE(based::min(4, 3) == 3);
24 }
26 TEST_CASE("min(value, literal) = left", "[algorithm/min]")
27 {
28 int a = 3;
30 using ResT = decltype(based::min(a, 4));
32 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
33 REQUIRE(based::min(a, 4) == 3);
34 }
36 TEST_CASE("min(value, literal) = right", "[algorithm/min]")
37 {
38 int a = 4;
40 using ResT = decltype(based::min(a, 3));
42 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
43 REQUIRE(based::min(a, 3) == 3);
44 }
46 TEST_CASE("min(literal, value) = left", "[algorithm/min]")
47 {
48 int b = 4;
50 using ResT = decltype(based::min(3, b));
52 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
53 REQUIRE(based::min(3, b) == 3);
54 }
56 TEST_CASE("min(literal, value) = right", "[algorithm/min]")
57 {
58 int b = 3;
60 using ResT = decltype(based::min(4, b));
62 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
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 ResT = decltype(based::min(a, b));
73 STATIC_REQUIRE(based::trait::IsSame<int&, ResT>);
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 ResT = decltype(based::min(a, b));
84 STATIC_REQUIRE(based::trait::IsSame<int&, ResT>);
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 ResT = decltype(based::min(a, 4));
94 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
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 ResT = decltype(based::min(a, 3));
104 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
105 REQUIRE(based::min(a, 3) == 3);
108 TEST_CASE("min(literal, const value) = left", "[algorithm/min]")
110 const int b = 4;
112 using ResT = decltype(based::min(3, b));
114 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
115 REQUIRE(based::min(3, b) == 3);
118 TEST_CASE("min(literal, const value) = right", "[algorithm/min]")
120 const int b = 3;
122 using ResT = decltype(based::min(4, b));
124 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
125 REQUIRE(based::min(4, b) == 3);
128 TEST_CASE("min(const value, const value) = left", "[algorithm/min]")
130 const int a = 3;
131 const int b = 4;
133 using ResT = decltype(based::min(a, b));
135 STATIC_REQUIRE(based::trait::IsSame<const int&, ResT>);
136 REQUIRE(based::min(a, b) == 3);
139 TEST_CASE("min(const value, const value) = right", "[algorithm/min]")
141 const int a = 4;
142 const int b = 3;
144 using ResT = decltype(based::min(a, b));
146 STATIC_REQUIRE(based::trait::IsSame<const int&, ResT>);
147 REQUIRE(based::min(a, b) == 3);
150 TEST_CASE("min(value, const value) = left", "[algorithm/min]")
152 int a = 3;
153 const int b = 4;
155 using ResT = decltype(based::min(a, b));
157 STATIC_REQUIRE(based::trait::IsSame<const int&, ResT>);
158 REQUIRE(based::min(a, b) == 3);
161 TEST_CASE("min(value, const value) = right", "[algorithm/min]")
163 int a = 4;
164 const int b = 3;
166 using ResT = decltype(based::min(a, b));
168 STATIC_REQUIRE(based::trait::IsSame<const int&, ResT>);
169 REQUIRE(based::min(a, b) == 3);
172 TEST_CASE("min(const value, value) = left", "[algorithm/min]")
174 const int a = 3;
175 int b = 4;
177 using ResT = decltype(based::min(a, b));
179 STATIC_REQUIRE(based::trait::IsSame<const int&, ResT>);
180 REQUIRE(based::min(a, b) == 3);
183 TEST_CASE("min(const value, value) = right", "[algorithm/min]")
185 const int a = 4;
186 int b = 3;
188 using ResT = decltype(based::min(a, b));
190 STATIC_REQUIRE(based::trait::IsSame<const int&, ResT>);
191 REQUIRE(based::min(a, b) == 3);
194 TEST_CASE("min(move, literal) = left", "[algorithm/min]")
196 int a = 3;
198 using ResT = decltype(based::min(based::move(a), 4));
200 STATIC_REQUIRE(based::trait::IsSame<int&&, ResT>);
201 REQUIRE(based::min(based::move(a), 4) == 3);
204 TEST_CASE("min(move, literal) = right", "[algorithm/min]")
206 int a = 4;
208 using ResT = decltype(based::min(based::move(a), 3));
210 STATIC_REQUIRE(based::trait::IsSame<int&&, ResT>);
211 REQUIRE(based::min(based::move(a), 3) == 3);
214 TEST_CASE("min(move, value) = left", "[algorithm/min]")
216 int a = 3;
217 int b = 4;
219 using ResT = decltype(based::min(based::move(a), b));
221 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
222 REQUIRE(based::min(based::move(a), b) == 3);
225 TEST_CASE("min(move, value) = right", "[algorithm/min]")
227 int a = 4;
228 int b = 3;
230 using ResT = decltype(based::min(based::move(a), b));
232 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
233 REQUIRE(based::min(based::move(a), b) == 3);
236 TEST_CASE("min(move, const value) = left", "[algorithm/min]")
238 int a = 3;
239 const int b = 4;
241 using ResT = decltype(based::min(based::move(a), b));
243 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
244 REQUIRE(based::min(based::move(a), b) == 3);
247 TEST_CASE("min(move, const value) = right", "[algorithm/min]")
249 int a = 4;
250 const int b = 3;
252 using ResT = decltype(based::min(based::move(a), b));
254 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
255 REQUIRE(based::min(based::move(a), b) == 3);
258 TEST_CASE("min(literal, move) = left", "[algorithm/min]")
260 int b = 4;
262 using ResT = decltype(based::min(3, based::move(b)));
264 STATIC_REQUIRE(based::trait::IsSame<int&&, ResT>);
265 REQUIRE(based::min(3, based::move(b)) == 3);
268 TEST_CASE("min(literal, move) = right", "[algorithm/min]")
270 int b = 3;
272 using ResT = decltype(based::min(4, based::move(b)));
274 STATIC_REQUIRE(based::trait::IsSame<int&&, ResT>);
275 REQUIRE(based::min(4, based::move(b)) == 3);
278 TEST_CASE("min(value, move) = left", "[algorithm/min]")
280 int a = 3;
281 int b = 4;
283 using ResT = decltype(based::min(a, based::move(b)));
285 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
286 REQUIRE(based::min(a, based::move(b)) == 3);
289 TEST_CASE("min(value, move) = right", "[algorithm/min]")
291 int a = 4;
292 int b = 3;
294 using ResT = decltype(based::min(a, based::move(b)));
296 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
297 REQUIRE(based::min(a, based::move(b)) == 3);
300 TEST_CASE("min(const value, move) = left", "[algorithm/min]")
302 const int a = 3;
303 int b = 4;
305 using ResT = decltype(based::min(a, based::move(b)));
307 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
308 REQUIRE(based::min(a, based::move(b)) == 3);
311 TEST_CASE("min(const value, move) = right", "[algorithm/min]")
313 const int a = 4;
314 int b = 3;
316 using ResT = decltype(based::min(a, based::move(b)));
318 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
319 REQUIRE(based::min(a, based::move(b)) == 3);
322 TEST_CASE("min(move, move) = left", "[algorithm/min]")
324 int a = 3;
325 int b = 4;
327 using ResT = decltype(based::min(based::move(a), based::move(b)));
329 STATIC_REQUIRE(based::trait::IsSame<int&&, ResT>);
330 REQUIRE(based::min(based::move(a), based::move(b)) == 3);
333 TEST_CASE("min(move, move) = right", "[algorithm/min]")
335 int a = 4;
336 int b = 3;
338 using ResT = decltype(based::min(based::move(a), based::move(b)));
340 STATIC_REQUIRE(based::trait::IsSame<int&&, ResT>);
341 REQUIRE(based::min(based::move(a), based::move(b)) == 3);
344 // NOLINTEND(*const-arg*,*const-correctness*,*after-move, *access-moved)
346 TEST_CASE("min-stability", "[algorithm/min]")
348 using TypeT = std::pair<int, int>;
350 static const auto cmp = [](const TypeT& x, const TypeT& y)
352 return x.first < y.first;
353 };
355 const TypeT a = {3, 4};
356 const TypeT b = {3, 5};
358 REQUIRE(based::min(a, b, cmp).second == 4);
359 REQUIRE(based::min(b, a, cmp).second == 5);