xtd 0.2.0
Loading...
Searching...
No Matches
collection_assert.h
Go to the documentation of this file.
1
4#pragma once
5#include "assert.h"
6
8namespace xtd {
10 namespace tunit {
24 public:
26 collection_assert() = delete;
28
30
43 template<typename expected_t, typename 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<typename expected_t, typename 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 assert::succeed(message, stack_frame);
64 }
65
67 template<typename expected_t, typename 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<typename expected_t, typename 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 assert::succeed(message, stack_frame);
77 }
79
93 template<typename 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<typename 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 assert::succeed(message, stack_frame);
116 }
117
119 template<typename 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<typename 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 assert::succeed(message, stack_frame);
129 }
131
144 template<typename 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<typename 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 assert::succeed(message, stack_frame);
168 }
169
171 template<typename 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<typename 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 assert::succeed(message, stack_frame);
182 }
184
196 template<typename expected_t, typename 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<typename expected_t, typename 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 (std::equal(actual.begin(), actual.end(), expected.begin(), expected.end()) == false)
212 fail(join_items(expected), join_items(actual), message, stack_frame);
213 else
214 assert::succeed(message, stack_frame);
215 }
216
218 template<typename item_t>
219 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);}
220 template<typename item_t>
221 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()) {
222 if (std::equal(actual.begin(), actual.end(), expected.begin(), expected.end()) == false)
223 fail(join_items(expected), join_items(actual), message, stack_frame);
224 else
225 assert::succeed(message, stack_frame);
226 }
227 template<typename collection_t, typename item_t>
228 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);}
229 template<typename collection_t, typename item_t>
230 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()) {
231 if (std::equal(actual.begin(), actual.end(), expected.begin(), expected.end()) == false)
232 fail(join_items(expected), join_items(actual), message, stack_frame);
233 else
234 assert::succeed(message, stack_frame);
235 }
236 template<typename item_t, typename collection_t>
237 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);}
238 template<typename item_t, typename collection_t>
239 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()) {
240 if (std::equal(actual.begin(), actual.end(), expected.begin(), expected.end()) == false)
241 fail(join_items(expected), join_items(actual), message, stack_frame);
242 else
243 assert::succeed(message, stack_frame);
244 }
246
258 template<typename expected_t, typename actual_t>
259 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);}
271 template<typename expected_t, typename actual_t>
272 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()) {
273 if (!__are_equivalent(expected, actual))
274 fail("equivalent " + join_items(expected), join_items(actual), message, stack_frame);
275 else
276 assert::succeed(message, stack_frame);
277 }
278
280 template<typename expected_t, typename actual_t>
281 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);}
282 template<typename expected_t, typename actual_t>
283 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()) {
284 if (!__are_equivalent(expected, actual))
285 fail("equivalent " + join_items(expected), join_items(actual), message, stack_frame);
286 else
287 assert::succeed(message, stack_frame);
288 }
289 template<typename collection_t, typename item_t>
290 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);}
291 template<typename collection_t, typename item_t>
292 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()) {
293 if (!__are_equivalent(expected, actual))
294 fail("equivalent " + join_items(expected), join_items(actual), message, stack_frame);
295 else
296 assert::succeed(message, stack_frame);
297 }
298 template<typename item_t, typename collection_t>
299 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);}
300 template<typename item_t, typename collection_t>
301 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()) {
302 if (!__are_equivalent(expected, actual))
303 fail("equivalent " + join_items(expected), join_items(actual), message, stack_frame);
304 else
305 assert::succeed(message, stack_frame);
306 }
308
320 template<typename expected_t, typename actual_t>
321 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);}
333 template<typename expected_t, typename actual_t>
334 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()) {
335 if (std::equal(actual.begin(), actual.end(), expected.begin(), expected.end()) == true)
336 fail("not " + join_items(expected), join_items(actual), message, stack_frame);
337 else
338 assert::succeed(message, stack_frame);
339 }
340
342 template<typename item_t>
343 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);}
344 template<typename item_t>
345 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()) {
346 if (std::equal(actual.begin(), actual.end(), expected.begin(), expected.end()) == true)
347 fail("not " + join_items(expected), join_items(actual), message, stack_frame);
348 else
349 assert::succeed(message, stack_frame);
350 }
351 template<typename collection_t, typename item_t>
352 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);}
353 template<typename collection_t, typename item_t>
354 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()) {
355 if (std::equal(actual.begin(), actual.end(), expected.begin(), expected.end()) == true)
356 fail("not " + join_items(expected), join_items(actual), message, stack_frame);
357 else
358 assert::succeed(message, stack_frame);
359 }
360 template<typename item_t, typename collection_t>
361 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);}
362 template<typename item_t, typename collection_t>
363 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()) {
364 if (std::equal(actual.begin(), actual.end(), expected.begin(), expected.end()) == true)
365 fail("not " + join_items(expected), join_items(actual), message, stack_frame);
366 else
367 assert::succeed(message, stack_frame);
368 }
370
382 template<typename expected_t, typename actual_t>
383 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);}
395 template<typename expected_t, typename actual_t>
396 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()) {
397 if (__are_equivalent(expected, actual))
398 fail("not equivalent " + join_items(expected), join_items(actual), message, stack_frame);
399 else
400 assert::succeed(message, stack_frame);
401 }
402
404 template<typename expected_t, typename actual_t>
405 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);}
406 template<typename expected_t, typename actual_t>
407 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()) {
408 if (__are_equivalent(expected, actual))
409 fail("not equivalent " + join_items(expected), join_items(actual), message, stack_frame);
410 else
411 assert::succeed(message, stack_frame);
412 }
413 template<typename collection_t, typename item_t>
414 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);}
415 template<typename collection_t, typename item_t>
416 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()) {
417 if (__are_equivalent(expected, actual))
418 fail("not equivalent " + join_items(expected), join_items(actual), message, stack_frame);
419 else
420 assert::succeed(message, stack_frame);
421 }
422 template<typename item_t, typename collection_t>
423 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);}
424 template<typename item_t, typename collection_t>
425 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()) {
426 if (__are_equivalent(expected, actual))
427 fail("not equivalent " + join_items(expected), join_items(actual), message, stack_frame);
428 else
429 assert::succeed(message, stack_frame);
430 }
432
444 template<typename expected_t, typename actual_t>
445 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);}
457 template<typename expected_t, typename actual_t>
458 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()) {
459 for (auto item : expected) {
460 if (std::find(actual.begin(), actual.end(), item) == actual.end()) {
461 fail("contains " + join_items(expected), join_items(actual), message, stack_frame);
462 return;
463 }
464 }
465 assert::succeed(message, stack_frame);
466 }
467
469 template<typename item_t>
470 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);}
471 template<typename item_t>
472 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()) {
473 for (auto item : expected) {
474 if (std::find(actual.begin(), actual.end(), item) == actual.end()) {
475 fail("contains " + join_items(expected), join_items(actual), message, stack_frame);
476 return;
477 }
478 }
479 assert::succeed(message, stack_frame);
480 }
481 template<typename collection_t, typename item_t>
482 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);}
483 template<typename collection_t, typename item_t>
484 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()) {
485 for (auto item : expected) {
486 if (std::find(actual.begin(), actual.end(), item) == actual.end()) {
487 fail("contains " + join_items(expected), join_items(actual), message, stack_frame);
488 return;
489 }
490 }
491 assert::succeed(message, stack_frame);
492 }
493 template<typename item_t, typename collection_t>
494 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);}
495 template<typename item_t, typename collection_t>
496 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()) {
497 for (auto item : expected) {
498 if (std::find(actual.begin(), actual.end(), item) == actual.end()) {
499 fail("contains " + join_items(expected), join_items(actual), message, stack_frame);
500 return;
501 }
502 }
503 assert::succeed(message, stack_frame);
504 }
506
518 template<typename expected_t, typename actual_t>
519 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);}
531 template<typename expected_t, typename actual_t>
532 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()) {
533 for (auto item : expected) {
534 if (std::find(actual.begin(), actual.end(), item) == actual.end()) {
535 assert::succeed(message, stack_frame);
536 return;
537 }
538 }
539 fail("not contains " + join_items(expected), join_items(actual), message, stack_frame);
540 }
541
543 template<typename item_t>
544 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);}
545 template<typename item_t>
546 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()) {
547 for (auto item : expected) {
548 if (std::find(actual.begin(), actual.end(), item) == actual.end()) {
549 assert::succeed(message, stack_frame);
550 return;
551 }
552 }
553 fail("not contains " + join_items(expected), join_items(actual), message, stack_frame);
554 }
555 template<typename collection_t, typename item_t>
556 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);}
557 template<typename collection_t, typename item_t>
558 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()) {
559 for (auto item : expected) {
560 if (std::find(actual.begin(), actual.end(), item) == actual.end()) {
561 assert::succeed(message, stack_frame);
562 return;
563 }
564 }
565 fail("not contains " + join_items(expected), join_items(actual), message, stack_frame);
566 }
567 template<typename item_t, typename collection_t>
568 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);}
569 template<typename item_t, typename collection_t>
570 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()) {
571 for (auto item : expected) {
572 if (std::find(actual.begin(), actual.end(), item) == actual.end()) {
573 assert::succeed(message, stack_frame);
574 return;
575 }
576 }
577 fail("not contains " + join_items(expected), join_items(actual), message, stack_frame);
578 }
580
592 template<typename value_t>
593 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);}
606 template<typename value_t>
607 static void is_empty(const value_t& value, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
608 if (std::empty(value))
609 assert::succeed(message, stack_frame);
610 else
611 fail("<empty>", join_items(value), message, stack_frame);
612 }
613
615 template<typename value_t>
616 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);}
617 template<typename value_t>
618 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()) {
619 if (std::empty(value))
620 assert::succeed(message, stack_frame);
621 else
622 fail("<empty>", join_items(value), message, stack_frame);
623 }
625
637 template<typename value_t>
638 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);}
651 template<typename value_t>
652 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()) {
653 if (!std::empty(value))
654 assert::succeed(message, stack_frame);
655 else
656 fail("not <empty>", "<empty>", message, stack_frame);
657 }
658
660 template<typename value_t>
661 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);}
662 template<typename value_t>
663 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()) {
664 if (!std::empty(value))
665 assert::succeed(message, stack_frame);
666 else
667 fail("not <empty>", "<empty>", message, stack_frame);
668 }
670
682 template<typename value_t>
683 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);}
696 template<typename value_t>
697 static void is_ordered(const value_t& value, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
698 if (std::is_sorted(value.begin(), value.end()))
699 assert::succeed(message, stack_frame);
700 else
701 fail("<ordered>", join_items(value), message, stack_frame);
702 }
703
705 template<typename value_t>
706 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);}
707 template<typename value_t>
708 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()) {
709 if (std::is_sorted(value.begin(), value.end()))
710 assert::succeed(message, stack_frame);
711 else
712 fail("<ordered>", join_items(value), message, stack_frame);
713 }
716
717 private:
718 template <typename expected_t, typename actual_t>
719 static bool __are_equivalent(const expected_t expected, const actual_t& actual) {
720 if (std::distance(expected.begin(), expected.end()) != std::distance(actual.begin(), actual.end())) return false;
721 for (auto iterator = expected.begin(); iterator != expected.end(); ++iterator)
722 if (std::find(actual.begin(), actual.end(), *iterator) == actual.end()) return false;
723 return true;
724 }
725
726 };
727 }
728}
static const basic_string empty_string
Represents the empty basic_string.
Definition basic_string.h:124
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition stack_frame.h:47
static stack_frame current(const xtd::source_location &value=xtd::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.h:29
The collection_assert class contains a collection of static methods that implement the most collectio...
Definition collection_assert.h: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.h:272
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.h:697
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.h:593
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.h:683
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.h: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.h: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.h:383
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.h:652
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.h:445
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.h: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.h: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.h: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.h:334
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.h:519
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.h:607
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.h:638
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.h: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.h: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.h:532
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.h:321
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.h:458
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.h:396
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.h: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.h:259
#define tunit_export_
Define shared library export.
Definition tunit_export.h:13
int32_t int32
Represents a 32-bit signed integer.
Definition int32.h:23
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Contains xtd::tunit::assert class.