|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r59253 - in sandbox: boost/algorithm libs/algorithm/creasing libs/algorithm/creasing/example libs/algorithm/creasing/test
From: gerickson_at_[hidden]
Date: 2010-01-24 11:42:03
Author: gerickson
Date: 2010-01-24 11:42:02 EST (Sun, 24 Jan 2010)
New Revision: 59253
URL: http://svn.boost.org/trac/boost/changeset/59253
Log:
Initial revision.
Added:
sandbox/boost/algorithm/creasing.hpp (contents, props changed)
sandbox/libs/algorithm/creasing/
sandbox/libs/algorithm/creasing/example/
sandbox/libs/algorithm/creasing/example/Jamfile (contents, props changed)
sandbox/libs/algorithm/creasing/example/creasing_ex.cpp (contents, props changed)
sandbox/libs/algorithm/creasing/test/
sandbox/libs/algorithm/creasing/test/Jamfile.v2 (contents, props changed)
sandbox/libs/algorithm/creasing/test/creasing_test.cpp (contents, props changed)
Added: sandbox/boost/algorithm/creasing.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/algorithm/creasing.hpp 2010-01-24 11:42:02 EST (Sun, 24 Jan 2010)
@@ -0,0 +1,94 @@
+// Boost creasing.hpp header file -----------------------------------------//
+
+// Copyright (c) 2010 Nuovation System Designs, LLC
+// Grant Erickson <gerickson_at_[hidden]>
+//
+// 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)
+//
+// See http://www.boost.org/ for latest version.
+//
+// Description:
+// A set of four algorithms for inquiring about the properties of
+// sequences, including:
+//
+// - Increasing
+// - Decreasing
+// - Strictly Increasing
+// - Strictly Decreasing
+
+#ifndef BOOST_ALGORITHM_CREASING_HPP
+#define BOOST_ALGORITHM_CREASING_HPP
+
+#include <algorithm>
+#include <functional>
+#include <iterator>
+
+namespace boost {
+
+ namespace detail {
+
+ template <typename ForwardIterator, typename BinaryPredicate>
+ bool
+ is_creasing(ForwardIterator first, ForwardIterator last,
+ BinaryPredicate binary_pred)
+ {
+ return std::adjacent_find(first,
+ last,
+ std::not2(binary_pred)) == last;
+ }
+
+ } // namespace detail
+
+ template <typename ForwardIterator>
+ bool
+ is_increasing(ForwardIterator first, ForwardIterator last)
+ {
+ typedef typename std::iterator_traits<ForwardIterator>::value_type
+ value_type;
+
+ return detail::is_creasing(first,
+ last,
+ std::less_equal<value_type>());
+ }
+
+ template <typename ForwardIterator>
+ bool
+ is_decreasing(ForwardIterator first, ForwardIterator last)
+ {
+ typedef typename std::iterator_traits<ForwardIterator>::value_type
+ value_type;
+
+ return detail::is_creasing(first,
+ last,
+ std::greater_equal<value_type>());
+ }
+
+ template <typename ForwardIterator>
+ bool
+ is_strictly_increasing(ForwardIterator first, ForwardIterator last)
+ {
+ typedef typename std::iterator_traits<ForwardIterator>::value_type
+ value_type;
+
+ return detail::is_creasing(first,
+ last,
+ std::less<value_type>());
+ }
+
+ template <typename ForwardIterator>
+ bool
+ is_strictly_decreasing(ForwardIterator first, ForwardIterator last)
+ {
+ typedef typename std::iterator_traits<ForwardIterator>::value_type
+ value_type;
+
+ return detail::is_creasing(first,
+ last,
+ std::greater<value_type>());
+ }
+
+} // namespace boost
+
+#endif // BOOST_ALGORITHM_CREASING_HPP
Added: sandbox/libs/algorithm/creasing/example/Jamfile
==============================================================================
--- (empty file)
+++ sandbox/libs/algorithm/creasing/example/Jamfile 2010-01-24 11:42:02 EST (Sun, 24 Jan 2010)
@@ -0,0 +1,11 @@
+# Boost.Creasing Library test Jamfile
+#
+# Copyright (c) 2010 Nuovation System Designs, LLC
+# Grant Erickson <gerickson_at_[hidden]>
+#
+# 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)
+
+exe creasing_ex : creasing_ex.cpp ;
+
Added: sandbox/libs/algorithm/creasing/example/creasing_ex.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/algorithm/creasing/example/creasing_ex.cpp 2010-01-24 11:42:02 EST (Sun, 24 Jan 2010)
@@ -0,0 +1,69 @@
+// Copyright (c) 2010 Nuovation System Designs, LLC
+// Grant Erickson <gerickson_at_[hidden]>
+//
+// 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)
+//
+// See http://www.boost.org/ for latest version.
+
+#include <algorithm>
+#include <iostream>
+
+#include <boost/algorithm/creasing.hpp>
+#include <boost/lambda/lambda.hpp>
+
+/* Preprocessor Defines */
+
+#define elementsof(v) (sizeof (v) / sizeof (v[0]))
+#define begin(v) (v)
+#define end(v) (v + elementsof (v))
+
+static void
+output_sequence_property(bool result, const char * property)
+{
+ std::cout << " "
+ << ((result) ? "Is " : "Is not ")
+ << property
+ << std::endl;
+}
+
+template <typename InputIterator>
+static void
+analyze_sequence(InputIterator first, InputIterator last)
+{
+ bool is_increasing;
+ bool is_decreasing;
+ bool is_strictly_increasing;
+ bool is_strictly_decreasing;
+
+ using namespace std;
+ using namespace boost::lambda;
+
+ is_increasing = boost::is_increasing(first, last);
+ is_decreasing = boost::is_decreasing(first, last);
+ is_strictly_increasing = boost::is_strictly_increasing(first, last);
+ is_strictly_decreasing = boost::is_strictly_decreasing(first, last);
+
+ cout << "The sequence { ";
+ for_each(first, last, cout << _1 << ' ');
+ cout << " }..." << endl;
+
+ output_sequence_property(is_increasing, "increasing");
+ output_sequence_property(is_strictly_increasing, "strictly increasing");
+ output_sequence_property(is_decreasing, "decreasing");
+ output_sequence_property(is_strictly_decreasing, "strictly decreasing");
+}
+
+int main(void)
+{
+ const int sequence1[] = { 1, 2, 3, 4, 5 };
+ const int sequence2[] = { 7, 7, 7, 7, 7 };
+ const float sequence3[] = { 7.618, 4.971, 6.126, 1.727, 6.510 };
+
+ analyze_sequence(begin(sequence1), end(sequence1));
+ analyze_sequence(begin(sequence2), end(sequence2));
+ analyze_sequence(begin(sequence3), end(sequence3));
+
+ return 0;
+}
Added: sandbox/libs/algorithm/creasing/test/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/libs/algorithm/creasing/test/Jamfile.v2 2010-01-24 11:42:02 EST (Sun, 24 Jan 2010)
@@ -0,0 +1,18 @@
+# Boost.Creasing Library test Jamfile
+#
+# Copyright (c) 2010 Nuovation System Designs, LLC
+# Grant Erickson <gerickson_at_[hidden]>
+#
+# 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)
+
+import testing ;
+
+{
+ test-suite algorithm/creasing:
+ : [ run creasing_test.cpp
+ : : : : creasing ]
+ ;
+}
+
Added: sandbox/libs/algorithm/creasing/test/creasing_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/algorithm/creasing/test/creasing_test.cpp 2010-01-24 11:42:02 EST (Sun, 24 Jan 2010)
@@ -0,0 +1,165 @@
+// Copyright (c) 2010 Nuovation System Designs, LLC
+// Grant Erickson <gerickson_at_[hidden]>
+//
+// 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)
+//
+// See http://www.boost.org/ for latest version.
+
+#include <algorithm>
+#include <iostream>
+
+#include <boost/algorithm/creasing.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/test/unit_test.hpp>
+
+using namespace boost;
+
+/* Preprocessor Defines */
+
+#define elementsof(v) (sizeof (v) / sizeof (v[0]))
+#define begin(v) (v)
+#define end(v) (v + elementsof (v))
+
+template <typename InputIterator, typename Function>
+static bool
+test_sequence(InputIterator inBegin,
+ InputIterator inEnd,
+ Function inFunction)
+{
+ return (inFunction(inBegin, inEnd));
+}
+
+static void
+test_creasing(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 };
+ bool result;
+
+ // Test a strictly increasing sequence
+
+ result = test_sequence(begin(strictlyIncreasingValues),
+ end(strictlyIncreasingValues),
+ is_strictly_increasing<int const *>);
+ BOOST_CHECK_EQUAL(result, true);
+ result = test_sequence(begin(strictlyIncreasingValues),
+ end(strictlyIncreasingValues),
+ is_increasing<int const *>);
+ BOOST_CHECK_EQUAL(result, true);
+ result = test_sequence(begin(strictlyIncreasingValues),
+ end(strictlyIncreasingValues),
+ is_strictly_decreasing<int const *>);
+ BOOST_CHECK_EQUAL(result, false);
+ result = test_sequence(begin(strictlyIncreasingValues),
+ end(strictlyIncreasingValues),
+ is_decreasing<int const *>);
+ BOOST_CHECK_EQUAL(result, false);
+
+ // Test a strictly decreasing sequence
+
+ result = test_sequence(begin(strictlyDecreasingValues),
+ end(strictlyDecreasingValues),
+ is_strictly_increasing<int const *>);
+ BOOST_CHECK_EQUAL(result, false);
+ result = test_sequence(begin(strictlyDecreasingValues),
+ end(strictlyDecreasingValues),
+ is_increasing<int const *>);
+ BOOST_CHECK_EQUAL(result, false);
+ result = test_sequence(begin(strictlyDecreasingValues),
+ end(strictlyDecreasingValues),
+ is_strictly_decreasing<int const *>);
+ BOOST_CHECK_EQUAL(result, true);
+ result = test_sequence(begin(strictlyDecreasingValues),
+ end(strictlyDecreasingValues),
+ is_decreasing<int const *>);
+ BOOST_CHECK_EQUAL(result, true);
+
+ // Test an increasing sequence
+
+ result = test_sequence(begin(increasingValues),
+ end(increasingValues),
+ is_strictly_increasing<int const *>);
+ BOOST_CHECK_EQUAL(result, false);
+ result = test_sequence(begin(increasingValues),
+ end(increasingValues),
+ is_increasing<int const *>);
+ BOOST_CHECK_EQUAL(result, true);
+ result = test_sequence(begin(increasingValues),
+ end(increasingValues),
+ is_strictly_decreasing<int const *>);
+ BOOST_CHECK_EQUAL(result, false);
+ result = test_sequence(begin(increasingValues),
+ end(increasingValues),
+ is_decreasing<int const *>);
+ BOOST_CHECK_EQUAL(result, false);
+
+ // Test a decreasing sequence
+
+ result = test_sequence(begin(decreasingValues),
+ end(decreasingValues),
+ is_strictly_increasing<int const *>);
+ BOOST_CHECK_EQUAL(result, false);
+ result = test_sequence(begin(decreasingValues),
+ end(decreasingValues),
+ is_increasing<int const *>);
+ BOOST_CHECK_EQUAL(result, false);
+ result = test_sequence(begin(decreasingValues),
+ end(decreasingValues),
+ is_strictly_decreasing<int const *>);
+ BOOST_CHECK_EQUAL(result, false);
+ result = test_sequence(begin(decreasingValues),
+ end(decreasingValues),
+ is_decreasing<int const *>);
+ BOOST_CHECK_EQUAL(result, true);
+
+ // Test a random sequence
+
+ result = test_sequence(begin(randomValues),
+ end(randomValues),
+ is_strictly_increasing<int const *>);
+ BOOST_CHECK_EQUAL(result, false);
+ result = test_sequence(begin(randomValues),
+ end(randomValues),
+ is_increasing<int const *>);
+ BOOST_CHECK_EQUAL(result, false);
+ result = test_sequence(begin(randomValues),
+ end(randomValues),
+ is_strictly_decreasing<int const *>);
+ BOOST_CHECK_EQUAL(result, false);
+ result = test_sequence(begin(randomValues),
+ end(randomValues),
+ is_decreasing<int const *>);
+ BOOST_CHECK_EQUAL(result, false);
+
+ // Test a constant sequence
+
+ result = test_sequence(begin(constantValues),
+ end(constantValues),
+ is_strictly_increasing<int const *>);
+ BOOST_CHECK_EQUAL(result, false);
+ result = test_sequence(begin(constantValues),
+ end(constantValues),
+ is_increasing<int const *>);
+ BOOST_CHECK_EQUAL(result, true);
+ result = test_sequence(begin(constantValues),
+ end(constantValues),
+ is_strictly_decreasing<int const *>);
+ BOOST_CHECK_EQUAL(result, false);
+ result = test_sequence(begin(constantValues),
+ end(constantValues),
+ is_decreasing<int const *>);
+ BOOST_CHECK_EQUAL(result, true);
+}
+
+int test_main( int, char * [] )
+{
+ test_creasing();
+
+ 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