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/container_hash/hash.hpp> 13 # endif 14 #endif 15 16 #include <boost/config.hpp> 17 #include <boost/core/lightweight_test.hpp> 18 19 #if defined(BOOST_HASH_TEST_EXTENSIONS) && !defined(BOOST_NO_CXX11_HDR_ARRAY) 20 #define TEST_ARRAY 21 #include <array> 22 #include <vector> 23 #endif 24 25 #ifdef TEST_ARRAY 26 27 template <typename T> array_tests(T const & v)28void array_tests(T const& v) { 29 boost::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 empty_array_test()40void empty_array_test() { 41 /* 42 boost::hash<std::array<int, 0> > empty_array_hash; 43 std::array<int, 0> empty_array; 44 BOOST_TEST(empty_array_hash(empty_array) == boost::hash_value(empty_array)); 45 */ 46 } 47 int_1_array_test()48void int_1_array_test() 49 { 50 std::vector<std::array<int, 1> > arrays; 51 std::array<int, 1> val; 52 val[0] = 0; 53 arrays.push_back(val); 54 val[0] = 1; 55 arrays.push_back(val); 56 val[0] = 2; 57 arrays.push_back(val); 58 array_tests(arrays); 59 } 60 string_1_array_test()61void string_1_array_test() 62 { 63 std::vector<std::array<std::string, 1> > arrays; 64 std::array<std::string, 1> val; 65 arrays.push_back(val); 66 val[0] = "one"; 67 arrays.push_back(val); 68 val[0] = "two"; 69 arrays.push_back(val); 70 array_tests(arrays); 71 } 72 string_3_array_test()73void string_3_array_test() 74 { 75 std::vector<std::array<std::string,3 > > arrays; 76 std::array<std::string, 3> val; 77 arrays.push_back(val); 78 val[0] = "one"; 79 arrays.push_back(val); 80 val[0] = ""; val[1] = "one"; val[2] = ""; 81 arrays.push_back(val); 82 val[0] = ""; val[1] = ""; val[2] = "one"; 83 arrays.push_back(val); 84 val[0] = "one"; val[1] = "one"; val[2] = "one"; 85 arrays.push_back(val); 86 val[0] = "one"; val[1] = "two"; val[2] = "three"; 87 arrays.push_back(val); 88 array_tests(arrays); 89 } 90 91 #endif // TEST_ARRAY 92 main()93int main() 94 { 95 #ifdef TEST_ARRAY 96 empty_array_test(); 97 int_1_array_test(); 98 string_1_array_test(); 99 string_3_array_test(); 100 #endif 101 102 return boost::report_errors(); 103 } 104