From 58502fddcabfcf6d13cea2dba349dcf710057012 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 15 Jun 2022 22:52:56 +0300 Subject: [PATCH] Add hash_container_test.cpp --- test/Jamfile.v2 | 2 ++ test/hash_container_test.cpp | 52 ++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 test/hash_container_test.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index c756e01..f0d7001 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -79,3 +79,5 @@ local fs-path-req = "-gcc:-Wshadow" "-gcc: run hash_fs_path_test.cpp /boost//filesystem/off : : : $(fs-path-req) msvc-14.0,latest:no ; run detail_is_range_test2.cpp : : : $(fs-path-req) ; + +run hash_container_test.cpp ; diff --git a/test/hash_container_test.cpp b/test/hash_container_test.cpp new file mode 100644 index 0000000..f24c3d5 --- /dev/null +++ b/test/hash_container_test.cpp @@ -0,0 +1,52 @@ +// Copyright 2022 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include +#include +#include +#if !defined(BOOST_NO_CXX11_HDR_FORWARD_LIST) +# include +#endif + +template std::size_t hv( T const& t ) +{ + return boost::hash()( t ); +} + +template void test() +{ + for( std::size_t i = 0; i < 8; ++i ) + { + std::vector v( i ); + std::size_t h0 = hv( v ); + + std::deque d( v.begin(), v.end() ); + BOOST_TEST_EQ( h0, hv( d ) ); + + std::list l( v.begin(), v.end() ); + BOOST_TEST_EQ( h0, hv( l ) ); + +#if !defined(BOOST_NO_CXX11_HDR_FORWARD_LIST) + + std::forward_list f( v.begin(), v.end() ); + BOOST_TEST_EQ( h0, hv( f ) ); + +#endif + } +} + +int main() +{ + test(); + test(); + test(); + test(); + test(); + test(); + + return boost::report_errors(); +}