summaryrefslogtreecommitdiff
path: root/libs/algorithm/test/iota_test1.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2013-06-25 22:59:01 +0000
committer <>2013-09-27 11:49:28 +0000
commit8c4528713d907ee2cfd3bfcbbad272c749867f84 (patch)
treec09e2ce80f47b90c85cc720f5139089ad9c8cfff /libs/algorithm/test/iota_test1.cpp
downloadboost-tarball-baserock/morph.tar.gz
Imported from /home/lorry/working-area/delta_boost-tarball/boost_1_54_0.tar.bz2.boost_1_54_0baserock/morph
Diffstat (limited to 'libs/algorithm/test/iota_test1.cpp')
-rw-r--r--libs/algorithm/test/iota_test1.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/libs/algorithm/test/iota_test1.cpp b/libs/algorithm/test/iota_test1.cpp
new file mode 100644
index 000000000..080d3d78b
--- /dev/null
+++ b/libs/algorithm/test/iota_test1.cpp
@@ -0,0 +1,80 @@
+/*
+ Copyright (c) Marshall Clow 2011-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/iota.hpp>
+
+#define BOOST_TEST_MAIN
+#include <boost/test/unit_test.hpp>
+
+#include <iostream>
+#include <string>
+#include <vector>
+#include <list>
+
+// Test to make sure a sequence is "correctly formed"; i.e, ascending by one
+template <typename Iterator, typename T>
+bool test_iota_results ( Iterator first, Iterator last, T initial_value ) {
+ if ( first == last ) return true;
+ if ( initial_value != *first ) return false;
+ Iterator prev = first;
+ while ( ++first != last ) {
+ if (( *first - *prev ) != 1 )
+ return false;
+ prev = first;
+ }
+ return true;
+ }
+
+template <typename Range, typename T>
+bool test_iota_results ( const Range &r, T initial_value ) {
+ return test_iota_results (boost::begin (r), boost::end (r), initial_value );
+}
+
+
+void test_ints () {
+ std::vector<int> v;
+ std::list<int> l;
+
+ v.clear (); v.reserve ( 10 );
+ boost::algorithm::iota ( v.begin (), v.end (), 23 );
+ BOOST_CHECK ( test_iota_results ( v.begin (), v.end (), 23 ));
+
+ v.clear (); v.reserve ( 19 );
+ boost::algorithm::iota ( v, 18 );
+ BOOST_CHECK ( test_iota_results ( v, 18 ));
+
+ v.clear ();
+ boost::algorithm::iota_n ( std::back_inserter(v), 99, 20 );
+ BOOST_CHECK ( test_iota_results ( v, 99 ));
+
+/*
+ l.clear (); l.reserve ( 5 );
+ boost::algorithm::iota ( l.begin (), l.end (), 123 );
+ BOOST_CHECK ( test_iota_results ( l.begin (), l.end (), 123 ));
+
+ l.clear (); l.reserve ( 9 );
+ boost::algorithm::iota ( l.begin (), l.end (), 87 );
+ BOOST_CHECK ( test_iota_results ( l.begin (), l.end (), 87 ));
+*/
+
+ l.clear ();
+ boost::algorithm::iota_n ( std::back_inserter(l), 99, 20 );
+ BOOST_CHECK ( test_iota_results ( l, 99 ));
+
+ l.clear ();
+ boost::algorithm::iota_n ( std::front_inserter(l), 123, 20 );
+ BOOST_CHECK ( test_iota_results ( l.rbegin (), l.rend (), 123 ));
+ }
+
+
+BOOST_AUTO_TEST_CASE( test_main )
+{
+ test_ints ();
+}