$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r80618 - trunk/libs/algorithm/test
From: marshall_at_[hidden]
Date: 2012-09-21 10:52:38
Author: marshall
Date: 2012-09-21 10:52:38 EDT (Fri, 21 Sep 2012)
New Revision: 80618
URL: http://svn.boost.org/trac/boost/changeset/80618
Log:
Fix bugs in copy_if; add basic tests. Refs #7400. Thanks to Hideaki Takei for the catch
Added:
   trunk/libs/algorithm/test/copy_if_test1.cpp   (contents, props changed)
Text files modified: 
   trunk/libs/algorithm/test/Jamfile.v2 |     1 +                                       
   1 files changed, 1 insertions(+), 0 deletions(-)
Modified: trunk/libs/algorithm/test/Jamfile.v2
==============================================================================
--- trunk/libs/algorithm/test/Jamfile.v2	(original)
+++ trunk/libs/algorithm/test/Jamfile.v2	2012-09-21 10:52:38 EDT (Fri, 21 Sep 2012)
@@ -32,6 +32,7 @@
      
      [ run ordered_test.cpp       : : : : ordered_test ]
      [ run find_if_not_test1.cpp  : : : : find_if_not_test1 ]
+     [ run copy_if_test1.cpp       : : : : copy_if_test1 ]
      [ run copy_n_test1.cpp       : : : : copy_n_test1 ]
      [ run iota_test1.cpp         : : : : iota_test1 ]
 
Added: trunk/libs/algorithm/test/copy_if_test1.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/algorithm/test/copy_if_test1.cpp	2012-09-21 10:52:38 EDT (Fri, 21 Sep 2012)
@@ -0,0 +1,87 @@
+/* 
+   Copyright (c) Marshall Clow 2012.
+
+   Distributed under the Boost Software License, Version 1.0. (See accompanying
+   file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+    For more information, see http://www.boost.org
+*/
+
+#include <boost/config.hpp>
+#include <boost/algorithm/cxx11/copy_if.hpp>
+#include <boost/test/included/test_exec_monitor.hpp>
+
+#include <algorithm>
+#include <string>
+#include <iostream>
+#include <vector>
+#include <list>
+
+#include <boost/algorithm/cxx11/all_of.hpp>
+
+namespace ba = boost::algorithm;
+// namespace ba = boost;
+
+bool is_true  ( int v ) { return true; }
+bool is_false ( int v ) { return false; }
+bool is_even  ( int v ) { return v % 2 == 0; }
+bool is_odd   ( int v ) { return v % 2 == 1; }
+
+template <typename Container>
+void test_sequence ( Container const &c ) {
+
+    typedef typename Container::value_type value_type;
+    std::vector<value_type> v;
+    
+//  None of the elements
+    v.clear ();
+    ba::copy_if ( c.begin (), c.end (), back_inserter ( v ), is_false);
+    BOOST_CHECK ( v.size () == 0 );
+
+    v.clear ();
+    ba::copy_if ( c, back_inserter ( v ), is_false);
+    BOOST_CHECK ( v.size () == 0 );
+
+//	All the elements
+    v.clear ();
+    ba::copy_if ( c.begin (), c.end (), back_inserter ( v ), is_true);
+    BOOST_CHECK ( v.size () == c.size ());
+    BOOST_CHECK ( std::equal ( c.begin (), c.end (), v.begin ()));
+
+    v.clear ();
+    ba::copy_if ( c, back_inserter ( v ), is_true);
+    BOOST_CHECK ( v.size () == c.size ());
+    BOOST_CHECK ( v.size () == c.size ());
+    BOOST_CHECK ( std::equal ( c.begin (), c.end (), v.begin ()));
+
+//	Some of the elements
+    v.clear ();
+    ba::copy_if ( c.begin (), c.end (), back_inserter ( v ), is_even );
+    BOOST_CHECK ( v.size () == std::count_if ( c.begin (), c.end (), is_even ));
+    BOOST_CHECK ( ba::all_of ( v.begin (), v.end (), is_even ));
+
+    v.clear ();
+    ba::copy_if ( c, back_inserter ( v ), is_even );
+    BOOST_CHECK ( v.size () == std::count_if ( c.begin (), c.end (), is_even ));
+    BOOST_CHECK ( ba::all_of ( v.begin (), v.end (), is_even ));
+    }
+
+
+void test_sequence1 () {
+    std::vector<int> v;
+    for ( int i = 5; i < 15; ++i )
+        v.push_back ( i );
+    test_sequence  ( v );
+    
+    std::list<int> l;
+    for ( int i = 25; i > 15; --i )
+        l.push_back ( i );
+    test_sequence  ( l );   
+    }
+
+
+int test_main( int , char* [] )
+{
+  test_sequence1 ();
+  return 0;
+}