2
0
mirror of https://github.com/boostorg/uuid.git synced 2026-01-19 04:42:16 +00:00

Update test_hash.cpp

This commit is contained in:
Peter Dimov
2024-04-21 21:24:14 +03:00
parent b4ccf853bf
commit 137878269b
2 changed files with 13 additions and 19 deletions

View File

@@ -27,7 +27,7 @@ boost_test(TYPE run SOURCES test_tagging.cpp)
boost_test(TYPE run SOURCES test_uuid_class.cpp)
boost_test(TYPE run SOURCES test_uuid_in_map.cpp)
boost_test(TYPE run SOURCES test_hash.cpp)
boost_test(TYPE run SOURCES test_hash.cpp LINK_LIBRARIES Boost::container_hash)
boost_test(TYPE run SOURCES test_hash_value.cpp)
boost_test(TYPE run SOURCES test_detail_endian.cpp)
boost_test(TYPE run SOURCES test_boost_unordered.cpp LINK_LIBRARIES Boost::unordered)

View File

@@ -1,34 +1,28 @@
//
// Copyright (c) 2018 James E. King III
//
// Copyright (c) 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)
//
// std::hash support for uuid
//
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/string_generator.hpp>
#include <boost/uuid/random_generator.hpp>
#include <boost/container_hash/hash.hpp>
#include <boost/core/lightweight_test.hpp>
#include <unordered_set>
int main()
{
using namespace boost::uuids;
string_generator gen;
uuid u1 = gen("01234567-89AB-CDEF-0123-456789abcdef");
uuid u2 = gen("fedcba98-7654-3210-fedc-ba9876543210");
random_generator gen;
std::hash<uuid> hasher;
BOOST_TEST(hasher(u1) != hasher(u2));
for( int i = 0; i < 256; ++i )
{
uuid u = gen();
std::unordered_set<boost::uuids::uuid> uns;
uns.insert(u1);
uns.insert(u2);
std::size_t v = hash_value( u );
BOOST_TEST_EQ(uns.size(), 2);
BOOST_TEST_EQ( boost::hash<uuid>()( u ), v );
BOOST_TEST_EQ( std::hash<uuid>()( u ), v );
}
return boost::report_errors();
}