Merged boost::algorithm::gather and updated tests for Utility, Algorithm and Utility libraries

[SVN r83154]
This commit is contained in:
Marshall Clow
2013-02-25 18:43:26 +00:00
parent ba1a2437cf
commit a73b6fb582
4 changed files with 57 additions and 92 deletions

View File

@ -4,13 +4,18 @@
import testing ; import testing ;
alias unit_test_framework
: # sources
/boost//unit_test_framework
;
test-suite array : test-suite array :
[ run array0.cpp ] [ run array0.cpp unit_test_framework : : : : array0 ]
[ run array1.cpp ] [ run array1.cpp ]
[ run array2.cpp ] [ run array2.cpp ]
[ run array3.cpp ] [ run array3.cpp ]
[ run array4.cpp ] [ run array4.cpp ]
[ run array5.cpp ] [ run array5.cpp ]
[ run array6.cpp ] [ run array6.cpp unit_test_framework : : : : array6 ]
[ run array_hash.cpp ] [ run array_hash.cpp unit_test_framework : : : : array_hash ]
; ;

View File

@ -9,18 +9,15 @@
#include <iostream> #include <iostream>
#include <boost/array.hpp> #include <boost/array.hpp>
namespace { #define BOOST_TEST_MAIN
unsigned int failed_tests = 0; #include <boost/test/unit_test.hpp>
void fail_test( const char * reason ) { namespace {
++failed_tests;
std::cerr << "Test failure " << failed_tests << ": " << reason << std::endl;
}
template< class T > template< class T >
void BadValue( const T & ) void BadValue( const T & )
{ {
fail_test( "Unexpected value" ); BOOST_CHECK ( false );
} }
template< class T > template< class T >
@ -36,46 +33,24 @@ void RunTests()
// front/back and operator[] must compile, but calling them is undefined // front/back and operator[] must compile, but calling them is undefined
// Likewise, all tests below should evaluate to false, avoiding undefined behaviour // Likewise, all tests below should evaluate to false, avoiding undefined behaviour
if( !test_case.empty() ) { BOOST_CHECK ( test_case.empty());
BadValue( test_case.front() ); BOOST_CHECK ( const_test_case.empty());
}
if( !const_test_case.empty() ) { BOOST_CHECK ( test_case.size() == 0 );
BadValue( const_test_case.back() ); BOOST_CHECK ( const_test_case.size() == 0 );
}
if( test_case.size() > 0 ) {
BadValue( test_case[ 0 ] );
}
if( const_test_case.max_size() > 0 ) {
BadValue( const_test_case[ 0 ] );
}
// Assert requirements of TR1 6.2.2.4 // Assert requirements of TR1 6.2.2.4
if( test_case.begin() != test_case.end() ) { BOOST_CHECK ( test_case.begin() == test_case.end());
fail_test( "Not an empty range" ); BOOST_CHECK ( test_case.cbegin() == test_case.cend());
} BOOST_CHECK ( const_test_case.begin() == const_test_case.end());
if( test_case.cbegin() != test_case.cend() ) { BOOST_CHECK ( const_test_case.cbegin() == const_test_case.cend());
fail_test( "Not an empty range" );
}
if( const_test_case.begin() != const_test_case.end() ) {
fail_test( "Not an empty range" );
}
if( const_test_case.cbegin() != const_test_case.cend() ) {
fail_test( "Not an empty range" );
}
if( test_case.begin() == const_test_case.begin() ) {
fail_test( "iterators for different containers are not distinct" );
}
BOOST_CHECK ( test_case.begin() != const_test_case.begin() );
if( test_case.data() == const_test_case.data() ) { if( test_case.data() == const_test_case.data() ) {
// Value of data is unspecified in TR1, so no requirement this test pass or fail // Value of data is unspecified in TR1, so no requirement this test pass or fail
// However, it must compile! // However, it must compile!
} }
// Check can safely use all iterator types with std algorithms // Check can safely use all iterator types with std algorithms
std::for_each( test_case.begin(), test_case.end(), BadValue< T > ); std::for_each( test_case.begin(), test_case.end(), BadValue< T > );
std::for_each( test_case.rbegin(), test_case.rend(), BadValue< T > ); std::for_each( test_case.rbegin(), test_case.rend(), BadValue< T > );
@ -87,12 +62,12 @@ void RunTests()
// Check swap is well formed // Check swap is well formed
std::swap( test_case, test_case ); std::swap( test_case, test_case );
// Check assigment operator and overloads are well formed // Check assignment operator and overloads are well formed
test_case = const_test_case; test_case = const_test_case;
// Confirm at() throws the std lib defined exception // Confirm at() throws the std lib defined exception
try { try {
BadValue( test_case.at( 0 ) ); BadValue( test_case.at( 0 ));
} catch ( const std::out_of_range & ) { } catch ( const std::out_of_range & ) {
} }
@ -104,12 +79,11 @@ void RunTests()
} }
int main() BOOST_AUTO_TEST_CASE( test_main )
{ {
RunTests< bool >(); RunTests< bool >();
RunTests< void * >(); RunTests< void * >();
RunTests< long double >(); RunTests< long double >();
RunTests< std::string >(); RunTests< std::string >();
return failed_tests;
} }

