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 (7581B)
0 #include <catch2/catch_test_macros.hpp> 1 2 #include "based/type_traits.hpp" 3 #include "based/algorithm.hpp" 4 5 // NOLINTBEGIN(*const-arg*,*const-correctness*,*after-move, *access-moved) 6 7 TEST_CASE("max(literal, literal) = right", "[algorithm/max]") 8 { 9 using res_t = decltype(based::max(3, 4)); 10 REQUIRE(based::SameAs<int&&, res_t>); 11 REQUIRE(based::max(3, 4) == 4); 12 } 13 14 TEST_CASE("max(literal, literal) = left", "[algorithm/max]") 15 { 16 using res_t = decltype(based::max(4, 3)); 17 REQUIRE(based::SameAs<int&&, res_t>); 18 REQUIRE(based::max(4, 3) == 4); 19 } 20 21 TEST_CASE("max(value, literal) = right", "[algorithm/max]") 22 { 23 int a = 3; 24 25 using res_t = decltype(based::max(a, 4)); 26 REQUIRE(based::SameAs<int, res_t>); 27 REQUIRE(based::max(a, 4) == 4); 28 } 29 30 TEST_CASE("max(value, literal) = left", "[algorithm/max]") 31 { 32 int a = 4; 33 34 using res_t = decltype(based::max(a, 3)); 35 REQUIRE(based::SameAs<int, res_t>); 36 REQUIRE(based::max(a, 3) == 4); 37 } 38 39 TEST_CASE("max(literal, value) = right", "[algorithm/max]") 40 { 41 int b = 4; 42 43 using res_t = decltype(based::max(3, b)); 44 REQUIRE(based::SameAs<int, res_t>); 45 REQUIRE(based::max(3, b) == 4); 46 } 47 48 TEST_CASE("max(literal, value) = left", "[algorithm/max]") 49 { 50 int b = 3; 51 52 using res_t = decltype(based::max(4, b)); 53 REQUIRE(based::SameAs<int, res_t>); 54 REQUIRE(based::max(4, b) == 4); 55 } 56 57 TEST_CASE("max(value, value) = right", "[algorithm/max]") 58 { 59 int a = 3; 60 int b = 4; 61 62 using res_t = decltype(based::max(a, b)); 63 REQUIRE(based::SameAs<int&, res_t>); 64 REQUIRE(based::max(a, b) == 4); 65 } 66 67 TEST_CASE("max(value, value) = left", "[algorithm/max]") 68 { 69 int a = 4; 70 int b = 3; 71 72 using res_t = decltype(based::max(a, b)); 73 REQUIRE(based::SameAs<int&, res_t>); 74 REQUIRE(based::max(a, b) == 4); 75 } 76 77 TEST_CASE("max(const value, literal) = right", "[algorithm/max]") 78 { 79 const int a = 3; 80 81 using res_t = decltype(based::max(a, 4)); 82 REQUIRE(based::SameAs<int, res_t>); 83 REQUIRE(based::max(a, 4) == 4); 84 } 85 86 TEST_CASE("max(const value, literal) = left", "[algorithm/max]") 87 { 88 const int a = 4; 89 90 using res_t = decltype(based::max(a, 3)); 91 REQUIRE(based::SameAs<int, res_t>); 92 REQUIRE(based::max(a, 3) == 4); 93 } 94 95 TEST_CASE("max(literal, const value) = right", "[algorithm/max]") 96 { 97 const int b = 4; 98 99 using res_t = decltype(based::max(3, b)); 100 REQUIRE(based::SameAs<int, res_t>); 101 REQUIRE(based::max(3, b) == 4); 102 } 103 104 TEST_CASE("max(literal, const value) = left", "[algorithm/max]") 105 { 106 const int b = 3; 107 108 using res_t = decltype(based::max(4, b)); 109 REQUIRE(based::SameAs<int, res_t>); 110 REQUIRE(based::max(4, b) == 4); 111 } 112 113 TEST_CASE("max(const value, const value) = right", "[algorithm/max]") 114 { 115 const int a = 3; 116 const int b = 4; 117 118 using res_t = decltype(based::max(a, b)); 119 REQUIRE(based::SameAs<const int&, res_t>); 120 REQUIRE(based::max(a, b) == 4); 121 } 122 123 TEST_CASE("max(const value, const value) = left", "[algorithm/max]") 124 { 125 const int a = 4; 126 const int b = 3; 127 128 using res_t = decltype(based::max(a, b)); 129 REQUIRE(based::SameAs<const int&, res_t>); 130 REQUIRE(based::max(a, b) == 4); 131 } 132 133 TEST_CASE("max(value, const value) = right", "[algorithm/max]") 134 { 135 int a = 3; 136 const int b = 4; 137 138 using res_t = decltype(based::max(a, b)); 139 REQUIRE(based::SameAs<const int&, res_t>); 140 REQUIRE(based::max(a, b) == 4); 141 } 142 143 TEST_CASE("max(value, const value) = left", "[algorithm/max]") 144 { 145 int a = 4; 146 const int b = 3; 147 148 using res_t = decltype(based::max(a, b)); 149 REQUIRE(based::SameAs<const int&, res_t>); 150 REQUIRE(based::max(a, b) == 4); 151 } 152 153 TEST_CASE("max(const value, value) = right", "[algorithm/max]") 154 { 155 const int a = 3; 156 int b = 4; 157 158 using res_t = decltype(based::max(a, b)); 159 REQUIRE(based::SameAs<const int&, res_t>); 160 REQUIRE(based::max(a, b) == 4); 161 } 162 163 TEST_CASE("max(const value, value) = left", "[algorithm/max]") 164 { 165 const int a = 4; 166 int b = 3; 167 168 using res_t = decltype(based::max(a, b)); 169 REQUIRE(based::SameAs<const int&, res_t>); 170 REQUIRE(based::max(a, b) == 4); 171 } 172 173 TEST_CASE("max(move, literal) = right", "[algorithm/max]") 174 { 175 int a = 3; 176 177 using res_t = decltype(based::max(std::move(a), 4)); 178 REQUIRE(based::SameAs<int&&, res_t>); 179 REQUIRE(based::max(std::move(a), 4) == 4); 180 } 181 182 TEST_CASE("max(move, literal) = left", "[algorithm/max]") 183 { 184 int a = 4; 185 186 using res_t = decltype(based::max(std::move(a), 3)); 187 REQUIRE(based::SameAs<int&&, res_t>); 188 REQUIRE(based::max(std::move(a), 3) == 4); 189 } 190 191 TEST_CASE("max(move, value) = right", "[algorithm/max]") 192 { 193 int a = 3; 194 int b = 4; 195 196 using res_t = decltype(based::max(std::move(a), b)); 197 REQUIRE(based::SameAs<int, res_t>); 198 REQUIRE(based::max(std::move(a), b) == 4); 199 } 200 201 TEST_CASE("max(move, value) = left", "[algorithm/max]") 202 { 203 int a = 4; 204 int b = 3; 205 206 using res_t = decltype(based::max(std::move(a), b)); 207 REQUIRE(based::SameAs<int, res_t>); 208 REQUIRE(based::max(std::move(a), b) == 4); 209 } 210 211 TEST_CASE("max(move, const value) = right", "[algorithm/max]") 212 { 213 int a = 3; 214 const int b = 4; 215 216 using res_t = decltype(based::max(std::move(a), b)); 217 REQUIRE(based::SameAs<int, res_t>); 218 REQUIRE(based::max(std::move(a), b) == 4); 219 } 220 221 TEST_CASE("max(move, const value) = left", "[algorithm/max]") 222 { 223 int a = 4; 224 const int b = 3; 225 226 using res_t = decltype(based::max(std::move(a), b)); 227 REQUIRE(based::SameAs<int, res_t>); 228 REQUIRE(based::max(std::move(a), b) == 4); 229 } 230 231 TEST_CASE("max(literal, move) = right", "[algorithm/max]") 232 { 233 int b = 4; 234 235 using res_t = decltype(based::max(3, std::move(b))); 236 REQUIRE(based::SameAs<int&&, res_t>); 237 REQUIRE(based::max(3, std::move(b)) == 4); 238 } 239 240 TEST_CASE("max(literal, move) = left", "[algorithm/max]") 241 { 242 int b = 3; 243 244 using res_t = decltype(based::max(4, std::move(b))); 245 REQUIRE(based::SameAs<int&&, res_t>); 246 REQUIRE(based::max(4, std::move(b)) == 4); 247 } 248 249 TEST_CASE("max(value, move) = right", "[algorithm/max]") 250 { 251 int a = 3; 252 int b = 4; 253 254 using res_t = decltype(based::max(a, std::move(b))); 255 REQUIRE(based::SameAs<int, res_t>); 256 REQUIRE(based::max(a, std::move(b)) == 4); 257 } 258 259 TEST_CASE("max(value, move) = left", "[algorithm/max]") 260 { 261 int a = 4; 262 int b = 3; 263 264 using res_t = decltype(based::max(a, std::move(b))); 265 REQUIRE(based::SameAs<int, res_t>); 266 REQUIRE(based::max(a, std::move(b)) == 4); 267 } 268 269 TEST_CASE("max(const value, move) = right", "[algorithm/max]") 270 { 271 const int a = 3; 272 int b = 4; 273 274 using res_t = decltype(based::max(a, std::move(b))); 275 REQUIRE(based::SameAs<int, res_t>); 276 REQUIRE(based::max(a, std::move(b)) == 4); 277 } 278 279 TEST_CASE("max(const value, move) = left", "[algorithm/max]") 280 { 281 const int a = 4; 282 int b = 3; 283 284 using res_t = decltype(based::max(a, std::move(b))); 285 REQUIRE(based::SameAs<int, res_t>); 286 REQUIRE(based::max(a, std::move(b)) == 4); 287 } 288 289 TEST_CASE("max(move, move) = right", "[algorithm/max]") 290 { 291 int a = 3; 292 int b = 4; 293 294 using res_t = decltype(based::max(std::move(a), std::move(b))); 295 REQUIRE(based::SameAs<int&&, res_t>); 296 REQUIRE(based::max(std::move(a), std::move(b)) == 4); 297 } 298 299 TEST_CASE("max(move, move) = left", "[algorithm/max]") 300 { 301 int a = 4; 302 int b = 3; 303 304 using res_t = decltype(based::max(std::move(a), std::move(b))); 305 REQUIRE(based::SameAs<int&&, res_t>); 306 REQUIRE(based::max(std::move(a), std::move(b)) == 4); 307 } 308 309 // NOLINTEND(*const-arg*,*const-correctness*,*after-move, *access-moved) 310 311 TEST_CASE("max-stability", "[algorithm/max]") 312 { 313 using type_t = std::pair<int, int>; 314 315 static const auto cmp = [](const type_t& x, const type_t& y) 316 { 317 return x.first < y.first; 318 }; 319 320 const type_t a = {3, 4}; 321 const type_t b = {3, 5}; 322 323 REQUIRE(based::max(a, b, cmp).second == 5); 324 REQUIRE(based::max(b, a, cmp).second == 4); 325 }