diff --git a/include/boost/core/lightweight_test.hpp b/include/boost/core/lightweight_test.hpp index 8cc5547..8ed0f7d 100644 --- a/include/boost/core/lightweight_test.hpp +++ b/include/boost/core/lightweight_test.hpp @@ -181,58 +181,73 @@ inline void test_cstr_ne_impl( char const * expr1, char const * expr2, } } -template +template void test_all_eq_impl(FormattedOutputFunction& output, char const * file, int line, char const * function, - ForwardIterator1 first_begin, ForwardIterator1 first_end, - ForwardIterator2 second_begin, ForwardIterator2 second_end) + InputIterator1 first_begin, InputIterator1 first_end, + InputIterator2 second_begin, InputIterator2 second_end) { - typename std::iterator_traits::difference_type first_distance = std::distance(first_begin, first_end); - typename std::iterator_traits::difference_type second_distance = std::distance(second_begin, second_end); - if (first_distance != second_distance) + InputIterator1 first_it = first_begin; + InputIterator2 second_it = second_begin; + typename std::iterator_traits::difference_type first_index = 0; + typename std::iterator_traits::difference_type second_index = 0; + std::size_t error_count = 0; + do { - output << file << "(" << line << "): " - << "Container sizes are different" - << " in function '" << function << "': " - << first_distance << " != " << second_distance - << std::endl; - ++test_errors(); - } - else - { - ForwardIterator1 first_it = first_begin; - ForwardIterator2 second_it = second_begin; - std::size_t error_count = 0; - do + while ((first_it != first_end) && (second_it != second_end) && (*first_it == *second_it)) { - while ((first_it != first_end) && (second_it != second_end) && (*first_it == *second_it)) - { - ++first_it; - ++second_it; - } - if (first_it == first_end) - { - break; // do-while - } - if (error_count == 0) - { - output << file << "(" << line << "): Container contents differ in function '" << function << "': mismatching indices"; - } - output << " [" << std::distance(first_begin, first_it) << "] '" << test_output_impl(*first_it) << "' != '" << test_output_impl(*second_it) << "'"; ++first_it; ++second_it; - ++error_count; - } while (first_it != first_end); - + ++first_index; + ++second_index; + } + if ((first_it == first_end) || (second_it == second_end)) + { + break; // do-while + } if (error_count == 0) { - boost::detail::report_errors_remind(); + output << file << "(" << line << "): Container contents differ in function '" << function << "':"; + } + output << " [" << first_index << "] '" << test_output_impl(*first_it) << "' != '" << test_output_impl(*second_it) << "'"; + ++first_it; + ++second_it; + ++first_index; + ++second_index; + ++error_count; + } while (first_it != first_end); + + while (first_it != first_end) + { + ++first_it; + ++first_index; + } + while (second_it != second_end) + { + ++second_it; + ++second_index; + } + if (first_index != second_index) + { + if (error_count == 0) + { + output << file << "(" << line << "): Container sizes differ in function '" << function << "': size(" << first_index << ") != size(" << second_index << ")"; } else { - output << std::endl; - ++boost::detail::test_errors(); + output << " [*] size(" << first_index << ") != size(" << second_index << ")"; } + ++error_count; + } + + if (error_count == 0) + { + boost::detail::report_errors_remind(); + } + else + { + output << std::endl; + ++boost::detail::test_errors(); } } diff --git a/test/lightweight_test_fail11.cpp b/test/lightweight_test_fail11.cpp index 474d307..120a859 100644 --- a/test/lightweight_test_fail11.cpp +++ b/test/lightweight_test_fail11.cpp @@ -9,18 +9,52 @@ // #include +#include #include int main() { int test_cases = 0; + // Array + + { + int x[] = { 1 }; + int y[] = { 1, 2 }; + BOOST_TEST_ALL_EQ( x, x + sizeof(x)/sizeof(x[0]), y, y + sizeof(y)/sizeof(y[0]) ); + ++test_cases; + } + + { + int x[] = { 1, 2 }; + int y[] = { 1 }; + BOOST_TEST_ALL_EQ( x, x + sizeof(x)/sizeof(x[0]), y, y + sizeof(y)/sizeof(y[0]) ); + ++test_cases; + } + + { + int x[] = { 2 }; + int y[] = { 1, 2 }; + BOOST_TEST_ALL_EQ( x, x + sizeof(x)/sizeof(x[0]), y, y + sizeof(y)/sizeof(y[0]) ); + ++test_cases; + } + + { + int x[] = { 1, 2, 3, 4 }; + int y[] = { 1, 3, 2, 4 }; + BOOST_TEST_ALL_EQ( x, x + sizeof(x)/sizeof(x[0]), y, y + sizeof(y)/sizeof(y[0]) ); + ++test_cases; + } + + // Vector + { std::vector x, y; x.push_back( 1 ); BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); ++test_cases; } + { std::vector x, y; y.push_back( 1 ); @@ -44,6 +78,48 @@ int main() ++test_cases; } + { + std::vector x, y; + x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); + y.push_back( 1 ); y.push_back( 3 ); y.push_back( 2 ); y.push_back( 4 ); + BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); + ++test_cases; + } + + { + std::vector x, y; + x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); x.push_back( 4 ); + y.push_back( 1 ); y.push_back( 3 ); y.push_back( 2 );; + BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); + ++test_cases; + } + + // Set + + { + std::set x, y; + x.insert(1); + y.insert(1); y.insert(3); + BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); + ++test_cases; + } + + { + std::set x, y; + x.insert(1); x.insert(2); + y.insert(1); + BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); + ++test_cases; + } + + { + std::set x, y; + x.insert(1); x.insert(2); + y.insert(1); y.insert(3); + BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); + ++test_cases; + } + boost::report_errors(); return boost::detail::test_errors() == test_cases;