diff options
author | Anas Nashif <anas.nashif@intel.com> | 2013-08-26 08:15:55 -0400 |
---|---|---|
committer | Anas Nashif <anas.nashif@intel.com> | 2013-08-26 08:15:55 -0400 |
commit | bb4dd8289b351fae6b55e303f189127a394a1edd (patch) | |
tree | 77c9c35a31b1459dd7988c2448e797d142530c41 /libs/functional/hash/test/hash_std_tuple_test.cpp | |
parent | 1a78a62555be32868418fe52f8e330c9d0f95d5a (diff) | |
download | boost-bb4dd8289b351fae6b55e303f189127a394a1edd.tar.gz boost-bb4dd8289b351fae6b55e303f189127a394a1edd.tar.bz2 boost-bb4dd8289b351fae6b55e303f189127a394a1edd.zip |
Imported Upstream version 1.51.0upstream/1.51.0
Diffstat (limited to 'libs/functional/hash/test/hash_std_tuple_test.cpp')
-rw-r--r-- | libs/functional/hash/test/hash_std_tuple_test.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/libs/functional/hash/test/hash_std_tuple_test.cpp b/libs/functional/hash/test/hash_std_tuple_test.cpp new file mode 100644 index 0000000000..9314336af5 --- /dev/null +++ b/libs/functional/hash/test/hash_std_tuple_test.cpp @@ -0,0 +1,77 @@ + +// Copyright 2012 Daniel James. +// 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) + +#include "./config.hpp" + +#ifdef TEST_EXTENSIONS +# ifdef TEST_STD_INCLUDES +# include <functional> +# else +# include <boost/functional/hash.hpp> +# endif +#endif + +#include <boost/config.hpp> +#include <boost/detail/lightweight_test.hpp> + +#if defined(TEST_EXTENSIONS) && !defined(BOOST_NO_CXX11_HDR_TUPLE) +#define TEST_TUPLE +#include <tuple> +#include <vector> +#endif + +#ifdef TEST_TUPLE + +template <typename T> +void tuple_tests(T const& v) { + boost::hash<typename T::value_type> hf; + for(typename T::const_iterator i = v.begin(); i != v.end(); ++i) { + for(typename T::const_iterator j = v.begin(); j != v.end(); ++j) { + if (i != j) + BOOST_TEST(hf(*i) != hf(*j)); + else + BOOST_TEST(hf(*i) == hf(*j)); + } + } +} + +void empty_tuple_test() { + boost::hash<std::tuple<> > empty_tuple_hash; + std::tuple<> empty_tuple; + BOOST_TEST(empty_tuple_hash(empty_tuple) == boost::hash_value(empty_tuple)); +} + +void int_tuple_test() { + std::vector<std::tuple<int> > int_tuples; + int_tuples.push_back(std::make_tuple(0)); + int_tuples.push_back(std::make_tuple(1)); + int_tuples.push_back(std::make_tuple(2)); + tuple_tests(int_tuples); +} + +void int_string_tuple_test() { + std::vector<std::tuple<int, std::string> > int_string_tuples; + int_string_tuples.push_back(std::make_tuple(0, std::string("zero"))); + int_string_tuples.push_back(std::make_tuple(1, std::string("one"))); + int_string_tuples.push_back(std::make_tuple(2, std::string("two"))); + int_string_tuples.push_back(std::make_tuple(0, std::string("one"))); + int_string_tuples.push_back(std::make_tuple(1, std::string("zero"))); + int_string_tuples.push_back(std::make_tuple(0, std::string(""))); + int_string_tuples.push_back(std::make_tuple(1, std::string(""))); + tuple_tests(int_string_tuples); +} + +#endif // TEST_TUPLE + +int main() +{ +#ifdef TEST_TUPLE + empty_tuple_test(); + int_tuple_test(); + int_string_tuple_test(); +#endif + + return boost::report_errors(); +} |