From 7a88ef8658ce1be29c58ce84b0935a18bbe8373a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Br=C3=B6nnimann?= Date: Wed, 21 Jul 2004 17:15:40 +0000 Subject: [PATCH] Now includes minmax_test in the test suite. [SVN r23909] --- minmax/test/Jamfile | 6 +++ minmax/test/minmax_test.cpp | 73 +++++++++++++++++++------------------ 2 files changed, 43 insertions(+), 36 deletions(-) diff --git a/minmax/test/Jamfile b/minmax/test/Jamfile index ab478eb..1a4e85b 100644 --- a/minmax/test/Jamfile +++ b/minmax/test/Jamfile @@ -23,5 +23,11 @@ DEPENDS all : test ; : : minmax_element ] + [ run + minmax_test.cpp + : : + : + : minmax + ] ; } diff --git a/minmax/test/minmax_test.cpp b/minmax/test/minmax_test.cpp index 72b75be..efd277c 100644 --- a/minmax/test/minmax_test.cpp +++ b/minmax/test/minmax_test.cpp @@ -1,78 +1,79 @@ #include #include -#include -#include -#include -#include -#include -#include #include #include #include class custom { - int _M_x; - friend bool operator<(custom const& x, custom const& y); + int m_x; friend std::ostream& operator<<(std::ostream& str, custom const& x); public: - explicit custom(int x = 0) : _M_x(x) {} - custom(custom const& y) : _M_x(y._M_x) {} - custom operator+(custom const& y) const { return custom(_M_x+y._M_x); } - custom& operator+=(custom const& y) { _M_x += y._M_x; return *this; } + explicit custom(int x = 0) : m_x(x) {} + custom(custom const& y) : m_x(y.m_x) {} + bool operator==(custom const& y) const { return m_x == y.m_x; } + bool operator<(custom const& y) const { return m_x < y.m_x; } + custom operator+(custom const& y) const { return custom(m_x+y.m_x); } + custom& operator+=(custom const& y) { m_x += y.m_x; return *this; } }; -bool operator< (custom const& x, custom const& y) +std::ostream& +operator<<(std::ostream& str, custom const& x) { - return x._M_x < y._M_x; + return str << x.m_x; } template struct less_count : std::less { typedef std::less Base; - less_count(less_count const& lc) : _M_counter(lc._M_counter) {} - less_count(int& counter) : _M_counter(counter) {} + less_count(less_count const& lc) : m_counter(lc.m_counter) {} + less_count(int& counter) : m_counter(counter) {} bool operator()(Value const& a, Value const& b) const { - ++_M_counter; + ++m_counter; return Base::operator()(a,b); } void reset() { - _M_counter = 0; + m_counter = 0; } private: - int& _M_counter; + int& m_counter; }; template -void test(int n, char* name) +void test(char*) { using namespace boost; + Value zero(0), one(1); + int counter = 0; + less_count lc(counter); // Test functionality - tuple result = minmax(0, 1); - BOOST_CHECK_EQUAL( result.get<0>(), 0 ); - BOOST_CHECK_EQUAL( result.get<1>(), 1 ); + tuple result1 = minmax(zero, one); + BOOST_CHECK_EQUAL( result1.get<0>(), zero ); + BOOST_CHECK_EQUAL( result1.get<1>(), one ); - result = minmax(1, 0); - BOOST_CHECK_EQUAL( result.get<0>(), 0 ); - BOOST_CHECK_EQUAL( result.get<1>(), 1 ); + tuple result2 = minmax(one, zero); + BOOST_CHECK_EQUAL( result2.get<0>(), zero ); + BOOST_CHECK_EQUAL( result2.get<1>(), one ); // Test functionality and number of comparisons - int counter = 0; - BOOST_CHECK_EQUAL( result.get<0>(), 0 ); - BOOST_CHECK_EQUAL( result.get<1>(), 1 ); + lc.reset(); + tuple result3 = minmax(zero, one, lc ); + BOOST_CHECK_EQUAL( result3.get<0>(), zero ); + BOOST_CHECK_EQUAL( result3.get<1>(), one ); BOOST_CHECK_EQUAL( counter, 1 ); - result = minmax(1, 0, less_count(counter) ); - BOOST_CHECK_EQUAL( result.get<0>(), 0 ); - BOOST_CHECK_EQUAL( result.get<1>(), 1 ); - BOOST_CHECK_EQUAL( counter, 2); + lc.reset(); + tuple result4 = minmax(one, zero, lc ); + BOOST_CHECK_EQUAL( result4.get<0>(), zero ); + BOOST_CHECK_EQUAL( result4.get<1>(), one ); + BOOST_CHECK_EQUAL( counter, 1); } -int test_main( int argc, char* argv[] ) +int test_main( int , char* [] ) { - test(n, "builtin"); - test(n, "custom "); + test("builtin"); + test("custom "); return 0; }