From cd1a18da49413ede03e83bd3e81b832a481270b6 Mon Sep 17 00:00:00 2001 From: Gammasoft Date: Sun, 10 Nov 2024 12:22:57 +0100 Subject: [PATCH] Fix xtd::tunit::collection_assert::contains and xtd::tunit::collection_assert::does_not_contain methods on linux --- .../include/xtd/tunit/collection_assert.h | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/xtd.tunit/include/xtd/tunit/collection_assert.h b/src/xtd.tunit/include/xtd/tunit/collection_assert.h index 07d9bdaf7fb..060463fa67c 100644 --- a/src/xtd.tunit/include/xtd/tunit/collection_assert.h +++ b/src/xtd.tunit/include/xtd/tunit/collection_assert.h @@ -456,8 +456,8 @@ namespace xtd { /// ``` template 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()) { - for (auto item : expected) { - if (std::find(actual.begin(), actual.end(), item) == actual.end()) { + for (const auto& item : expected) { + if (std::find_if(std::begin(actual), std::end(actual), [&](const auto& value) {return value == item;}) == std::end(actual)) { fail("contains " + join_items(expected), join_items(actual), message, stack_frame); return; } @@ -470,8 +470,8 @@ namespace xtd { static void contains(const std::initializer_list& expected, const std::initializer_list& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {contains(expected, actual, xtd::string::empty_string, stack_frame);} template static void contains(const std::initializer_list& expected, const std::initializer_list& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) { - for (auto item : expected) { - if (std::find(actual.begin(), actual.end(), item) == actual.end()) { + for (const auto& item : expected) { + if (std::find_if(std::begin(actual), std::end(actual), [&](const item_t& value) {return value == item;}) == std::end(actual)) { fail("contains " + join_items(expected), join_items(actual), message, stack_frame); return; } @@ -482,8 +482,8 @@ namespace xtd { static void contains(const collection_t& expected, const std::initializer_list& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {contains(expected, actual, xtd::string::empty_string, stack_frame);} template static void contains(const collection_t& expected, const std::initializer_list& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) { - for (auto item : expected) { - if (std::find(actual.begin(), actual.end(), item) == actual.end()) { + for (const auto& item : expected) { + if (std::find_if(std::begin(actual), std::end(actual), [&](const item_t& value) {return value == item;}) == std::end(actual)) { fail("contains " + join_items(expected), join_items(actual), message, stack_frame); return; } @@ -494,8 +494,8 @@ namespace xtd { static void contains(const std::initializer_list& 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);} template static void contains(const std::initializer_list& expected, const collection_t& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) { - for (auto item : expected) { - if (std::find(actual.begin(), actual.end(), item) == actual.end()) { + for (const auto& item : expected) { + if (std::find_if(std::begin(actual), std::end(actual), [&](const item_t& value) {return value == item;}) == std::end(actual)) { fail("contains " + join_items(expected), join_items(actual), message, stack_frame); return; } @@ -530,8 +530,8 @@ namespace xtd { /// ``` template 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()) { - for (auto item : expected) { - if (std::find(actual.begin(), actual.end(), item) == actual.end()) { + for (const auto& item : expected) { + if (std::find_if(std::begin(actual), std::end(actual), [&](const auto& value) {return value == item;}) == std::end(actual)) { assert::succeed(message, stack_frame); return; } @@ -544,8 +544,8 @@ namespace xtd { static void does_not_contain(const std::initializer_list& expected, const std::initializer_list& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {does_not_contain(expected, actual, xtd::string::empty_string, stack_frame);} template static void does_not_contain(const std::initializer_list& expected, const std::initializer_list& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) { - for (auto item : expected) { - if (std::find(actual.begin(), actual.end(), item) == actual.end()) { + for (const auto& item : expected) { + if (std::find_if(std::begin(actual), std::end(actual), [&](const item_t& value) {return value == item;}) == std::end(actual)) { assert::succeed(message, stack_frame); return; } @@ -556,8 +556,8 @@ namespace xtd { static void does_not_contain(const collection_t& expected, const std::initializer_list& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {does_not_contain(expected, actual, xtd::string::empty_string, stack_frame);} template static void does_not_contain(const collection_t& expected, const std::initializer_list& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) { - for (auto item : expected) { - if (std::find(actual.begin(), actual.end(), item) == actual.end()) { + for (const auto& item : expected) { + if (std::find_if(std::begin(actual), std::end(actual), [&](const item_t& value) {return value == item;}) == std::end(actual)) { assert::succeed(message, stack_frame); return; } @@ -568,8 +568,8 @@ namespace xtd { static void does_not_contain(const std::initializer_list& 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);} template static void does_not_contain(const std::initializer_list& expected, const collection_t& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) { - for (auto item : expected) { - if (std::find(actual.begin(), actual.end(), item) == actual.end()) { + for (const auto& item : expected) { + if (std::find_if(std::begin(actual), std::end(actual), [&](const item_t& value) {return value == item;}) == std::end(actual)) { assert::succeed(message, stack_frame); return; } @@ -719,10 +719,10 @@ namespace xtd { static bool __are_equivalent(const expected_t expected, const actual_t& actual) { if (std::distance(expected.begin(), expected.end()) != std::distance(actual.begin(), actual.end())) return false; for (auto iterator = expected.begin(); iterator != expected.end(); ++iterator) - if (std::find(actual.begin(), actual.end(), *iterator) == actual.end()) return false; + if (std::find_if(std::begin(actual), std::end(actual), [&](const auto& value) {return value == *iterator;}) == std::end(actual)) return false; return true; } - + }; } }