basedOpinionated utility library |
git clone git://git.dimitrijedobrota.com/based.git |
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING |
max_test.cpp (7991B)
0 #define CATCH_CONFIG_RUNTIME_STATIC_REQUIRE
2 #include "based/algorithms/max.hpp"
4 #include <catch2/catch_test_macros.hpp>
6 #include "based/concepts/is/same.hpp"
7 #include "based/utility/move.hpp"
9 // NOLINTBEGIN(*const-arg*,*const-correctness*,*after-move, *access-moved)
11 TEST_CASE("max(literal, literal) = right", "[algorithm/max]")
12 {
13 using res_t = decltype(based::max(3, 4));
15 STATIC_REQUIRE(based::SameAs<int&&, res_t>);
16 REQUIRE(based::max(3, 4) == 4);
17 }
19 TEST_CASE("max(literal, literal) = left", "[algorithm/max]")
20 {
21 using res_t = decltype(based::max(4, 3));
23 STATIC_REQUIRE(based::SameAs<int&&, res_t>);
24 REQUIRE(based::max(4, 3) == 4);
25 }
27 TEST_CASE("max(value, literal) = right", "[algorithm/max]")
28 {
29 int a = 3;
31 using res_t = decltype(based::max(a, 4));
33 STATIC_REQUIRE(based::SameAs<int, res_t>);
34 REQUIRE(based::max(a, 4) == 4);
35 }
37 TEST_CASE("max(value, literal) = left", "[algorithm/max]")
38 {
39 int a = 4;
41 using res_t = decltype(based::max(a, 3));
43 STATIC_REQUIRE(based::SameAs<int, res_t>);
44 REQUIRE(based::max(a, 3) == 4);
45 }
47 TEST_CASE("max(literal, value) = right", "[algorithm/max]")
48 {
49 int b = 4;
51 using res_t = decltype(based::max(3, b));
53 STATIC_REQUIRE(based::SameAs<int, res_t>);
54 REQUIRE(based::max(3, b) == 4);
55 }
57 TEST_CASE("max(literal, value) = left", "[algorithm/max]")
58 {
59 int b = 3;
61 using res_t = decltype(based::max(4, b));
63 STATIC_REQUIRE(based::SameAs<int, res_t>);
64 REQUIRE(based::max(4, b) == 4);
65 }
67 TEST_CASE("max(value, value) = right", "[algorithm/max]")
68 {
69 int a = 3;
70 int b = 4;
72 using res_t = decltype(based::max(a, b));
74 STATIC_REQUIRE(based::SameAs<int&, res_t>);
75 REQUIRE(based::max(a, b) == 4);
76 }
78 TEST_CASE("max(value, value) = left", "[algorithm/max]")
79 {
80 int a = 4;
81 int b = 3;
83 using res_t = decltype(based::max(a, b));
85 STATIC_REQUIRE(based::SameAs<int&, res_t>);
86 REQUIRE(based::max(a, b) == 4);
87 }
89 TEST_CASE("max(const value, literal) = right", "[algorithm/max]")
90 {
91 const int a = 3;
93 using res_t = decltype(based::max(a, 4));
95 STATIC_REQUIRE(based::SameAs<int, res_t>);
96 REQUIRE(based::max(a, 4) == 4);
97 }
99 TEST_CASE("max(const value, literal) = left", "[algorithm/max]")
100 {
101 const int a = 4;
103 using res_t = decltype(based::max(a, 3));
105 STATIC_REQUIRE(based::SameAs<int, res_t>);
106 REQUIRE(based::max(a, 3) == 4);
107 }
109 TEST_CASE("max(literal, const value) = right", "[algorithm/max]")
110 {
111 const int b = 4;
113 using res_t = decltype(based::max(3, b));
115 STATIC_REQUIRE(based::SameAs<int, res_t>);
116 REQUIRE(based::max(3, b) == 4);
117 }
119 TEST_CASE("max(literal, const value) = left", "[algorithm/max]")
120 {
121 const int b = 3;
123 using res_t = decltype(based::max(4, b));
125 STATIC_REQUIRE(based::SameAs<int, res_t>);
126 REQUIRE(based::max(4, b) == 4);
127 }
129 TEST_CASE("max(const value, const value) = right", "[algorithm/max]")
130 {
131 const int a = 3;
132 const int b = 4;
134 using res_t = decltype(based::max(a, b));
136 STATIC_REQUIRE(based::SameAs<const int&, res_t>);
137 REQUIRE(based::max(a, b) == 4);
138 }
140 TEST_CASE("max(const value, const value) = left", "[algorithm/max]")
141 {
142 const int a = 4;
143 const int b = 3;
145 using res_t = decltype(based::max(a, b));
147 STATIC_REQUIRE(based::SameAs<const int&, res_t>);
148 REQUIRE(based::max(a, b) == 4);
149 }
151 TEST_CASE("max(value, const value) = right", "[algorithm/max]")
152 {
153 int a = 3;
154 const int b = 4;
156 using res_t = decltype(based::max(a, b));
158 STATIC_REQUIRE(based::SameAs<const int&, res_t>);
159 REQUIRE(based::max(a, b) == 4);
160 }
162 TEST_CASE("max(value, const value) = left", "[algorithm/max]")
163 {
164 int a = 4;
165 const int b = 3;
167 using res_t = decltype(based::max(a, b));
169 STATIC_REQUIRE(based::SameAs<const int&, res_t>);
170 REQUIRE(based::max(a, b) == 4);
171 }
173 TEST_CASE("max(const value, value) = right", "[algorithm/max]")
174 {
175 const int a = 3;
176 int b = 4;
178 using res_t = decltype(based::max(a, b));
180 STATIC_REQUIRE(based::SameAs<const int&, res_t>);
181 REQUIRE(based::max(a, b) == 4);
182 }
184 TEST_CASE("max(const value, value) = left", "[algorithm/max]")
185 {
186 const int a = 4;
187 int b = 3;
189 using res_t = decltype(based::max(a, b));
191 STATIC_REQUIRE(based::SameAs<const int&, res_t>);
192 REQUIRE(based::max(a, b) == 4);
193 }
195 TEST_CASE("max(move, literal) = right", "[algorithm/max]")
196 {
197 int a = 3;
199 using res_t = decltype(based::max(based::move(a), 4));
201 STATIC_REQUIRE(based::SameAs<int&&, res_t>);
202 REQUIRE(based::max(based::move(a), 4) == 4);
203 }
205 TEST_CASE("max(move, literal) = left", "[algorithm/max]")
206 {
207 int a = 4;
209 using res_t = decltype(based::max(based::move(a), 3));
211 STATIC_REQUIRE(based::SameAs<int&&, res_t>);
212 REQUIRE(based::max(based::move(a), 3) == 4);
213 }
215 TEST_CASE("max(move, value) = right", "[algorithm/max]")
216 {
217 int a = 3;
218 int b = 4;
220 using res_t = decltype(based::max(based::move(a), b));
222 STATIC_REQUIRE(based::SameAs<int, res_t>);
223 REQUIRE(based::max(based::move(a), b) == 4);
224 }
226 TEST_CASE("max(move, value) = left", "[algorithm/max]")
227 {
228 int a = 4;
229 int b = 3;
231 using res_t = decltype(based::max(based::move(a), b));
233 STATIC_REQUIRE(based::SameAs<int, res_t>);
234 REQUIRE(based::max(based::move(a), b) == 4);
235 }
237 TEST_CASE("max(move, const value) = right", "[algorithm/max]")
238 {
239 int a = 3;
240 const int b = 4;
242 using res_t = decltype(based::max(based::move(a), b));
244 STATIC_REQUIRE(based::SameAs<int, res_t>);
245 REQUIRE(based::max(based::move(a), b) == 4);
246 }
248 TEST_CASE("max(move, const value) = left", "[algorithm/max]")
249 {
250 int a = 4;
251 const int b = 3;
253 using res_t = decltype(based::max(based::move(a), b));
255 STATIC_REQUIRE(based::SameAs<int, res_t>);
256 REQUIRE(based::max(based::move(a), b) == 4);
257 }
259 TEST_CASE("max(literal, move) = right", "[algorithm/max]")
260 {
261 int b = 4;
263 using res_t = decltype(based::max(3, based::move(b)));
265 STATIC_REQUIRE(based::SameAs<int&&, res_t>);
266 REQUIRE(based::max(3, based::move(b)) == 4);
267 }
269 TEST_CASE("max(literal, move) = left", "[algorithm/max]")
270 {
271 int b = 3;
273 using res_t = decltype(based::max(4, based::move(b)));
275 STATIC_REQUIRE(based::SameAs<int&&, res_t>);
276 REQUIRE(based::max(4, based::move(b)) == 4);
277 }
279 TEST_CASE("max(value, move) = right", "[algorithm/max]")
280 {
281 int a = 3;
282 int b = 4;
284 using res_t = decltype(based::max(a, based::move(b)));
286 STATIC_REQUIRE(based::SameAs<int, res_t>);
287 REQUIRE(based::max(a, based::move(b)) == 4);
288 }
290 TEST_CASE("max(value, move) = left", "[algorithm/max]")
291 {
292 int a = 4;
293 int b = 3;
295 using res_t = decltype(based::max(a, based::move(b)));
297 STATIC_REQUIRE(based::SameAs<int, res_t>);
298 REQUIRE(based::max(a, based::move(b)) == 4);
299 }
301 TEST_CASE("max(const value, move) = right", "[algorithm/max]")
302 {
303 const int a = 3;
304 int b = 4;
306 using res_t = decltype(based::max(a, based::move(b)));
308 STATIC_REQUIRE(based::SameAs<int, res_t>);
309 REQUIRE(based::max(a, based::move(b)) == 4);
310 }
312 TEST_CASE("max(const value, move) = left", "[algorithm/max]")
313 {
314 const int a = 4;
315 int b = 3;
317 using res_t = decltype(based::max(a, based::move(b)));
319 STATIC_REQUIRE(based::SameAs<int, res_t>);
320 REQUIRE(based::max(a, based::move(b)) == 4);
321 }
323 TEST_CASE("max(move, move) = right", "[algorithm/max]")
324 {
325 int a = 3;
326 int b = 4;
328 using res_t = decltype(based::max(based::move(a), based::move(b)));
330 STATIC_REQUIRE(based::SameAs<int&&, res_t>);
331 REQUIRE(based::max(based::move(a), based::move(b)) == 4);
332 }
334 TEST_CASE("max(move, move) = left", "[algorithm/max]")
335 {
336 int a = 4;
337 int b = 3;
339 using res_t = decltype(based::max(based::move(a), based::move(b)));
341 STATIC_REQUIRE(based::SameAs<int&&, res_t>);
342 REQUIRE(based::max(based::move(a), based::move(b)) == 4);
343 }
345 // NOLINTEND(*const-arg*,*const-correctness*,*after-move, *access-moved)
347 TEST_CASE("max-stability", "[algorithm/max]")
348 {
349 using type_t = std::pair<int, int>;
351 static const auto cmp = [](const type_t& x, const type_t& y)
352 {
353 return x.first < y.first;
354 };
356 const type_t a = {3, 4};
357 const type_t b = {3, 5};
359 REQUIRE(based::max(a, b, cmp).second == 5);
360 REQUIRE(based::max(b, a, cmp).second == 4);
361 }