Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame^] | 1 | |
| 2 | // Copyright 2012 Daniel James. |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | #include "./config.hpp" |
| 7 | |
| 8 | #ifdef BOOST_HASH_TEST_EXTENSIONS |
| 9 | # ifdef BOOST_HASH_TEST_STD_INCLUDES |
| 10 | # include <functional> |
| 11 | # else |
| 12 | # include <boost/functional/hash.hpp> |
| 13 | # endif |
| 14 | #endif |
| 15 | |
| 16 | #include <boost/config.hpp> |
| 17 | #include <boost/detail/lightweight_test.hpp> |
| 18 | |
| 19 | #if defined(BOOST_HASH_TEST_EXTENSIONS) && !defined(BOOST_NO_CXX11_HDR_TUPLE) |
| 20 | #define TEST_TUPLE |
| 21 | #include <tuple> |
| 22 | #include <vector> |
| 23 | #endif |
| 24 | |
| 25 | #ifdef TEST_TUPLE |
| 26 | |
| 27 | template <typename T> |
| 28 | void tuple_tests(T const& v) { |
| 29 | ndnboost::hash<typename T::value_type> hf; |
| 30 | for(typename T::const_iterator i = v.begin(); i != v.end(); ++i) { |
| 31 | for(typename T::const_iterator j = v.begin(); j != v.end(); ++j) { |
| 32 | if (i != j) |
| 33 | BOOST_TEST(hf(*i) != hf(*j)); |
| 34 | else |
| 35 | BOOST_TEST(hf(*i) == hf(*j)); |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | void empty_tuple_test() { |
| 41 | ndnboost::hash<std::tuple<> > empty_tuple_hash; |
| 42 | std::tuple<> empty_tuple; |
| 43 | BOOST_TEST(empty_tuple_hash(empty_tuple) == ndnboost::hash_value(empty_tuple)); |
| 44 | } |
| 45 | |
| 46 | void int_tuple_test() { |
| 47 | std::vector<std::tuple<int> > int_tuples; |
| 48 | int_tuples.push_back(std::make_tuple(0)); |
| 49 | int_tuples.push_back(std::make_tuple(1)); |
| 50 | int_tuples.push_back(std::make_tuple(2)); |
| 51 | tuple_tests(int_tuples); |
| 52 | } |
| 53 | |
| 54 | void int_string_tuple_test() { |
| 55 | std::vector<std::tuple<int, std::string> > int_string_tuples; |
| 56 | int_string_tuples.push_back(std::make_tuple(0, std::string("zero"))); |
| 57 | int_string_tuples.push_back(std::make_tuple(1, std::string("one"))); |
| 58 | int_string_tuples.push_back(std::make_tuple(2, std::string("two"))); |
| 59 | int_string_tuples.push_back(std::make_tuple(0, std::string("one"))); |
| 60 | int_string_tuples.push_back(std::make_tuple(1, std::string("zero"))); |
| 61 | int_string_tuples.push_back(std::make_tuple(0, std::string(""))); |
| 62 | int_string_tuples.push_back(std::make_tuple(1, std::string(""))); |
| 63 | tuple_tests(int_string_tuples); |
| 64 | } |
| 65 | |
| 66 | #endif // TEST_TUPLE |
| 67 | |
| 68 | int main() |
| 69 | { |
| 70 | #ifdef TEST_TUPLE |
| 71 | empty_tuple_test(); |
| 72 | int_tuple_test(); |
| 73 | int_string_tuple_test(); |
| 74 | #endif |
| 75 | |
| 76 | return ndnboost::report_errors(); |
| 77 | } |