View File

@ -10,39 +10,31 @@
#include <boost/array.hpp> #include <boost/array.hpp>
#include <algorithm> #include <algorithm>
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
namespace { namespace {
unsigned int failed_tests = 0; template< class T >
void RunTests()
void fail_test( const char * reason ) { {
++failed_tests;
std::cerr << "Test failure " << failed_tests << ": " << reason << std::endl;
}
template< class T >
void RunTests()
{
typedef boost::array< T, 5 > test_type; typedef boost::array< T, 5 > test_type;
typedef T arr[5]; typedef T arr[5];
test_type test_case; // = { 1, 1, 2, 3, 5 }; test_type test_case; // = { 1, 1, 2, 3, 5 };
arr &aRef = get_c_array ( test_case ); arr &aRef = get_c_array ( test_case );
if ( &*test_case.begin () != &aRef[0] ) BOOST_CHECK ( &*test_case.begin () == &aRef[0] );
fail_test ( "Array6: Same thing not equal?(1)" );
const arr &caRef = get_c_array ( test_case ); const arr &caRef = get_c_array ( test_case );
typename test_type::const_iterator iter = test_case.begin (); typename test_type::const_iterator iter = test_case.begin ();
if ( &*iter != &caRef[0] ) BOOST_CHECK ( &*iter == &caRef[0] );
fail_test ( "Array6: Same thing not equal?(2)" ); }
} }
} BOOST_AUTO_TEST_CASE( test_main )
int main()
{ {
RunTests< bool >(); RunTests< bool >();
RunTests< void * >(); RunTests< void * >();
RunTests< long double >(); RunTests< long double >();
RunTests< std::string >(); RunTests< std::string >();
return failed_tests;
} }

View File

@ -11,19 +11,16 @@
#include <algorithm> #include <algorithm>
#include <boost/functional/hash.hpp> #include <boost/functional/hash.hpp>
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
namespace { namespace {
unsigned int failed_tests = 0;
void fail_test( const char * reason ) { template< class T >
++failed_tests; void RunTests()
std::cerr << "Test failure " << failed_tests << ": " << reason << std::endl; {
} // std::size_t hash0 = boost::hash<boost::array<T,0> > () ( boost::array<T, 0> ());
// std::size_t hash1 = boost::hash<boost::array<T,1> > () ( boost::array<T, 1> ());
template< class T >
void RunTests()
{
// std::size_t hash0 = boost::hash<boost::array<T,0> > () ( boost::array<T, 0> ());
// std::size_t hash1 = boost::hash<boost::array<T,1> > () ( boost::array<T, 1> ());
typedef boost::array< T, 5 > barr; typedef boost::array< T, 5 > barr;
typedef T arr[5]; typedef T arr[5];
@ -32,18 +29,15 @@ void RunTests()
std::size_t bhash = boost::hash<barr> () ( test_barr ); std::size_t bhash = boost::hash<barr> () ( test_barr );
std::size_t ahash = boost::hash<arr> () ( test_arr ); std::size_t ahash = boost::hash<arr> () ( test_arr );
if ( ahash != bhash ) BOOST_CHECK ( ahash == bhash );
fail_test ( "Array_hash: Hash-mismatch on " ); }
}
} }
int main() BOOST_AUTO_TEST_CASE( test_main )
{ {
RunTests< int >(); RunTests< int >();
RunTests< long >(); RunTests< long >();
RunTests< long double >(); RunTests< long double >();
return failed_tests;
} }