|
Boost-Commit : |
From: philgarofalo_at_[hidden]
Date: 2008-01-12 14:47:23
Author: pgarofalo
Date: 2008-01-12 14:47:22 EST (Sat, 12 Jan 2008)
New Revision: 42703
URL: http://svn.boost.org/trac/boost/changeset/42703
Log:
Updated the example and test applications. They now properly refer to the new combinatorial function names and the minimal Boost test library.
Text files modified:
sandbox/libs/sequence_algo/test/test_combinatorial.cpp | 385 +++++++++++++++++++--------------------
1 files changed, 185 insertions(+), 200 deletions(-)
Modified: sandbox/libs/sequence_algo/test/test_combinatorial.cpp
==============================================================================
--- sandbox/libs/sequence_algo/test/test_combinatorial.cpp (original)
+++ sandbox/libs/sequence_algo/test/test_combinatorial.cpp 2008-01-12 14:47:22 EST (Sat, 12 Jan 2008)
@@ -2,7 +2,7 @@
// Test program for r-permutation and r-combination generic functions
// in rcombo.h.
-// Copyright © Philip F. Garofalo 2002. All rights reserved.
+// Copyright © Philip F. Garofalo 2008. All rights reserved.
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
@@ -37,14 +37,9 @@
#include <functional> // greater<>
#include <stdexcept>
#include <cstring> // strncmp
-using namespace std;
-
-#ifdef __MWERKS__
-#include <console.h>
-#endif
//#define BOOST_INCLUDE_MAIN
-#include <boost/test/test_tools.hpp>
+#include <boost/test/minimal.hpp>
#include <boost/lexical_cast.hpp>
#include "combinatorial.hpp"
@@ -54,13 +49,6 @@
#define DIM(a) (sizeof(a)/sizeof(a)[0])
-// externals
-
-namespace boost {
- namespace test {
- extern int test_tools_errors; // defined in test_main.cpp
- }
-}
// Test data ---------------------------------------->>
@@ -72,11 +60,11 @@
// partial template specialization, so we'll need to explicitly specialize
// iterator_traits for the container type, which is char* in this test app.
// It is required only before the call to the default version of
-// prev_r_permutation,the one without the user-supplied compare function.
+// prev_partial_permutation,the one without the user-supplied compare function.
//
namespace std {
template<>
- struct iterator_traits<char*> {
+ struct detail::iterator_traits<char*> {
typedef random_access_iterator_tag iterator_category;
typedef ptrdiff_t difference_type;
typedef char value_type;
@@ -125,21 +113,22 @@
template<class InputIterator>
void format_sequence(InputIterator first, InputIterator middle,
- InputIterator last, ostream& os = cout)
+ InputIterator last, std::ostream& os = std::cout)
{
//typedef typename iterator_traits<InputIterator>::value_type T; // not compiling
- copy(first, middle, ostream_iterator<char>(os, " ")); // <char> was <T>
+ std::copy(first, middle, std::ostream_iterator<char>(os, " ")); // <char> was <T>
os << "| ";
- copy(middle, last, ostream_iterator<char>(os, " "));
+ std::copy(middle, last, std::ostream_iterator<char>(os, " "));
} // format_sequence
// invalid_combination_msg ----------------------------------------------//
template<class T>
-string invalid_sequence_msg(const string& seq_type, unsigned n, const T& seq, int r)
+std::string invalid_sequence_msg(const std::string& seq_type, unsigned n,
+ const T& seq, int r)
{
- ostringstream msg;
+ std::ostringstream msg;
msg << "Invalid " << seq_type << " #" << n << " of P(" << seq.size()
<< ", " << r << "): ";
format_sequence(seq.begin(), seq.begin() + r, seq.end(), msg);
@@ -149,7 +138,7 @@
// invalid_combination_msg ----------------------------------------------//
template<class T>
-inline string invalid_combination_msg(unsigned n, const T& seq, int r)
+inline std::string invalid_combination_msg(unsigned n, const T& seq, int r)
{
return invalid_sequence_msg("combination", n, seq, r);
} // invalid_combination_msg
@@ -157,90 +146,90 @@
// invalid_permutation_msg ----------------------------------------------//
template<class T>
-inline string invalid_permutation_msg(unsigned n, const T& seq, int r)
+inline std::string invalid_permutation_msg(unsigned n, const T& seq, int r)
{
return invalid_sequence_msg("permutation", n, seq, r);
}
-// valid_next_r_permutation --------------------------------------------------//
+// valid_next_partial_permutation --------------------------------------------------//
template<class ForwardIterator>
-bool valid_next_r_permutation(ForwardIterator first,
+bool valid_next_partial_permutation(ForwardIterator first,
ForwardIterator middle,
bool fresh_start)
{
- typedef typename iterator_traits<ForwardIterator>::value_type T;
- static vector<T> prev;
+ typedef typename detail::iterator_traits<ForwardIterator>::value_type T;
+ static std::vector<T> prev;
bool retval = true;
if (!fresh_start && first != middle) // test to ensure this sequence is greater than previous
retval = lexicographical_compare(prev.begin(), prev.end(), first, middle);
- prev = vector<T>(first, middle);
+ prev = std::vector<T>(first, middle);
return retval;
-} // valid_next_r_permutation
+} // valid_next_partial_permutation
-// valid_next_r_permutation ---------------------------------------------//
+// valid_next_partial_permutation ---------------------------------------------//
template<class ForwardIterator, class Compare>
-bool valid_next_r_permutation(ForwardIterator first,
+bool valid_next_partial_permutation(ForwardIterator first,
ForwardIterator middle,
Compare comp,
bool fresh_start)
{
- typedef typename iterator_traits<ForwardIterator>::value_type T;
- static vector<T> prev;
+ typedef typename detail::iterator_traits<ForwardIterator>::value_type T;
+ static std::vector<T> prev;
bool retval = true;
if (!fresh_start && first != middle) // test to ensure this sequence is greater than previous
retval = lexicographical_compare(prev.begin(), prev.end(), first, middle, comp);
- prev = vector<T>(first, middle);
+ prev = std::vector<T>(first, middle);
return retval;
-} // valid_next_r_permutation
+} // valid_next_partial_permutation
-// valid_prev_r_permutation ---------------------------------------------//
+// valid_prev_partial_permutation ---------------------------------------------//
template<class ForwardIterator>
-bool valid_prev_r_permutation(ForwardIterator first,
+bool valid_prev_partial_permutation(ForwardIterator first,
ForwardIterator middle,
bool fresh_start)
{
- typedef typename iterator_traits<ForwardIterator>::value_type T;
- static vector<T> prev;
+ typedef typename detail::iterator_traits<ForwardIterator>::value_type T;
+ static std::vector<T> prev;
bool retval = true;
if (!fresh_start && first != middle) // test to ensure this sequence is greater than previous
retval = lexicographical_compare(first, middle, prev.begin(), prev.end());
- prev = vector<T>(first, middle);
+ prev = std::vector<T>(first, middle);
return retval;
-} // valid_prev_r_permutation
+} // valid_prev_partial_permutation
-// valid_prev_r_permutation ---------------------------------------------//
+// valid_prev_partial_permutation ---------------------------------------------//
template<class ForwardIterator, class Compare>
-bool valid_prev_r_permutation(ForwardIterator first,
+bool valid_prev_partial_permutation(ForwardIterator first,
ForwardIterator middle,
Compare comp,
bool fresh_start)
{
- typedef typename iterator_traits<ForwardIterator>::value_type T;
- static vector<T> prev;
+ typedef typename detail::iterator_traits<ForwardIterator>::value_type T;
+ static std::vector<T> prev;
bool retval = true;
if (!fresh_start && first != middle) // test to ensure this sequence is greater than previous
retval = lexicographical_compare(first, middle, prev.begin(), prev.end(), comp);
- prev = vector<T>(first, middle);
+ prev = std::vector<T>(first, middle);
return retval;
-} // valid_prev_r_permutation
+} // valid_prev_partial_permutation
-// valid_r_combination --------------------------------------------------//
+// valid_partial_combination --------------------------------------------------//
template<class ForwardIterator>
-bool valid_next_r_combination(ForwardIterator first,
+bool valid_next_partial_combination(ForwardIterator first,
ForwardIterator middle,
bool fresh_start)
{
@@ -248,22 +237,22 @@
return false;
// and greater than the last one
- typedef typename iterator_traits<ForwardIterator>::value_type T;
- static vector<T> prev;
+ typedef typename detail::iterator_traits<ForwardIterator>::value_type T;
+ static std::vector<T> prev;
bool retval = true;
if (!fresh_start && first != middle) // test to ensure this sequence is greater than last
retval = lexicographical_compare(prev.begin(), prev.end(), first, middle);
- prev = vector<T>(first, middle);
+ prev = std::vector<T>(first, middle);
return retval;
-} // valid_next_r_combination
+} // valid_next_partial_combination
-// valid_prev_r_combination ---------------------------------------------//
+// valid_prev_partial_combination ---------------------------------------------//
template<class ForwardIterator>
-bool valid_prev_r_combination(ForwardIterator first,
+bool valid_prev_partial_combination(ForwardIterator first,
ForwardIterator middle,
bool fresh_start)
{
@@ -271,22 +260,22 @@
return false;
// and less than the last one
- typedef typename iterator_traits<ForwardIterator>::value_type T;
- static vector<T> prev;
+ typedef typename detail::iterator_traits<ForwardIterator>::value_type T;
+ static std::vector<T> prev;
bool retval = true;
if (!fresh_start && first != middle) // test to ensure this sequence is less than last
retval = lexicographical_compare(first, middle, prev.begin(), prev.end());
- prev = vector<T>(first, middle);
+ prev = std::vector<T>(first, middle);
return retval;
-} // valid_prev_r_combination
+} // valid_prev_partial_combination
-// valid_next_r_combination ---------------------------------------------//
+// valid_next_partial_combination ---------------------------------------------//
template<class ForwardIterator, class Compare>
-bool valid_next_r_combination(ForwardIterator first,
+bool valid_next_partial_combination(ForwardIterator first,
ForwardIterator middle,
Compare comp,
bool fresh_start)
@@ -294,21 +283,21 @@
if (!is_sorted(first, middle, comp))
return false;
- typedef typename iterator_traits<ForwardIterator>::value_type T;
- static vector<T> prev;
+ typedef typename detail::iterator_traits<ForwardIterator>::value_type T;
+ static std::vector<T> prev;
bool retval = true;
if (!fresh_start && first != middle) // test to ensure this sequence is greater than last
retval = lexicographical_compare(prev.begin(), prev.end(), first, middle, comp);
- prev = vector<T>(first, middle);
+ prev = std::vector<T>(first, middle);
return retval;
-} // valid_next_r_combination
+} // valid_next_partial_combination
-// valid_prev_r_combination ---------------------------------------------//
+// valid_prev_partial_combination ---------------------------------------------//
template<class ForwardIterator, class Compare>
-bool valid_prev_r_combination(ForwardIterator first,
+bool valid_prev_partial_combination(ForwardIterator first,
ForwardIterator middle,
Compare comp,
bool fresh_start)
@@ -316,36 +305,36 @@
if (!is_sorted(first, middle, comp))
return false;
- typedef typename iterator_traits<ForwardIterator>::value_type T;
- static vector<T> prev;
+ typedef typename detail::iterator_traits<ForwardIterator>::value_type T;
+ static std::vector<T> prev;
bool retval = true;
if (!fresh_start && first != middle) // test to ensure this sequence is less than last
retval = lexicographical_compare(first, middle, prev.begin(), prev.end(), comp);
- prev = vector<T>(first, middle);
+ prev = std::vector<T>(first, middle);
return retval;
-} // valid_prev_r_combination
+} // valid_prev_partial_combination
// test_factorial -------------------------------------------------------//
void test_factorial()
{
- BOOST_CRITICAL_TEST(factorial(0) == 1);
- BOOST_CRITICAL_TEST(factorial(1) == 1);
- BOOST_CRITICAL_TEST(factorial(5) == 120);
- BOOST_CRITICAL_TEST(factorial(6) == 720);
- BOOST_CRITICAL_TEST(factorial(11) == 39916800UL);
-
- BOOST_CRITICAL_TEST(factorial(0, 0) == 1);
- BOOST_CRITICAL_TEST(factorial(1, 1) == 1);
- BOOST_CRITICAL_TEST(factorial(2, 1) == 2);
- BOOST_CRITICAL_TEST(factorial(2, 2) == 2);
- BOOST_CRITICAL_TEST(factorial(5, 3) == 60);
- BOOST_CRITICAL_TEST(factorial(6, 4) == 360);
- BOOST_CRITICAL_TEST(factorial(7, 0) == 1);
- BOOST_CRITICAL_TEST(factorial(7, 2) == 42);
- BOOST_CRITICAL_TEST(factorial(7, 7) == 5040);
+ BOOST_REQUIRE(factorial(0) == 1);
+ BOOST_REQUIRE(factorial(1) == 1);
+ BOOST_REQUIRE(factorial(5) == 120);
+ BOOST_REQUIRE(factorial(6) == 720);
+ BOOST_REQUIRE(factorial(11) == 39916800UL);
+
+ BOOST_REQUIRE(factorial(0, 0) == 1);
+ BOOST_REQUIRE(factorial(1, 1) == 1);
+ BOOST_REQUIRE(factorial(2, 1) == 2);
+ BOOST_REQUIRE(factorial(2, 2) == 2);
+ BOOST_REQUIRE(factorial(5, 3) == 60);
+ BOOST_REQUIRE(factorial(6, 4) == 360);
+ BOOST_REQUIRE(factorial(7, 0) == 1);
+ BOOST_REQUIRE(factorial(7, 2) == 42);
+ BOOST_REQUIRE(factorial(7, 7) == 5040);
} // test_factorial
@@ -360,22 +349,22 @@
// expected number.
// 3. The last sequence is equal to the first.
-// test_next_r_permutation ----------------------------------------------//
+// test_next_partial_permutation ----------------------------------------------//
template<class T>
-void test_next_r_permutation(T& seq, int r)
+void test_next_partial_permutation(T& seq, int r)
{
- partial_sort(seq.begin(), seq.begin() + r, seq.end());
+ std::partial_sort(seq.begin(), seq.begin() + r, seq.end());
T checkseq = seq;
unsigned count = 0;
try {
do {
++count;
- if (!valid_next_r_permutation(seq.begin(), seq.begin() + r, count == 1))
+ if (!valid_next_partial_permutation(seq.begin(), seq.begin() + r, count == 1))
{
BOOST_ERROR(invalid_permutation_msg(count, seq, r).c_str());
}
- } while(next_r_permutation(seq.begin(), seq.begin() + r, seq.end()));
+ } while(next_partial_permutation(seq.begin(), seq.begin() + r, seq.end()));
}
catch(const combinatorial_range_error& oops)
{
@@ -386,8 +375,8 @@
const unsigned long perm_cnt = factorial(seq.size(), r);
if (count != perm_cnt)
{
- ostringstream msg;
- msg << "next_r_permutation generated "<< count
+ std::ostringstream msg;
+ msg << "next_partial_permutation generated "<< count
<< " permutations when there should have been "
<< perm_cnt << '\n';
BOOST_ERROR(msg.str().c_str());
@@ -395,33 +384,33 @@
if (!equal(seq.begin(), seq.begin() + r, checkseq.begin()))
{
- BOOST_ERROR("next_r_permutation didn't restore sequence to initial value at end of series.");
+ BOOST_ERROR("next_partial_permutation didn't restore sequence to initial value at end of series.");
format_sequence(seq.begin(), seq.begin() + r, seq.end());
- cout << '\n';
+ std::cout << '\n';
format_sequence(checkseq.begin(), checkseq.begin() + r, checkseq.end());
- cout << '\n';
+ std::cout << '\n';
}
-} // test_next_r_permutation
+} // test_next_partial_permutation
-// test_next_r_permutation_comp -----------------------------------------//
+// test_next_partial_permutation_comp -----------------------------------------//
template<class T>
-void test_next_r_permutation_comp(T& seq, int r)
+void test_next_partial_permutation_comp(T& seq, int r)
{
typedef typename T::value_type U;
- partial_sort(seq.begin(), seq.begin() + r, seq.end(), greater<U>());
+ std::partial_sort(seq.begin(), seq.begin() + r, seq.end(), std::greater<U>());
T checkseq = seq;
unsigned count = 0;
try {
do {
++count;
- if (!valid_next_r_permutation(seq.begin(), seq.begin() + r,
- greater<U>(), count == 1))
+ if (!valid_next_partial_permutation(seq.begin(), seq.begin() + r,
+ std::greater<U>(), count == 1))
{
BOOST_ERROR(invalid_permutation_msg(count, seq, r).c_str());
}
- } while(next_r_permutation(seq.begin(), seq.begin() + r, seq.end(),
- greater<U>()));
+ } while(next_partial_permutation(seq.begin(), seq.begin() + r, seq.end(),
+ std::greater<U>()));
} // try
catch(const combinatorial_range_error& oops)
{
@@ -432,8 +421,8 @@
const unsigned long perm_cnt = factorial(seq.size(), r);
if (count != perm_cnt)
{
- ostringstream msg;
- msg << "next_r_permutation generated "<< count
+ std::ostringstream msg;
+ msg << "next_partial_permutation generated "<< count
<< " permutations when there should have been "
<< perm_cnt << '\n';
BOOST_ERROR(msg.str().c_str());
@@ -441,31 +430,31 @@
if (!equal(seq.begin(), seq.begin() + r, checkseq.begin()))
{
- BOOST_ERROR("next_r_permutation didn't restore sequence to initial value at end of series.");
+ BOOST_ERROR("next_partial_permutation didn't restore sequence to initial value at end of series.");
format_sequence(seq.begin(), seq.begin() + r, seq.end());
- cout << '\n';
+ std::cout << '\n';
format_sequence(checkseq.begin(), checkseq.begin() + r, checkseq.end());
- cout << '\n';
+ std::cout << '\n';
}
-} // test_next_r_permutation_comp
+} // test_next_partial_permutation_comp
-// test_prev_r_permutation ----------------------------------------------//
+// test_prev_partial_permutation ----------------------------------------------//
template<class T>
-void test_prev_r_permutation(T& seq, int r)
+void test_prev_partial_permutation(T& seq, int r)
{
typedef typename T::value_type U;
- partial_sort(seq.begin(), seq.begin() + r, seq.end(), greater<U>());
+ std::partial_sort(seq.begin(), seq.begin() + r, seq.end(), std::greater<U>());
T checkseq = seq;
unsigned count = 0;
try {
do {
++count;
- if (!valid_prev_r_permutation(seq.begin(), seq.begin() + r, count == 1))
+ if (!valid_prev_partial_permutation(seq.begin(), seq.begin() + r, count == 1))
{
BOOST_ERROR(invalid_permutation_msg(count, seq, r).c_str());
}
- } while(prev_r_permutation(seq.begin(), seq.begin() + r, seq.end()));
+ } while(prev_partial_permutation(seq.begin(), seq.begin() + r, seq.end()));
} // try
catch(const combinatorial_range_error& oops)
{
@@ -476,8 +465,8 @@
const unsigned long perm_cnt = factorial(seq.size(), r);
if (count != perm_cnt)
{
- ostringstream msg;
- msg << "prev_r_permutation generated "<< count
+ std::ostringstream msg;
+ msg << "prev_partial_permutation generated "<< count
<< " permutations when there should have been "
<< perm_cnt << '\n';
BOOST_ERROR(msg.str().c_str());
@@ -485,33 +474,33 @@
if (!equal(seq.begin(), seq.begin() + r, checkseq.begin()))
{
- BOOST_ERROR("prev_r_permutation didn't restore sequence to initial value at end of series.");
+ BOOST_ERROR("prev_partial_permutation didn't restore sequence to initial value at end of series.");
format_sequence(seq.begin(), seq.begin() + r, seq.end());
- cout << '\n';
+ std::cout << '\n';
format_sequence(checkseq.begin(), checkseq.begin() + r, checkseq.end());
- cout << '\n';
+ std::cout << '\n';
}
-} // test_prev_r_permutation
+} // test_prev_partial_permutation
-// test_prev_r_permutation_comp -------------------------------------------//
+// test_prev_partial_permutation_comp -------------------------------------------//
template<class T>
-void test_prev_r_permutation_comp(T& seq, int r)
+void test_prev_partial_permutation_comp(T& seq, int r)
{
typedef typename T::value_type U;
- partial_sort(seq.begin(), seq.begin() + r, seq.end());
+ std::partial_sort(seq.begin(), seq.begin() + r, seq.end());
T checkseq = seq;
unsigned count = 0;
try {
do {
++count;
- if (!valid_prev_r_permutation(seq.begin(), seq.begin() + r,
- greater<U>(), count == 1))
+ if (!valid_prev_partial_permutation(seq.begin(), seq.begin() + r,
+ std::greater<U>(), count == 1))
{
BOOST_ERROR(invalid_permutation_msg(count, seq, r).c_str());
}
- } while(prev_r_permutation(seq.begin(), seq.begin() + r, seq.end(),
- greater<U>()));
+ } while(prev_partial_permutation(seq.begin(), seq.begin() + r, seq.end(),
+ std::greater<U>()));
} // try
catch(const combinatorial_range_error& oops)
{
@@ -522,8 +511,8 @@
const unsigned long perm_cnt = factorial(seq.size(), r);
if (count != perm_cnt)
{
- ostringstream msg;
- msg << "prev_r_permutation generated "<< count
+ std::ostringstream msg;
+ msg << "prev_partial_permutation generated "<< count
<< " permutations when there should have been "
<< perm_cnt << '\n';
BOOST_ERROR(msg.str().c_str());
@@ -531,28 +520,28 @@
if (!equal(seq.begin(), seq.begin() + r, checkseq.begin()))
{
- BOOST_ERROR("prev_r_permutation didn't restore sequence to initial value at end of series.");
+ BOOST_ERROR("prev_partial_permutation didn't restore sequence to initial value at end of series.");
format_sequence(seq.begin(), seq.begin() + r, seq.end());
- cout << '\n';
+ std::cout << '\n';
format_sequence(checkseq.begin(), checkseq.begin() + r, checkseq.end());
- cout << '\n';
+ std::cout << '\n';
}
-} // test_prev_r_permutation_comp
+} // test_prev_partial_permutation_comp
-// test_next_r_combination ----------------------------------------------//
+// test_next_partial_combination ----------------------------------------------//
template<class T>
-void test_next_r_combination(T& seq, int r)
+void test_next_partial_combination(T& seq, int r)
{
- partial_sort(seq.begin(), seq.begin() + r, seq.end());
+ std::partial_sort(seq.begin(), seq.begin() + r, seq.end());
T checkseq = seq;
unsigned count = 0;
try {
do {
++count;
- if (!valid_next_r_combination(seq.begin(), seq.begin() + r, count == 1))
+ if (!valid_next_partial_combination(seq.begin(), seq.begin() + r, count == 1))
BOOST_ERROR(invalid_combination_msg(count, seq, r).c_str());
- } while(next_r_combination(seq.begin(), seq.begin() + r, seq.end()));
+ } while(next_partial_combination(seq.begin(), seq.begin() + r, seq.end()));
} // try
catch(const combinatorial_range_error& oops)
{
@@ -570,8 +559,8 @@
const unsigned long comb_cnt = factorial(seq.size(), r) / factorial(r);
if (count != comb_cnt)
{
- ostringstream msg;
- msg << "next_r_combination generated "<< count
+ std::ostringstream msg;
+ msg << "next_partial_combination generated "<< count
<< " combinations when there should have been "
<< comb_cnt << '\n';
BOOST_ERROR(msg.str().c_str());
@@ -579,31 +568,31 @@
if (!equal(seq.begin(), seq.begin() + r, checkseq.begin()))
{
- BOOST_ERROR("next_r_permutation didn't restore sequence to initial value at end of series.");
+ BOOST_ERROR("next_partial_permutation didn't restore sequence to initial value at end of series.");
format_sequence(seq.begin(), seq.begin() + r, seq.end());
- cout << '\n';
+ std::cout << '\n';
format_sequence(checkseq.begin(), checkseq.begin() + r, checkseq.end());
- cout << '\n';
+ std::cout << '\n';
}
-} // test_next_r_combination
+} // test_next_partial_combination
-// test_next_r_combination_comp -----------------------------------------//
+// test_next_partial_combination_comp -----------------------------------------//
template<class T>
-void test_next_r_combination_comp(T& seq, int r)
+void test_next_partial_combination_comp(T& seq, int r)
{
typedef typename T::value_type U;
- partial_sort(seq.begin(), seq.begin() + r, seq.end(), greater<U>());
+ std::partial_sort(seq.begin(), seq.begin() + r, seq.end(), std::greater<U>());
T checkseq = seq;
unsigned count = 0;
try {
do {
++count;
- if (!valid_next_r_combination(seq.begin(), seq.begin() + r,
- greater<U>(), count == 1))
+ if (!valid_next_partial_combination(seq.begin(), seq.begin() + r,
+ std::greater<U>(), count == 1))
BOOST_ERROR(invalid_combination_msg(count, seq, r).c_str());
- } while(next_r_combination(seq.begin(), seq.begin() + r, seq.end(),
- greater<U>()));
+ } while(next_partial_combination(seq.begin(), seq.begin() + r, seq.end(),
+ std::greater<U>()));
} // try
catch(const combinatorial_range_error& oops)
{
@@ -619,8 +608,8 @@
const unsigned long comb_cnt = factorial(seq.size(), r) / factorial(r);
if (count != comb_cnt)
{
- ostringstream msg;
- msg << "next_r_combination generated "<< count
+ std::ostringstream msg;
+ msg << "next_partial_combination generated "<< count
<< " combinations when there should have been "
<< comb_cnt << '\n';
BOOST_ERROR(msg.str().c_str());
@@ -628,29 +617,29 @@
if (!equal(seq.begin(), seq.begin() + r, checkseq.begin()))
{
- BOOST_ERROR("next_r_combutation didn't restore sequence to initial value at end of series.");
+ BOOST_ERROR("next_partial_combutation didn't restore sequence to initial value at end of series.");
format_sequence(seq.begin(), seq.begin() + r, seq.end());
- cout << '\n';
+ std::cout << '\n';
format_sequence(checkseq.begin(), checkseq.begin() + r, checkseq.end());
- cout << '\n';
+ std::cout << '\n';
}
-} // test_next_r_combination_comp
+} // test_next_partial_combination_comp
-// test_prev_r_combination ----------------------------------------------//
+// test_prev_partial_combination ----------------------------------------------//
template<class T>
-void test_prev_r_combination(T& seq, int r)
+void test_prev_partial_combination(T& seq, int r)
{
- sort(seq.begin(), seq.end());
- rotate(seq.begin(), seq.end() - r, seq.end());
+ std::sort(seq.begin(), seq.end());
+ std::rotate(seq.begin(), seq.end() - r, seq.end());
T checkseq = seq;
unsigned count = 0;
try {
do {
++count;
- if (!valid_prev_r_combination(seq.begin(), seq.begin() + r, count == 1))
+ if (!valid_prev_partial_combination(seq.begin(), seq.begin() + r, count == 1))
BOOST_ERROR(invalid_combination_msg(count, seq, r).c_str());
- } while(prev_r_combination(seq.begin(), seq.begin() + r, seq.end()));
+ } while(prev_partial_combination(seq.begin(), seq.begin() + r, seq.end()));
} // try
catch(const combinatorial_range_error& oops)
{
@@ -666,8 +655,8 @@
const unsigned long comb_cnt = factorial(seq.size(), r) / factorial(r);
if (count != comb_cnt)
{
- ostringstream msg;
- msg << "prev_r_combination generated "<< count
+ std::ostringstream msg;
+ msg << "prev_partial_combination generated "<< count
<< " combinations when there should have been "
<< comb_cnt << '\n';
BOOST_ERROR(msg.str().c_str());
@@ -675,32 +664,32 @@
if (!equal(seq.begin(), seq.begin() + r, checkseq.begin()))
{
- BOOST_ERROR("prev_r_combination didn't restore sequence to initial value at end of series.");
+ BOOST_ERROR("prev_partial_combination didn't restore sequence to initial value at end of series.");
format_sequence(seq.begin(), seq.begin() + r, seq.end());
- cout << '\n';
+ std::cout << '\n';
format_sequence(checkseq.begin(), checkseq.begin() + r, checkseq.end());
- cout << '\n';
+ std::cout << '\n';
}
-} // test_prev_r_combination
+} // test_prev_partial_combination
-// test_prev_r_combination_comp -----------------------------------------//
+// test_prev_partial_combination_comp -----------------------------------------//
template<class T>
-void test_prev_r_combination_comp(T& seq, int r)
+void test_prev_partial_combination_comp(T& seq, int r)
{
typedef typename T::value_type U;
- sort(seq.begin(), seq.end(), greater<U>());
- rotate(seq.begin(), seq.end() - r, seq.end());
+ std::sort(seq.begin(), seq.end(), std::greater<U>());
+ std::rotate(seq.begin(), seq.end() - r, seq.end());
T checkseq = seq;
unsigned count = 0;
try {
do {
++count;
- if (!valid_prev_r_combination(seq.begin(), seq.begin() + r,
- greater<U>(), count == 1))
+ if (!valid_prev_partial_combination(seq.begin(), seq.begin() + r,
+ std::greater<U>(), count == 1))
BOOST_ERROR(invalid_combination_msg(count, seq, r).c_str());
- } while(prev_r_combination(seq.begin(), seq.begin() + r, seq.end(),
- greater<U>()));
+ } while(prev_partial_combination(seq.begin(), seq.begin() + r, seq.end(),
+ std::greater<U>()));
} // try
catch(const combinatorial_range_error& oops)
{
@@ -716,8 +705,8 @@
const unsigned long comb_cnt = factorial(seq.size(), r) / factorial(r);
if (count != comb_cnt)
{
- ostringstream msg;
- msg << "prev_r_combination generated "<< count
+ std::ostringstream msg;
+ msg << "prev_partial_combination generated "<< count
<< " combinations when there should have been "
<< comb_cnt << '\n';
BOOST_ERROR(msg.str().c_str());
@@ -725,53 +714,49 @@
if (!equal(seq.begin(), seq.begin() + r, checkseq.begin()))
{
- BOOST_ERROR("prev_r_combination didn't restore sequence to initial value at end of series.");
+ BOOST_ERROR("prev_partial_combination didn't restore sequence to initial value at end of series.");
format_sequence(seq.begin(), seq.begin() + r, seq.end());
- cout << '\n';
+ std::cout << '\n';
format_sequence(checkseq.begin(), checkseq.begin() + r, checkseq.end());
- cout << '\n';
+ std::cout << '\n';
}
-} // test_prev_r_combination_comp
+} // test_prev_partial_combination_comp
// test_main ------------------------------------------------------------//
int test_main(int, char*[])
{
-#ifdef __MWERKS__
- // argc = ccommand(&argv);
-#endif
-
// test factorial function ---------------------------------------->>
test_factorial();
- vector<char> nums(theNumerals, theNumerals + DIM(theNumerals));
+ std::vector<char> nums(theNumerals, theNumerals + DIM(theNumerals));
// test permutation and combination functions --------------------->>
// Repeat for various container sizes
for (int s = 0; s < DIM(theNumerals); s++)
{
- vector<char> nums2(theNumerals, theNumerals + s);
+ std::vector<char> nums2(theNumerals, theNumerals + s);
// repeat tests for r equal to 1 through the size of the container.
for(int r = 1; r <= nums2.size(); r++)
{
- test_next_r_permutation(nums2, r);
- test_next_r_permutation_comp(nums2, r);
+ test_next_partial_permutation(nums2, r);
+ test_next_partial_permutation_comp(nums2, r);
- test_prev_r_permutation(nums2, r);
- test_prev_r_permutation_comp(nums2, r);
+ test_prev_partial_permutation(nums2, r);
+ test_prev_partial_permutation_comp(nums2, r);
- test_next_r_combination(nums2, r);
- test_next_r_combination_comp(nums2, r);
+ test_next_partial_combination(nums2, r);
+ test_next_partial_combination_comp(nums2, r);
- test_prev_r_combination(nums2, r);
- test_prev_r_combination_comp(nums2, r);
+ test_prev_partial_combination(nums2, r);
+ test_prev_partial_combination_comp(nums2, r);
} // for
} // for
- cout << "\nTest of rcombo.hpp is complete." << endl;
+ std::cout << "\nTest of rcombo.hpp is complete." << std::endl;
- return test::test_tools_errors ? EXIT_FAILURE : EXIT_SUCCESS;
+ return boost::minimal_test::errors_counter() > 0 ? EXIT_FAILURE : EXIT_SUCCESS;
} // test_main
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