[Boost.Test] range support

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Boost.Test] range support

Jens Theisen-3
Hello,

what do people think about Boost.Range support?

Instead of writing


my_range_type r = <complex expression>;

std::vector< int > v = list_of(1)(2)(3);

BOOST_CHECK_EQUAL_COLLECTIONS(r.begin(), r.end(), v.begin(), v.end());


one could write more conveniently the single line


BOOST_CHECK_EQUAL_RANGES( <complex expression>, list_of(1)(2)(3) );


It's also more readable and would so improve the documentational aspect of  
tests.

(Is it ok to post short diffs as this?)

Index: boost/test/test_tools.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/test/test_tools.hpp,v
retrieving revision 1.59
diff -u -r1.59 test_tools.hpp
--- boost/test/test_tools.hpp 3 Mar 2006 17:39:46 -0000 1.59
+++ boost/test/test_tools.hpp 6 Mar 2006 19:50:52 -0000
@@ -33,6 +33,7 @@
 #include <boost/preprocessor/repetition/repeat.hpp>
 #include <boost/preprocessor/punctuation/comma_if.hpp>
 #include <boost/preprocessor/arithmetic/add.hpp>
+#include <boost/range/functions.hpp>
 #include <boost/limits.hpp>

 #include <boost/type_traits/is_array.hpp>
@@ -222,6 +223,22 @@

 //____________________________________________________________________________//

+#define BOOST_EQUAL_RANGES_IMPL( L, R, TL )           \
+    BOOST_TEST_TOOL_IMPL( check_impl, ::boost::test_tools::tt_detail::equal_range_impl( \
+        (L), (R) ), "", TL, CHECK_EQUAL_COLL ),       \
+    2,                                                \
+    BOOST_STRINGIZE( L ), BOOST_STRINGIZE( R ) )      \
+/**/
+
+#define BOOST_WARN_EQUAL_RANGES( L, R )     \
+    BOOST_EQUAL_RANGES_IMPL( L, R, WARN )
+#define BOOST_CHECK_EQUAL_RANGES( L, R )    \
+    BOOST_EQUAL_RANGES_IMPL( L, R, CHECK )
+#define BOOST_REQUIRE_EQUAL_RANGES( L, R )  \
+    BOOST_EQUAL_RANGES_IMPL( L, R, REQUIRE )
+
+//____________________________________________________________________________//
+
 #define BOOST_BITWISE_EQUAL_IMPL( L, R, TL )                                    \
     BOOST_TEST_TOOL_IMPL( check_impl,                                           \
       ::boost::test_tools::tt_detail::bitwise_equal_impl( (L), (R) ),           \
@@ -547,6 +564,16 @@

 //____________________________________________________________________________//

+template <typename Left, typename Right>
+inline predicate_result
+equal_range_impl( Left const& left, Right const& right )
+{
+  return equal_coll_impl( boost::begin(left),  boost::end(left),
+  boost::begin(right), boost::end(right) );
+}
+
+//____________________________________________________________________________//
+
 template <class Left, class Right>
 inline predicate_result
 bitwise_equal_impl( Left const& left, Right const& right )


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [Boost.Test] range support

Gennadiy Rozental

"Jens Theisen" <[hidden email]> wrote in message
news:[hidden email]...

> Hello,
>
> what do people think about Boost.Range support?
>
> Instead of writing
>
>
> my_range_type r = <complex expression>;
>
> std::vector< int > v = list_of(1)(2)(3);
>
> BOOST_CHECK_EQUAL_COLLECTIONS(r.begin(), r.end(), v.begin(), v.end());
>
>
> one could write more conveniently the single line
>
>
> BOOST_CHECK_EQUAL_RANGES( <complex expression>, list_of(1)(2)(3) );
>
>
> It's also more readable and would so improve the documentational aspect of
> tests.

I think this idea has some merit. But I wouldn't want to enforce yet another
dependency on Boost.Test users. There are two options here:
 1. Put theses definition into separate header
 2. Guard these definitions with something like ifndef
BOOST_TEST_MINIMAL_DEPENDENCIES

In any case modification will have to be done after release.

Genandiy



_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [Boost.Test] range support

Jens Theisen-3
Gennadiy wrote:

>  1. Put theses definition into separate header

I would favor that.

> In any case modification will have to be done after release.

I'll come back to it then.

Jens



_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost