Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77134 - in trunk: boost/algorithm/cxx11 libs/algorithm/test
From: marshall_at_[hidden]
Date: 2012-02-28 13:44:07


Author: marshall
Date: 2012-02-28 13:44:06 EST (Tue, 28 Feb 2012)
New Revision: 77134
URL: http://svn.boost.org/trac/boost/changeset/77134

Log:
More tests; removed ambiguity
Text files modified:
   trunk/boost/algorithm/cxx11/ordered.hpp | 9 +++-
   trunk/libs/algorithm/test/ordered_test.cpp | 71 +++++++++++++++++++++++++++------------
   2 files changed, 56 insertions(+), 24 deletions(-)

Modified: trunk/boost/algorithm/cxx11/ordered.hpp
==============================================================================
--- trunk/boost/algorithm/cxx11/ordered.hpp (original)
+++ trunk/boost/algorithm/cxx11/ordered.hpp 2012-02-28 13:44:06 EST (Tue, 28 Feb 2012)
@@ -22,6 +22,7 @@
 
 #include <boost/utility/enable_if.hpp>
 #include <boost/type_traits/is_same.hpp>
+#include <boost/mpl/identity.hpp>
 
 namespace boost { namespace algorithm {
 
@@ -124,6 +125,9 @@
         return boost::algorithm::is_sorted_until ( boost::begin ( range ), boost::end ( range ));
     }
 
+namespace detail {
+ typedef struct { typedef bool type; } bool_;
+};
 
 /// \fn is_sorted ( const R &range, Pred p )
 /// \return whether or not the entire range R is sorted
@@ -133,7 +137,8 @@
 /// \param p A binary predicate that returns true if two elements are ordered.
 ///
     template <typename R, typename Pred>
- bool is_sorted ( const R &range, Pred p )
+ typename boost::lazy_disable_if_c< boost::is_same<R, Pred>::value, boost::mpl::identity<bool> >::type
+ is_sorted ( const R &range, Pred p )
     {
         return boost::algorithm::is_sorted ( boost::begin ( range ), boost::end ( range ), p );
     }
@@ -144,7 +149,7 @@
 ///
 /// \param range The range to be tested.
 ///
- template <typename R, typename Pred>
+ template <typename R>
     bool is_sorted ( const R &range )
     {
         return boost::algorithm::is_sorted ( boost::begin ( range ), boost::end ( range ));

Modified: trunk/libs/algorithm/test/ordered_test.cpp
==============================================================================
--- trunk/libs/algorithm/test/ordered_test.cpp (original)
+++ trunk/libs/algorithm/test/ordered_test.cpp 2012-02-28 13:44:06 EST (Tue, 28 Feb 2012)
@@ -31,13 +31,59 @@
 test_ordered(void)
 {
     const int strictlyIncreasingValues[] = { 1, 2, 3, 4, 5 };
+ const int randomValues[] = { 3, 6, 1, 2, 7 };
+ const int constantValues[] = { 1, 2, 2, 2, 5 };
+ int nonConstantArray[] = { 1, 2, 2, 2, 5 };
+ const int inOrderUntilTheEnd [] = { 0, 1, 2, 3, 4, 5, 6, 7, 6 };
+
+// Begin/end checks
+ BOOST_CHECK ( ba::is_sorted (b_e(strictlyIncreasingValues)));
+ BOOST_CHECK ( !ba::is_sorted (b_e(randomValues)));
+ BOOST_CHECK ( ba::is_sorted (b_e(strictlyIncreasingValues), std::less<int>()));
+ BOOST_CHECK ( !ba::is_sorted (b_e(strictlyIncreasingValues), std::greater<int>()));
+
+// Range checks
+ BOOST_CHECK ( ba::is_sorted (a_range(strictlyIncreasingValues)));
+ BOOST_CHECK ( !ba::is_sorted (a_range(randomValues)));
+ BOOST_CHECK ( ba::is_sorted (a_range(strictlyIncreasingValues), std::less<int>()));
+ BOOST_CHECK ( !ba::is_sorted (a_range(strictlyIncreasingValues), std::greater<int>()));
+
+ BOOST_CHECK ( ba::is_sorted_until ( b_e(strictlyIncreasingValues)) == a_end(strictlyIncreasingValues));
+ BOOST_CHECK ( ba::is_sorted_until ( b_e(strictlyIncreasingValues), std::less<int>()) == a_end(strictlyIncreasingValues));
+ BOOST_CHECK ( ba::is_sorted_until ( a_range(strictlyIncreasingValues)) == boost::end(strictlyIncreasingValues));
+ BOOST_CHECK ( ba::is_sorted_until ( a_range(strictlyIncreasingValues), std::less<int>()) == boost::end(strictlyIncreasingValues));
+
+// Check for const and non-const arrays
+ BOOST_CHECK ( ba::is_sorted_until ( b_e(constantValues), std::less<int>()) != a_end(constantValues));
+ BOOST_CHECK ( ba::is_sorted_until ( a_range(constantValues), std::less<int>()) != boost::end(constantValues));
+ BOOST_CHECK ( ba::is_sorted_until ( b_e(nonConstantArray), std::less<int>()) != a_end(nonConstantArray));
+ BOOST_CHECK ( ba::is_sorted_until ( a_range(nonConstantArray), std::less<int>()) != boost::end(nonConstantArray));
+
+ BOOST_CHECK ( ba::is_sorted_until ( b_e(randomValues), std::less<int>()) == &randomValues[2] );
+ BOOST_CHECK ( ba::is_sorted_until ( b_e(randomValues)) == &randomValues[2] );
+ BOOST_CHECK ( ba::is_sorted_until ( a_range(randomValues), std::less<int>()) == &randomValues[2] );
+ BOOST_CHECK ( ba::is_sorted_until ( a_range(randomValues)) == &randomValues[2] );
+
+ BOOST_CHECK ( ba::is_sorted_until ( a_range(inOrderUntilTheEnd), std::less<int>()) == &inOrderUntilTheEnd[8] );
+ BOOST_CHECK ( ba::is_sorted_until ( a_range(inOrderUntilTheEnd)) == &inOrderUntilTheEnd[8] );
+
+// For zero and one element collections, the comparison predicate should never be called
+ BOOST_CHECK ( ba::is_sorted_until ( a_begin(randomValues), a_begin(randomValues), std::equal_to<int>()) == a_begin(randomValues));
+ BOOST_CHECK ( ba::is_sorted_until ( a_begin(randomValues), a_begin(randomValues)) == a_begin(randomValues));
+ BOOST_CHECK ( ba::is_sorted_until ( a_begin(randomValues), a_begin(randomValues) + 1, std::equal_to<int>()) == a_begin(randomValues) + 1);
+ BOOST_CHECK ( ba::is_sorted_until ( a_begin(randomValues), a_begin(randomValues) + 1 ) == a_begin(randomValues) + 1);
+}
+
+
+static void
+test_increasing_decreasing(void)
+{
+ const int strictlyIncreasingValues[] = { 1, 2, 3, 4, 5 };
     const int strictlyDecreasingValues[] = { 9, 8, 7, 6, 5 };
     const int increasingValues[] = { 1, 2, 2, 2, 5 };
     const int decreasingValues[] = { 9, 7, 7, 7, 5 };
     const int randomValues[] = { 3, 6, 1, 2, 7 };
     const int constantValues[] = { 7, 7, 7, 7, 7 };
- int nonConstantArray[] = { 7, 7, 7, 7, 7 };
- const int inOrderUntilTheEnd [] = { 0, 1, 2, 3, 4, 5, 6, 7, 6 };
 
     // Test a strictly increasing sequence
     BOOST_CHECK ( ba::is_strictly_increasing (b_e(strictlyIncreasingValues)));
@@ -98,30 +144,11 @@
     BOOST_CHECK ( !ba::is_strictly_decreasing (strictlyIncreasingValues, strictlyIncreasingValues+2));
     BOOST_CHECK ( !ba::is_decreasing (strictlyIncreasingValues, strictlyIncreasingValues+2));
     
- // Test underlying routines
- BOOST_CHECK ( ba::is_sorted_until ( b_e(strictlyIncreasingValues), std::less<int>()) == a_end(strictlyIncreasingValues));
- BOOST_CHECK ( ba::is_sorted_until ( a_range(strictlyIncreasingValues), std::less<int>()) == boost::end(strictlyIncreasingValues));
-
- BOOST_CHECK ( ba::is_sorted_until ( b_e(nonConstantArray), std::less<int>()) != a_end(nonConstantArray));
- BOOST_CHECK ( ba::is_sorted_until ( a_range(nonConstantArray), std::less<int>()) != boost::end(nonConstantArray));
-
- BOOST_CHECK ( ba::is_sorted_until ( b_e(randomValues), std::less<int>()) == &randomValues[2] );
- BOOST_CHECK ( ba::is_sorted_until ( a_range(randomValues), std::less<int>()) == &randomValues[2] );
-
- BOOST_CHECK ( ba::is_sorted_until ( b_e(randomValues), std::less<int>()) == &randomValues[2] );
- BOOST_CHECK ( ba::is_sorted_until ( a_range(randomValues), std::less<int>()) == &randomValues[2] );
-
- BOOST_CHECK ( ba::is_sorted_until ( a_range(inOrderUntilTheEnd), std::less<int>()) == &inOrderUntilTheEnd[8] );
-
-// For zero and one element collections, the comparison predicate should never be called
- BOOST_CHECK ( ba::is_sorted_until ( a_begin(randomValues), a_begin(randomValues), std::equal_to<int>()) == a_begin(randomValues));
- BOOST_CHECK ( ba::is_sorted_until ( a_begin(randomValues), a_begin(randomValues) + 1, std::equal_to<int>()) == a_begin(randomValues) + 1);
-
 }
 
 int test_main( int, char * [] )
 {
     test_ordered ();
-
+ test_increasing_decreasing ();
     return 0;
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk