xtd 0.2.0
collection_assert.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "assert.hpp"
6
8namespace xtd {
10 namespace tunit {
24 public:
26 collection_assert() = delete;
28
30
43 template<class expected_t, class collection_t>
44 static void all_items_are_instances_of(const collection_t& collection, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {all_items_are_instances_of<expected_t>(collection, xtd::string::empty_string, stack_frame);}
56 template<class expected_t, class collection_t>
57 static void all_items_are_instances_of(const collection_t& collection, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
58 for (auto item : collection)
59 if (dynamic_cast<expected_t>(item) == nullptr) {
60 fail("all items instance of <" + typeof_<expected_t>().full_name() + ">", join_items(collection), message, stack_frame);
61 return;
62 }
63 succeed(message, stack_frame);
64 }
65
67 template<class expected_t, class item_t>
68 static void all_items_are_instances_of(const std::initializer_list<item_t>& collection, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {all_items_are_instances_of<expected_t>(collection, xtd::string::empty_string, stack_frame);}
69 template<class expected_t, class item_t>
70 static void all_items_are_instances_of(const std::initializer_list<item_t>& collection, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
71 for (auto item : collection)
72 if (dynamic_cast<expected_t>(item) == nullptr) {
73 fail("all items instance of <" + typeof_<expected_t>().full_name() + ">", join_items(collection), message, stack_frame);
74 return;
75 }
76 succeed(message, stack_frame);
77 }
79
93 template<class collection_t>
94 static void all_items_are_not_null(const collection_t& collection, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {all_items_are_not_null(collection, xtd::string::empty_string, stack_frame);}
108 template<class collection_t>
109 static void all_items_are_not_null(const collection_t& collection, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
110 for (auto item : collection)
111 if (item == nullptr) {
112 fail("all items are not null", join_items(collection), message, stack_frame);
113 return;
114 }
115 succeed(message, stack_frame);
116 }
117
119 template<class item_t>
120 static void all_items_are_not_null(const std::initializer_list<item_t>& collection, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {all_items_are_not_null(collection, xtd::string::empty_string, stack_frame);}
121 template<class item_t>
122 static void all_items_are_not_null(const std::initializer_list<item_t>& collection, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
123 for (auto item : collection)
124 if (item == nullptr) {
125 fail("all items are not null", join_items(collection), message, stack_frame);
126 return;
127 }
128 succeed(message, stack_frame);
129 }
131
144 template<class collection_t>
145 static void all_items_are_unique(const collection_t& collection, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {all_items_are_unique(collection, xtd::string::empty_string, stack_frame);}
158 template<class collection_t>
159 static void all_items_are_unique(const collection_t& collection, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
160 auto value = *collection.cbegin();
161 std::map<decltype(value), int32> counts;
162 for (auto item : collection) {
163 auto result = counts.emplace(item, 1);
164 if (result.second == false)
165 fail("all items are unique", join_items(collection), message, stack_frame);
166 }
167 succeed(message, stack_frame);
168 }
169
171 template<class item_t>
172 static void all_items_are_unique(const std::initializer_list<item_t>& collection, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {all_items_are_unique(collection, xtd::string::empty_string, stack_frame);}
173 template<class item_t>
174 static void all_items_are_unique(const std::initializer_list<item_t>& collection, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
175 std::map<item_t, int32> counts;
176 for (auto item : collection) {
177 auto result = counts.emplace(item, 1);
178 if (result.second == false)
179 fail("all items are unique", join_items(collection), message, stack_frame);
180 }
181 succeed(message, stack_frame);
182 }
184
196 template<class expected_t, class actual_t>
197 static void are_equal(const expected_t& expected, const actual_t& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_equal(expected, actual, xtd::string::empty_string, stack_frame);}
209 template<class expected_t, class actual_t>
210 static void are_equal(const expected_t& expected, const actual_t& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
211 if (equals(actual.begin(), actual.end(), expected.begin(), expected.end())) succeed(message, stack_frame);
212 else fail(join_items(expected), join_items(actual), message, stack_frame);
213 }
214
216 template<class item_t>
217 static void are_equal(const std::initializer_list<item_t>& expected, const std::initializer_list<item_t>& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_equal(expected, actual, xtd::string::empty_string, stack_frame);}
218 template<class item_t>
219 static void are_equal(const std::initializer_list<item_t>& expected, const std::initializer_list<item_t>& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
220 if (equals(actual.begin(), actual.end(), expected.begin(), expected.end())) succeed(message, stack_frame);
221 else fail(join_items(expected), join_items(actual), message, stack_frame);
222 }
223 template<class collection_t, class item_t>
224 static void are_equal(const collection_t& expected, const std::initializer_list<item_t>& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_equal(expected, actual, xtd::string::empty_string, stack_frame);}
225 template<class collection_t, class item_t>
226 static void are_equal(const collection_t& expected, const std::initializer_list<item_t>& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
227 if (equals(actual.begin(), actual.end(), expected.begin(), expected.end())) succeed(message, stack_frame);
228 else fail(join_items(expected), join_items(actual), message, stack_frame);
229 }
230 template<class item_t, class collection_t>
231 static void are_equal(const std::initializer_list<item_t>& expected, const collection_t& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_equal(expected, actual, xtd::string::empty_string, stack_frame);}
232 template<class item_t, class collection_t>
233 static void are_equal(const std::initializer_list<item_t>& expected, const collection_t& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
234 if (equals(actual.begin(), actual.end(), expected.begin(), expected.end())) succeed(message, stack_frame);
235 else fail(join_items(expected), join_items(actual), message, stack_frame);
236 }
238
250 template<class expected_t, class actual_t>
251 static void are_equivalent(const expected_t& expected, const actual_t& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_equivalent(expected, actual, xtd::string::empty_string, stack_frame);}
263 template<class expected_t, class actual_t>
264 static void are_equivalent(const expected_t& expected, const actual_t& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
265 if (equivalents(expected.begin(), expected.end(), actual.begin(), actual.end())) succeed(message, stack_frame);
266 else fail("equivalent " + join_items(expected), join_items(actual), message, stack_frame);
267 }
268
270 template<class expected_t, class actual_t>
271 static void are_equivalent(const std::initializer_list<expected_t>& expected, const std::initializer_list<actual_t>& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_equivalent(expected, actual, xtd::string::empty_string, stack_frame);}
272 template<class expected_t, class actual_t>
273 static void are_equivalent(const std::initializer_list<expected_t>& expected, const std::initializer_list<actual_t>& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
274 if (equivalents(expected.begin(), expected.end(), actual.begin(), actual.end())) succeed(message, stack_frame);
275 else fail("equivalent " + join_items(expected), join_items(actual), message, stack_frame);
276 }
277 template<class collection_t, class item_t>
278 static void are_equivalent(const collection_t& expected, const std::initializer_list<item_t>& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_equivalent(expected, actual, xtd::string::empty_string, stack_frame);}
279 template<class collection_t, class item_t>
280 static void are_equivalent(const collection_t& expected, const std::initializer_list<item_t>& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
281 if (equivalents(expected.begin(), expected.end(), actual.begin(), actual.end())) succeed(message, stack_frame);
282 else fail("equivalent " + join_items(expected), join_items(actual), message, stack_frame);
283 }
284 template<class item_t, class collection_t>
285 static void are_equivalent(const std::initializer_list<item_t>& expected, const collection_t& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_equivalent(expected, actual, xtd::string::empty_string, stack_frame);}
286 template<class item_t, class collection_t>
287 static void are_equivalent(const std::initializer_list<item_t>& expected, const collection_t& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
288 if (equivalents(expected.begin(), expected.end(), actual.begin(), actual.end())) succeed(message, stack_frame);
289 else fail("equivalent " + join_items(expected), join_items(actual), message, stack_frame);
290 }
292
304 template<class expected_t, class actual_t>
305 static void are_not_equal(const expected_t& expected, const actual_t& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_not_equal(expected, actual, xtd::string::empty_string, stack_frame);}
317 template<class expected_t, class actual_t>
318 static void are_not_equal(const expected_t& expected, const actual_t& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
319 if (!equals(actual.begin(), actual.end(), expected.begin(), expected.end())) succeed(message, stack_frame);
320 else fail("not " + join_items(expected), join_items(actual), message, stack_frame);
321 }
322
324 template<class item_t>
325 static void are_not_equal(const std::initializer_list<item_t>& expected, const std::initializer_list<item_t>& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_not_equal(expected, actual, xtd::string::empty_string, stack_frame);}
326 template<class item_t>
327 static void are_not_equal(const std::initializer_list<item_t>& expected, const std::initializer_list<item_t>& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
328 if (!equals(actual.begin(), actual.end(), expected.begin(), expected.end())) succeed(message, stack_frame);
329 else fail("not " + join_items(expected), join_items(actual), message, stack_frame);
330 }
331 template<class collection_t, class item_t>
332 static void are_not_equal(const collection_t& expected, const std::initializer_list<item_t>& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_not_equal(expected, actual, xtd::string::empty_string, stack_frame);}
333 template<class collection_t, class item_t>
334 static void are_not_equal(const collection_t& expected, const std::initializer_list<item_t>& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
335 if (!equals(actual.begin(), actual.end(), expected.begin(), expected.end())) succeed(message, stack_frame);
336 else fail("not " + join_items(expected), join_items(actual), message, stack_frame);
337 }
338 template<class item_t, class collection_t>
339 static void are_not_equal(const std::initializer_list<item_t>& expected, const collection_t& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_not_equal(expected, actual, xtd::string::empty_string, stack_frame);}
340 template<class item_t, class collection_t>
341 static void are_not_equal(const std::initializer_list<item_t>& expected, const collection_t& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
342 if (!equals(actual.begin(), actual.end(), expected.begin(), expected.end())) succeed(message, stack_frame);
343 else fail("not " + join_items(expected), join_items(actual), message, stack_frame);
344 }
346
358 template<class expected_t, class actual_t>
359 static void are_not_equivalent(const expected_t& expected, const actual_t& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_not_equivalent(expected, actual, xtd::string::empty_string, stack_frame);}
371 template<class expected_t, class actual_t>
372 static void are_not_equivalent(const expected_t& expected, const actual_t& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
373 if (!equivalents(expected.begin(), expected.end(), actual.begin(), actual.end())) succeed(message, stack_frame);
374 else fail("not equivalent " + join_items(expected), join_items(actual), message, stack_frame);
375 }
376
378 template<class expected_t, class actual_t>
379 static void are_not_equivalent(const std::initializer_list<expected_t>& expected, const std::initializer_list<actual_t>& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_not_equivalent(expected, actual, xtd::string::empty_string, stack_frame);}
380 template<class expected_t, class actual_t>
381 static void are_not_equivalent(const std::initializer_list<expected_t>& expected, const std::initializer_list<actual_t>& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
382 if (!equivalents(expected.begin(), expected.end(), actual.begin(), actual.end())) succeed(message, stack_frame);
383 else fail("not equivalent " + join_items(expected), join_items(actual), message, stack_frame);
384 }
385 template<class collection_t, class item_t>
386 static void are_not_equivalent(const collection_t& expected, const std::initializer_list<item_t>& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_not_equivalent(expected, actual, xtd::string::empty_string, stack_frame);}
387 template<class collection_t, class item_t>
388 static void are_not_equivalent(const collection_t& expected, const std::initializer_list<item_t>& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
389 if (!equivalents(expected.begin(), expected.end(), actual.begin(), actual.end())) succeed(message, stack_frame);
390 else fail("not equivalent " + join_items(expected), join_items(actual), message, stack_frame);
391 }
392 template<class item_t, class collection_t>
393 static void are_not_equivalent(const std::initializer_list<item_t>& expected, const collection_t& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_not_equivalent(expected, actual, xtd::string::empty_string, stack_frame);}
394 template<class item_t, class collection_t>
395 static void are_not_equivalent(const std::initializer_list<item_t>& expected, const collection_t& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
396 if (!equivalents(expected.begin(), expected.end(), actual.begin(), actual.end())) succeed(message, stack_frame);
397 else fail("not equivalent " + join_items(expected), join_items(actual), message, stack_frame);
398 }
400
412 template<class expected_t, class actual_t>
413 static void contains(const expected_t& expected, const actual_t& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {contains(expected, actual, xtd::string::empty_string, stack_frame);}
425 template<class expected_t, class actual_t>
426 static void contains(const expected_t& expected, const actual_t& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
427 for (const auto& item : expected) {
428 if (std::find_if(std::begin(actual), std::end(actual), [&](const auto& value) {return value == item;}) == std::end(actual)) {
429 fail("contains " + join_items(expected), join_items(actual), message, stack_frame);
430 return;
431 }
432 }
433 succeed(message, stack_frame);
434 }
435
437 template<class item_t>
438 static void contains(const std::initializer_list<item_t>& expected, const std::initializer_list<item_t>& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {contains(expected, actual, xtd::string::empty_string, stack_frame);}
439 template<class item_t>
440 static void contains(const std::initializer_list<item_t>& expected, const std::initializer_list<item_t>& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
441 for (const auto& item : expected) {
442 if (std::find_if(std::begin(actual), std::end(actual), [&](const item_t& value) {return value == item;}) == std::end(actual)) {
443 fail("contains " + join_items(expected), join_items(actual), message, stack_frame);
444 return;
445 }
446 }
447 succeed(message, stack_frame);
448 }
449 template<class collection_t, class item_t>
450 static void contains(const collection_t& expected, const std::initializer_list<item_t>& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {contains(expected, actual, xtd::string::empty_string, stack_frame);}
451 template<class collection_t, class item_t>
452 static void contains(const collection_t& expected, const std::initializer_list<item_t>& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
453 for (const auto& item : expected) {
454 if (std::find_if(std::begin(actual), std::end(actual), [&](const item_t& value) {return value == item;}) == std::end(actual)) {
455 fail("contains " + join_items(expected), join_items(actual), message, stack_frame);
456 return;
457 }
458 }
459 succeed(message, stack_frame);
460 }
461 template<class item_t, class collection_t>
462 static void contains(const std::initializer_list<item_t>& expected, const collection_t& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {contains(expected, actual, xtd::string::empty_string, stack_frame);}
463 template<class item_t, class collection_t>
464 static void contains(const std::initializer_list<item_t>& expected, const collection_t& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
465 for (const auto& item : expected) {
466 if (std::find_if(std::begin(actual), std::end(actual), [&](const item_t& value) {return value == item;}) == std::end(actual)) {
467 fail("contains " + join_items(expected), join_items(actual), message, stack_frame);
468 return;
469 }
470 }
471 succeed(message, stack_frame);
472 }
474
486 template<class expected_t, class actual_t>
487 static void does_not_contain(const expected_t& expected, const actual_t& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {does_not_contain(expected, actual, xtd::string::empty_string, stack_frame);}
499 template<class expected_t, class actual_t>
500 static void does_not_contain(const expected_t& expected, const actual_t& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
501 for (const auto& item : expected) {
502 if (std::find_if(std::begin(actual), std::end(actual), [&](const auto& value) {return value == item;}) == std::end(actual)) {
503 succeed(message, stack_frame);
504 return;
505 }
506 }
507 fail("not contains " + join_items(expected), join_items(actual), message, stack_frame);
508 }
509
511 template<class item_t>
512 static void does_not_contain(const std::initializer_list<item_t>& expected, const std::initializer_list<item_t>& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {does_not_contain(expected, actual, xtd::string::empty_string, stack_frame);}
513 template<class item_t>
514 static void does_not_contain(const std::initializer_list<item_t>& expected, const std::initializer_list<item_t>& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
515 for (const auto& item : expected) {
516 if (std::find_if(std::begin(actual), std::end(actual), [&](const item_t& value) {return value == item;}) == std::end(actual)) {
517 succeed(message, stack_frame);
518 return;
519 }
520 }
521 fail("not contains " + join_items(expected), join_items(actual), message, stack_frame);
522 }
523 template<class collection_t, class item_t>
524 static void does_not_contain(const collection_t& expected, const std::initializer_list<item_t>& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {does_not_contain(expected, actual, xtd::string::empty_string, stack_frame);}
525 template<class collection_t, class item_t>
526 static void does_not_contain(const collection_t& expected, const std::initializer_list<item_t>& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
527 for (const auto& item : expected) {
528 if (std::find_if(std::begin(actual), std::end(actual), [&](const item_t& value) {return value == item;}) == std::end(actual)) {
529 succeed(message, stack_frame);
530 return;
531 }
532 }
533 fail("not contains " + join_items(expected), join_items(actual), message, stack_frame);
534 }
535 template<class item_t, class collection_t>
536 static void does_not_contain(const std::initializer_list<item_t>& expected, const collection_t& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {does_not_contain(expected, actual, xtd::string::empty_string, stack_frame);}
537 template<class item_t, class collection_t>
538 static void does_not_contain(const std::initializer_list<item_t>& expected, const collection_t& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
539 for (const auto& item : expected) {
540 if (std::find_if(std::begin(actual), std::end(actual), [&](const item_t& value) {return value == item;}) == std::end(actual)) {
541 succeed(message, stack_frame);
542 return;
543 }
544 }
545 fail("not contains " + join_items(expected), join_items(actual), message, stack_frame);
546 }
548
560 template<class value_t>
561 static void is_empty(const value_t& value, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {is_empty(value, xtd::string::empty_string, stack_frame);}
574 template<class value_t>
575 static void is_empty(const value_t& value, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
576 if (std::empty(value)) succeed(message, stack_frame);
577 else fail("<empty>", join_items(value), message, stack_frame);
578 }
579
581 template<class value_t>
582 static void is_empty(const std::initializer_list<value_t>& value, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {is_empty(value, xtd::string::empty_string, stack_frame);}
583 template<class value_t>
584 static void is_empty(const std::initializer_list<value_t>& value, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
585 if (std::empty(value)) succeed(message, stack_frame);
586 else fail("<empty>", join_items(value), message, stack_frame);
587 }
589
601 template<class value_t>
602 static void is_not_empty(const value_t& value, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {is_not_empty(value, xtd::string::empty_string, stack_frame);}
615 template<class value_t>
616 static void is_not_empty(const value_t& value, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
617 if (!std::empty(value)) succeed(message, stack_frame);
618 else fail("not <empty>", "<empty>", message, stack_frame);
619 }
620
622 template<class value_t>
623 static void is_not_empty(const std::initializer_list<value_t>& value, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {is_not_empty(value, xtd::string::empty_string, stack_frame);}
624 template<class value_t>
625 static void is_not_empty(const std::initializer_list<value_t>& value, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
626 if (!std::empty(value)) succeed(message, stack_frame);
627 else fail("not <empty>", "<empty>", message, stack_frame);
628 }
630
642 template<class value_t>
643 static void is_ordered(const value_t& value, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {is_ordered(value, xtd::string::empty_string, stack_frame);}
656 template<class value_t>
657 static void is_ordered(const value_t& value, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
658 if (std::is_sorted(value.begin(), value.end())) succeed(message, stack_frame);
659 else fail("<ordered>", join_items(value), message, stack_frame);
660 }
661
663 template<class value_t>
664 static void is_ordered(const std::initializer_list<value_t>& value, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {is_ordered(value, xtd::string::empty_string, stack_frame);}
665 template<class value_t>
666 static void is_ordered(const std::initializer_list<value_t>& value, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
667 if (std::is_sorted(value.begin(), value.end())) succeed(message, stack_frame);
668 else fail("<ordered>", join_items(value), message, stack_frame);
669 }
672
673 private:
674 template <class expected_iterator_t, class actual_iterator_t>
675 static bool equals(expected_iterator_t expected_begin, expected_iterator_t expected_end, actual_iterator_t actual_begin, actual_iterator_t actual_end) {
676 return std::equal(expected_begin, expected_end, actual_begin, actual_end, [&](const auto& expected, const auto& actual) {return base_assert::equals(expected, actual);});
677 }
678
679 template <class expected_iterator_t, class actual_iterator_t>
680 static bool equivalents(expected_iterator_t expected_begin, expected_iterator_t expected_end, actual_iterator_t actual_begin, actual_iterator_t actual_end) {
681 if (std::distance(expected_begin, expected_end) != std::distance(actual_begin, actual_end)) return false;
682 for (auto iterator = expected_begin; iterator != expected_end; ++iterator)
683 if (std::find_if(actual_begin, actual_end, [&](const auto& value) {return base_assert::equals(value, *iterator);}) == actual_end) return false;
684 return true;
685 }
686 };
687 }
688}
static const basic_string empty_string
Represents the empty basic_string.
Definition basic_string.hpp:116
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition stack_frame.hpp:48
static stack_frame current(const xtd::diagnostics::source_location &value=xtd::diagnostics::source_location::current()) noexcept
Crates a new xtd::diagnostics::stack_frame object corresponding to the location of the call site.
The base class for assert.
Definition base_assert.hpp:30
The collection_assert class contains a collection of static methods that implement the most collectio...
Definition collection_assert.hpp:23
static void are_equivalent(const expected_t &expected, const actual_t &actual, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that all collection items are equivalent.
Definition collection_assert.hpp:264
static void is_ordered(const value_t &value, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that collection is ordered.
Definition collection_assert.hpp:657
static void is_empty(const value_t &value, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that collection contains an item.
Definition collection_assert.hpp:561
static void is_ordered(const value_t &value, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that collection is ordered.
Definition collection_assert.hpp:643
static void are_equal(const expected_t &expected, const actual_t &actual, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that all collection items are equal.
Definition collection_assert.hpp:210
static void are_equal(const expected_t &expected, const actual_t &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that all collection items are equal.
Definition collection_assert.hpp:197
static void are_not_equivalent(const expected_t &expected, const actual_t &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that all collection items are not equivalent.
Definition collection_assert.hpp:359
static void is_not_empty(const value_t &value, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that collection or traits does not contain any item.
Definition collection_assert.hpp:616
static void contains(const expected_t &expected, const actual_t &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that collection contains all items.
Definition collection_assert.hpp:413
static void all_items_are_not_null(const collection_t &collection, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that all collection items are not null.
Definition collection_assert.hpp:109
static void all_items_are_unique(const collection_t &collection, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that all collection items are unique.
Definition collection_assert.hpp:159
static void all_items_are_instances_of(const collection_t &collection, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that all collection items are of the type supplied or a derived type.
Definition collection_assert.hpp:57
static void are_not_equal(const expected_t &expected, const actual_t &actual, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that all collection items are not equal.
Definition collection_assert.hpp:318
static void does_not_contain(const expected_t &expected, const actual_t &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that collection contains all items.
Definition collection_assert.hpp:487
static void is_empty(const value_t &value, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that collection contains an item.
Definition collection_assert.hpp:575
static void is_not_empty(const value_t &value, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that collection or traits does not contain any item.
Definition collection_assert.hpp:602
static void all_items_are_unique(const collection_t &collection, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that all collection items are unique.
Definition collection_assert.hpp:145
static void all_items_are_not_null(const collection_t &collection, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that all collection items are not null.
Definition collection_assert.hpp:94
static void does_not_contain(const expected_t &expected, const actual_t &actual, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that collection contains all items.
Definition collection_assert.hpp:500
static void are_not_equal(const expected_t &expected, const actual_t &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that all collection items are not equal.
Definition collection_assert.hpp:305
static void contains(const expected_t &expected, const actual_t &actual, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that collection contains all items.
Definition collection_assert.hpp:426
static void are_not_equivalent(const expected_t &expected, const actual_t &actual, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that all collection items are not equivalent.
Definition collection_assert.hpp:372
static void all_items_are_instances_of(const collection_t &collection, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that all collection items are of the type supplied or a derived type.
Definition collection_assert.hpp:44
static void are_equivalent(const expected_t &expected, const actual_t &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that all collection items are equivalent.
Definition collection_assert.hpp:251
#define tunit_export_
Define shared library export.
Definition tunit_export.hpp:13
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Contains xtd::tunit::assert class.