based

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

max_test.cpp (8144B)


0 #define CATCH_CONFIG_RUNTIME_STATIC_REQUIRE
2 #include "based/algorithm/max.hpp"
4 #include <catch2/catch_test_macros.hpp>
6 #include "based/concept/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 ResT = decltype(based::max(3, 4));
15 STATIC_REQUIRE(based::trait::IsSame<int&&, ResT>);
16 REQUIRE(based::max(3, 4) == 4);
17 }
19 TEST_CASE("max(literal, literal) = left", "[algorithm/max]")
20 {
21 using ResT = decltype(based::max(4, 3));
23 STATIC_REQUIRE(based::trait::IsSame<int&&, ResT>);
24 REQUIRE(based::max(4, 3) == 4);
25 }
27 TEST_CASE("max(value, literal) = right", "[algorithm/max]")
28 {
29 int a = 3;
31 using ResT = decltype(based::max(a, 4));
33 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
34 REQUIRE(based::max(a, 4) == 4);
35 }
37 TEST_CASE("max(value, literal) = left", "[algorithm/max]")
38 {
39 int a = 4;
41 using ResT = decltype(based::max(a, 3));
43 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
44 REQUIRE(based::max(a, 3) == 4);
45 }
47 TEST_CASE("max(literal, value) = right", "[algorithm/max]")
48 {
49 int b = 4;
51 using ResT = decltype(based::max(3, b));
53 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
54 REQUIRE(based::max(3, b) == 4);
55 }
57 TEST_CASE("max(literal, value) = left", "[algorithm/max]")
58 {
59 int b = 3;
61 using ResT = decltype(based::max(4, b));
63 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
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 ResT = decltype(based::max(a, b));
74 STATIC_REQUIRE(based::trait::IsSame<int&, ResT>);
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 ResT = decltype(based::max(a, b));
85 STATIC_REQUIRE(based::trait::IsSame<int&, ResT>);
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 ResT = decltype(based::max(a, 4));
95 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
96 REQUIRE(based::max(a, 4) == 4);
97 }
99 TEST_CASE("max(const value, literal) = left", "[algorithm/max]")
101 const int a = 4;
103 using ResT = decltype(based::max(a, 3));
105 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
106 REQUIRE(based::max(a, 3) == 4);
109 TEST_CASE("max(literal, const value) = right", "[algorithm/max]")
111 const int b = 4;
113 using ResT = decltype(based::max(3, b));
115 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
116 REQUIRE(based::max(3, b) == 4);
119 TEST_CASE("max(literal, const value) = left", "[algorithm/max]")
121 const int b = 3;
123 using ResT = decltype(based::max(4, b));
125 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
126 REQUIRE(based::max(4, b) == 4);
129 TEST_CASE("max(const value, const value) = right", "[algorithm/max]")
131 const int a = 3;
132 const int b = 4;
134 using ResT = decltype(based::max(a, b));
136 STATIC_REQUIRE(based::trait::IsSame<const int&, ResT>);
137 REQUIRE(based::max(a, b) == 4);
140 TEST_CASE("max(const value, const value) = left", "[algorithm/max]")
142 const int a = 4;
143 const int b = 3;
145 using ResT = decltype(based::max(a, b));
147 STATIC_REQUIRE(based::trait::IsSame<const int&, ResT>);
148 REQUIRE(based::max(a, b) == 4);
151 TEST_CASE("max(value, const value) = right", "[algorithm/max]")
153 int a = 3;
154 const int b = 4;
156 using ResT = decltype(based::max(a, b));
158 STATIC_REQUIRE(based::trait::IsSame<const int&, ResT>);
159 REQUIRE(based::max(a, b) == 4);
162 TEST_CASE("max(value, const value) = left", "[algorithm/max]")
164 int a = 4;
165 const int b = 3;
167 using ResT = decltype(based::max(a, b));
169 STATIC_REQUIRE(based::trait::IsSame<const int&, ResT>);
170 REQUIRE(based::max(a, b) == 4);
173 TEST_CASE("max(const value, value) = right", "[algorithm/max]")
175 const int a = 3;
176 int b = 4;
178 using ResT = decltype(based::max(a, b));
180 STATIC_REQUIRE(based::trait::IsSame<const int&, ResT>);
181 REQUIRE(based::max(a, b) == 4);
184 TEST_CASE("max(const value, value) = left", "[algorithm/max]")
186 const int a = 4;
187 int b = 3;
189 using ResT = decltype(based::max(a, b));
191 STATIC_REQUIRE(based::trait::IsSame<const int&, ResT>);
192 REQUIRE(based::max(a, b) == 4);
195 TEST_CASE("max(move, literal) = right", "[algorithm/max]")
197 int a = 3;
199 using ResT = decltype(based::max(based::move(a), 4));
201 STATIC_REQUIRE(based::trait::IsSame<int&&, ResT>);
202 REQUIRE(based::max(based::move(a), 4) == 4);
205 TEST_CASE("max(move, literal) = left", "[algorithm/max]")
207 int a = 4;
209 using ResT = decltype(based::max(based::move(a), 3));
211 STATIC_REQUIRE(based::trait::IsSame<int&&, ResT>);
212 REQUIRE(based::max(based::move(a), 3) == 4);
215 TEST_CASE("max(move, value) = right", "[algorithm/max]")
217 int a = 3;
218 int b = 4;
220 using ResT = decltype(based::max(based::move(a), b));
222 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
223 REQUIRE(based::max(based::move(a), b) == 4);
226 TEST_CASE("max(move, value) = left", "[algorithm/max]")
228 int a = 4;
229 int b = 3;
231 using ResT = decltype(based::max(based::move(a), b));
233 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
234 REQUIRE(based::max(based::move(a), b) == 4);
237 TEST_CASE("max(move, const value) = right", "[algorithm/max]")
239 int a = 3;
240 const int b = 4;
242 using ResT = decltype(based::max(based::move(a), b));
244 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
245 REQUIRE(based::max(based::move(a), b) == 4);
248 TEST_CASE("max(move, const value) = left", "[algorithm/max]")
250 int a = 4;
251 const int b = 3;
253 using ResT = decltype(based::max(based::move(a), b));
255 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
256 REQUIRE(based::max(based::move(a), b) == 4);
259 TEST_CASE("max(literal, move) = right", "[algorithm/max]")
261 int b = 4;
263 using ResT = decltype(based::max(3, based::move(b)));
265 STATIC_REQUIRE(based::trait::IsSame<int&&, ResT>);
266 REQUIRE(based::max(3, based::move(b)) == 4);
269 TEST_CASE("max(literal, move) = left", "[algorithm/max]")
271 int b = 3;
273 using ResT = decltype(based::max(4, based::move(b)));
275 STATIC_REQUIRE(based::trait::IsSame<int&&, ResT>);
276 REQUIRE(based::max(4, based::move(b)) == 4);
279 TEST_CASE("max(value, move) = right", "[algorithm/max]")
281 int a = 3;
282 int b = 4;
284 using ResT = decltype(based::max(a, based::move(b)));
286 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
287 REQUIRE(based::max(a, based::move(b)) == 4);
290 TEST_CASE("max(value, move) = left", "[algorithm/max]")
292 int a = 4;
293 int b = 3;
295 using ResT = decltype(based::max(a, based::move(b)));
297 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
298 REQUIRE(based::max(a, based::move(b)) == 4);
301 TEST_CASE("max(const value, move) = right", "[algorithm/max]")
303 const int a = 3;
304 int b = 4;
306 using ResT = decltype(based::max(a, based::move(b)));
308 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
309 REQUIRE(based::max(a, based::move(b)) == 4);
312 TEST_CASE("max(const value, move) = left", "[algorithm/max]")
314 const int a = 4;
315 int b = 3;
317 using ResT = decltype(based::max(a, based::move(b)));
319 STATIC_REQUIRE(based::trait::IsSame<int, ResT>);
320 REQUIRE(based::max(a, based::move(b)) == 4);
323 TEST_CASE("max(move, move) = right", "[algorithm/max]")
325 int a = 3;
326 int b = 4;
328 using ResT = decltype(based::max(based::move(a), based::move(b)));
330 STATIC_REQUIRE(based::trait::IsSame<int&&, ResT>);
331 REQUIRE(based::max(based::move(a), based::move(b)) == 4);
334 TEST_CASE("max(move, move) = left", "[algorithm/max]")
336 int a = 4;
337 int b = 3;
339 using ResT = decltype(based::max(based::move(a), based::move(b)));
341 STATIC_REQUIRE(based::trait::IsSame<int&&, ResT>);
342 REQUIRE(based::max(based::move(a), based::move(b)) == 4);
345 // NOLINTEND(*const-arg*,*const-correctness*,*after-move, *access-moved)
347 TEST_CASE("max-stability", "[algorithm/max]")
349 using TypeT = std::pair<int, int>;
351 static const auto cmp = [](const TypeT& x, const TypeT& y)
353 return x.first < y.first;
354 };
356 const TypeT a = {3, 4};
357 const TypeT b = {3, 5};
359 REQUIRE(based::max(a, b, cmp).second == 5);
360 REQUIRE(based::max(b, a, cmp).second == 4);