mirror of
https://github.com/boostorg/functional.git
synced 2025-08-02 14:04:27 +02:00
Change tests so they can be used to test implementations of TR1 (maybe, eventually).
[SVN r28052]
This commit is contained in:
@@ -8,7 +8,7 @@ subproject libs/functional/hash/test ;
|
||||
|
||||
import testing ;
|
||||
|
||||
DEPENDS all : functional/hash ;
|
||||
DEPENDS all : test ;
|
||||
|
||||
rule hash-test ( name )
|
||||
{
|
||||
|
@@ -11,7 +11,7 @@ template <class T>
|
||||
struct compile_time_tests
|
||||
{
|
||||
BOOST_MPL_ASSERT((boost::is_base_and_derived<
|
||||
std::unary_function<T, std::size_t>, boost::hash<T> >));
|
||||
std::unary_function<T, std::size_t>, HASH_NAMESPACE::hash<T> >));
|
||||
BOOST_STATIC_CONSTANT(bool, success = true);
|
||||
};
|
||||
|
||||
|
13
hash/test/config.hpp
Normal file
13
hash/test/config.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
// (C) Copyright Daniel James 2005.
|
||||
// Use, modification and distribution are subject to 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)
|
||||
|
||||
#if defined(TEST_STD)
|
||||
# define TEST_STD_INCLUDES
|
||||
# define HASH_NAMESPACE std::tr1
|
||||
#else
|
||||
# define HASH_NAMESPACE boost
|
||||
# define TEST_EXTENSIONS
|
||||
#endif
|
@@ -4,11 +4,21 @@
|
||||
// Boost Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/functional/hash/hash.hpp>
|
||||
#include "./config.hpp"
|
||||
|
||||
#ifdef TEST_EXTENSIONS
|
||||
# ifdef TEST_STD_INCLUDES
|
||||
# include <functional>
|
||||
# else
|
||||
# include <boost/functional/hash/hash.hpp>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
|
||||
#ifdef TEST_EXTENSIONS
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cctype>
|
||||
@@ -38,7 +48,7 @@ namespace boost
|
||||
|
||||
BOOST_AUTO_UNIT_TEST(custom_tests)
|
||||
{
|
||||
boost::hash<test::custom> custom_hasher;
|
||||
HASH_NAMESPACE::hash<test::custom> custom_hasher;
|
||||
BOOST_CHECK(custom_hasher(10) == 100u);
|
||||
test::custom x(55);
|
||||
BOOST_CHECK(custom_hasher(x) == 550u);
|
||||
@@ -49,11 +59,12 @@ BOOST_AUTO_UNIT_TEST(custom_tests)
|
||||
custom_vector.push_back(35);
|
||||
|
||||
std::size_t seed = 0;
|
||||
boost::hash_combine(seed, test::custom(5));
|
||||
boost::hash_combine(seed, test::custom(25));
|
||||
boost::hash_combine(seed, test::custom(35));
|
||||
HASH_NAMESPACE::hash_combine(seed, test::custom(5));
|
||||
HASH_NAMESPACE::hash_combine(seed, test::custom(25));
|
||||
HASH_NAMESPACE::hash_combine(seed, test::custom(35));
|
||||
|
||||
BOOST_CHECK(seed ==
|
||||
boost::hash_range(custom_vector.begin(), custom_vector.end()));
|
||||
HASH_NAMESPACE::hash_range(custom_vector.begin(), custom_vector.end()));
|
||||
}
|
||||
|
||||
#endif // TEST_EXTENSIONS
|
||||
|
@@ -4,13 +4,25 @@
|
||||
// Boost Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/functional/hash/deque.hpp>
|
||||
#include "./config.hpp"
|
||||
|
||||
#ifdef TEST_EXTENSIONS
|
||||
# ifdef TEST_STD_INCLUDES
|
||||
# include <functional>
|
||||
# else
|
||||
# include <boost/functional/hash/deque.hpp>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
|
||||
#ifdef TEST_EXTENSIONS
|
||||
|
||||
#include <deque>
|
||||
|
||||
using std::deque;
|
||||
#define CONTAINER_TYPE deque
|
||||
#include "./hash_sequence_test.hpp"
|
||||
|
||||
#endif // TEST_EXTENSIONS
|
||||
|
@@ -3,7 +3,13 @@
|
||||
// subject to 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)
|
||||
|
||||
#include <boost/functional/hash/hash.hpp>
|
||||
#include "./config.hpp"
|
||||
|
||||
#ifdef TEST_STD_INCLUDES
|
||||
# include <functional>
|
||||
#else
|
||||
# include <boost/functional/hash/hash.hpp>
|
||||
#endif
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
@@ -14,7 +20,7 @@
|
||||
template <class T>
|
||||
void float_tests(T* = 0)
|
||||
{
|
||||
boost::hash<T> x1;
|
||||
HASH_NAMESPACE::hash<T> x1;
|
||||
|
||||
T zero = 0;
|
||||
T minus_zero = (T) -1 * zero;
|
||||
|
@@ -4,14 +4,25 @@
|
||||
// Boost Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/functional/hash/list.hpp>
|
||||
#include "./config.hpp"
|
||||
|
||||
#ifdef TEST_EXTENSIONS
|
||||
# ifdef TEST_STD_INCLUDES
|
||||
# include <functional>
|
||||
# else
|
||||
# include <boost/functional/hash/list.hpp>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
|
||||
#ifdef TEST_EXTENSIONS
|
||||
|
||||
#include <list>
|
||||
|
||||
using std::list;
|
||||
#define CONTAINER_TYPE list
|
||||
#include "./hash_sequence_test.hpp"
|
||||
|
||||
#endif // TEST_EXTENSIONS
|
||||
|
@@ -4,13 +4,23 @@
|
||||
// Boost Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/functional/hash/map.hpp>
|
||||
#include "./config.hpp"
|
||||
|
||||
#ifdef TEST_EXTENSIONS
|
||||
# ifdef TEST_STD_INCLUDES
|
||||
# include <functional>
|
||||
# else
|
||||
# include <boost/functional/hash/map.hpp>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
|
||||
#include <map>
|
||||
|
||||
#ifdef TEST_EXTENSIONS
|
||||
|
||||
using std::map;
|
||||
#define CONTAINER_TYPE map
|
||||
#include "./hash_map_test.hpp"
|
||||
@@ -19,3 +29,4 @@ using std::multimap;
|
||||
#define CONTAINER_TYPE multimap
|
||||
#include "./hash_map_test.hpp"
|
||||
|
||||
#endif // TEST_EXTENSTIONS
|
||||
|
@@ -31,7 +31,7 @@ namespace BOOST_PP_CAT(CONTAINER_TYPE, _tests)
|
||||
containers[9].insert(pair(-1,3));
|
||||
containers[9].insert(pair(-1,3));
|
||||
|
||||
boost::hash<T> hasher;
|
||||
HASH_NAMESPACE::hash<T> hasher;
|
||||
|
||||
for(int i2 = 0; i2 < number_of_containers; ++i2) {
|
||||
BOOST_CHECK(hasher(containers[i2]) == hasher(containers[i2]));
|
||||
|
@@ -3,7 +3,13 @@
|
||||
// subject to 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)
|
||||
|
||||
#include <boost/functional/hash/hash.hpp>
|
||||
#include "./config.hpp"
|
||||
|
||||
#ifdef TEST_STD_INCLUDES
|
||||
# include <functional>
|
||||
#else
|
||||
# include <boost/functional/hash/hash.hpp>
|
||||
#endif
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
@@ -20,8 +26,8 @@ void numeric_test()
|
||||
{
|
||||
BOOST_CHECK(compile_time_tests<T>::success);
|
||||
|
||||
boost::hash<T> x1;
|
||||
boost::hash<T> x2;
|
||||
HASH_NAMESPACE::hash<T> x1;
|
||||
HASH_NAMESPACE::hash<T> x2;
|
||||
|
||||
BOOST_CHECK(x1(T(0)) == x2(T(0)));
|
||||
|
||||
|
@@ -1,9 +1,16 @@
|
||||
|
||||
// (C) Copyright Daniel James 2005.
|
||||
// Use, modification and distribution are subject to 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)
|
||||
|
||||
#include <boost/functional/hash/hash.hpp>
|
||||
#include "./config.hpp"
|
||||
|
||||
#ifdef TEST_STD_INCLUDES
|
||||
# include <functional>
|
||||
#else
|
||||
# include <boost/functional/hash/hash.hpp>
|
||||
#endif
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
@@ -19,8 +26,8 @@ BOOST_AUTO_UNIT_TEST(pointer_tests)
|
||||
BOOST_CHECK(compile_time_tests<int*>::success);
|
||||
BOOST_CHECK(compile_time_tests<void*>::success);
|
||||
|
||||
boost::hash<int*> x1;
|
||||
boost::hash<int*> x2;
|
||||
HASH_NAMESPACE::hash<int*> x1;
|
||||
HASH_NAMESPACE::hash<int*> x2;
|
||||
|
||||
int int1;
|
||||
int int2;
|
||||
|
@@ -3,11 +3,21 @@
|
||||
// Boost Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/functional/hash/hash.hpp>
|
||||
#include "./config.hpp"
|
||||
|
||||
#ifdef TEST_EXTENSIONS
|
||||
# ifdef TEST_STD_INCLUDES
|
||||
# include <functional>
|
||||
# else
|
||||
# include <boost/functional/hash/hash.hpp>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
|
||||
#ifdef TEST_EXTENSIONS
|
||||
|
||||
#include <boost/limits.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/type_traits/is_base_and_derived.hpp>
|
||||
@@ -29,27 +39,29 @@ BOOST_AUTO_UNIT_TEST(hash_range_tests)
|
||||
values5.push_back(20);
|
||||
|
||||
std::vector<int> x;
|
||||
BOOST_CHECK(boost::hash_range(empty.begin(), empty.end())
|
||||
== boost::hash_range(x.begin(), x.end()));
|
||||
BOOST_CHECK(boost::hash_range(empty.begin(), empty.end())
|
||||
!= boost::hash_range(values1.begin(), values1.end()));
|
||||
BOOST_CHECK(HASH_NAMESPACE::hash_range(empty.begin(), empty.end())
|
||||
== HASH_NAMESPACE::hash_range(x.begin(), x.end()));
|
||||
BOOST_CHECK(HASH_NAMESPACE::hash_range(empty.begin(), empty.end())
|
||||
!= HASH_NAMESPACE::hash_range(values1.begin(), values1.end()));
|
||||
|
||||
x.push_back(10);
|
||||
BOOST_CHECK(boost::hash_range(empty.begin(), empty.end())
|
||||
!= boost::hash_range(x.begin(), x.end()));
|
||||
BOOST_CHECK(boost::hash_range(values2.begin(), values2.end())
|
||||
== boost::hash_range(x.begin(), x.end()));
|
||||
BOOST_CHECK(HASH_NAMESPACE::hash_range(empty.begin(), empty.end())
|
||||
!= HASH_NAMESPACE::hash_range(x.begin(), x.end()));
|
||||
BOOST_CHECK(HASH_NAMESPACE::hash_range(values2.begin(), values2.end())
|
||||
== HASH_NAMESPACE::hash_range(x.begin(), x.end()));
|
||||
|
||||
x.push_back(20);
|
||||
BOOST_CHECK(boost::hash_range(empty.begin(), empty.end())
|
||||
!= boost::hash_range(x.begin(), x.end()));
|
||||
BOOST_CHECK(boost::hash_range(values2.begin(), values2.end())
|
||||
!= boost::hash_range(x.begin(), x.end()));
|
||||
BOOST_CHECK(boost::hash_range(values3.begin(), values3.end())
|
||||
== boost::hash_range(x.begin(), x.end()));
|
||||
BOOST_CHECK(HASH_NAMESPACE::hash_range(empty.begin(), empty.end())
|
||||
!= HASH_NAMESPACE::hash_range(x.begin(), x.end()));
|
||||
BOOST_CHECK(HASH_NAMESPACE::hash_range(values2.begin(), values2.end())
|
||||
!= HASH_NAMESPACE::hash_range(x.begin(), x.end()));
|
||||
BOOST_CHECK(HASH_NAMESPACE::hash_range(values3.begin(), values3.end())
|
||||
== HASH_NAMESPACE::hash_range(x.begin(), x.end()));
|
||||
|
||||
std::size_t seed = boost::hash_range(values3.begin(), values3.end());
|
||||
boost::hash_range(seed, values4.begin(), values4.end());
|
||||
boost::hash_range(seed, x.begin(), x.end());
|
||||
BOOST_CHECK(seed == boost::hash_range(values5.begin(), values5.end()));
|
||||
std::size_t seed = HASH_NAMESPACE::hash_range(values3.begin(), values3.end());
|
||||
HASH_NAMESPACE::hash_range(seed, values4.begin(), values4.end());
|
||||
HASH_NAMESPACE::hash_range(seed, x.begin(), x.end());
|
||||
BOOST_CHECK(seed == HASH_NAMESPACE::hash_range(values5.begin(), values5.end()));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -34,7 +34,7 @@ namespace BOOST_PP_CAT(CONTAINER_TYPE, _tests)
|
||||
containers[10].push_back(-1);
|
||||
containers[10].push_back(1);
|
||||
|
||||
boost::hash<T> hasher;
|
||||
HASH_NAMESPACE::hash<T> hasher;
|
||||
|
||||
for(int i2 = 0; i2 < number_of_containers; ++i2) {
|
||||
BOOST_CHECK(hasher(containers[i2]) == hasher(containers[i2]));
|
||||
|
@@ -4,11 +4,21 @@
|
||||
// Boost Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/functional/hash/set.hpp>
|
||||
#include "./config.hpp"
|
||||
|
||||
#ifdef TEST_EXTENSIONS
|
||||
# ifdef TEST_STD_INCLUDES
|
||||
# include <functional>
|
||||
# else
|
||||
# include <boost/functional/hash/set.hpp>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
|
||||
#ifdef TEST_EXTENSIONS
|
||||
|
||||
#include <set>
|
||||
|
||||
using std::set;
|
||||
@@ -18,3 +28,5 @@ using std::set;
|
||||
using std::multiset;
|
||||
#define CONTAINER_TYPE multiset
|
||||
#include "./hash_set_test.hpp"
|
||||
|
||||
#endif
|
||||
|
@@ -32,7 +32,7 @@ namespace BOOST_PP_CAT(CONTAINER_TYPE, _tests)
|
||||
containers[10].insert(-1);
|
||||
containers[10].insert(1);
|
||||
|
||||
boost::hash<T> hasher;
|
||||
HASH_NAMESPACE::hash<T> hasher;
|
||||
|
||||
for(int i2 = 0; i2 < number_of_containers; ++i2) {
|
||||
BOOST_CHECK(hasher(containers[i2]) == hasher(containers[i2]));
|
||||
|
@@ -3,7 +3,13 @@
|
||||
// Boost Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/functional/hash/hash.hpp>
|
||||
#include "./config.hpp"
|
||||
|
||||
#ifdef TEST_STD_INCLUDES
|
||||
# include <functional>
|
||||
#else
|
||||
# include <boost/functional/hash/hash.hpp>
|
||||
#endif
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
@@ -18,8 +24,8 @@ BOOST_AUTO_UNIT_TEST(string_tests)
|
||||
{
|
||||
BOOST_CHECK(compile_time_tests<std::string>::success);
|
||||
|
||||
boost::hash<std::string> x1;
|
||||
boost::hash<std::string> x2;
|
||||
HASH_NAMESPACE::hash<std::string> x1;
|
||||
HASH_NAMESPACE::hash<std::string> x2;
|
||||
|
||||
BOOST_CHECK(x1("Hello") == x2(std::string("Hel") + "lo"));
|
||||
BOOST_CHECK(x1("") == x2(std::string()));
|
||||
@@ -30,8 +36,8 @@ BOOST_AUTO_UNIT_TEST(wstring_tests)
|
||||
{
|
||||
BOOST_CHECK(compile_time_tests<std::wstring>::success);
|
||||
|
||||
boost::hash<std::wstring> x1;
|
||||
boost::hash<std::wstring> x2;
|
||||
HASH_NAMESPACE::hash<std::wstring> x1;
|
||||
HASH_NAMESPACE::hash<std::wstring> x2;
|
||||
|
||||
BOOST_CHECK(x1(L"Hello") == x2(std::wstring(L"Hel") + L"lo"));
|
||||
BOOST_CHECK(x1(L"") == x2(std::wstring()));
|
||||
|
@@ -4,13 +4,25 @@
|
||||
// Boost Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/functional/hash/vector.hpp>
|
||||
#include "./config.hpp"
|
||||
|
||||
#ifdef TEST_EXTENSIONS
|
||||
# ifdef TEST_STD_INCLUDES
|
||||
# include <functional>
|
||||
# else
|
||||
# include <boost/functional/hash/vector.hpp>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
|
||||
#ifdef TEST_EXTENSIONS
|
||||
|
||||
#include <vector>
|
||||
|
||||
using std::vector;
|
||||
#define CONTAINER_TYPE vector
|
||||
#include "./hash_sequence_test.hpp"
|
||||
|
||||
#endif // TEST_EXTENSIONS
|
||||
|
Reference in New Issue
Block a user