2
0
mirror of https://github.com/boostorg/hash2.git synced 2026-01-23 05:32:13 +00:00
Files
hash2/test/set.cpp
2023-12-03 20:37:04 +02:00

77 lines
1.6 KiB
C++

// Copyright 2017, 2018 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
//
// Endian-dependent test
#include <boost/hash2/hash_append.hpp>
#include <boost/hash2/fnv1a.hpp>
#include <boost/core/lightweight_test.hpp>
#include <set>
#include <unordered_set>
template<class H, class S, class R> void test( R r )
{
{
S s;
for( int i = 0; i < 64; ++i )
{
s.insert( i );
}
H h;
hash_append( h, s );
BOOST_TEST_EQ( h.result(), r );
}
{
S s;
for( int i = 0; i < 64; ++i )
{
s.insert( 63 - i );
}
H h;
hash_append( h, s );
BOOST_TEST_EQ( h.result(), r );
}
{
S s;
for( int i = 0; i < 64; ++i )
{
s.insert( ( i * 17 ) % 64 );
}
H h;
hash_append( h, s );
BOOST_TEST_EQ( h.result(), r );
}
}
int main()
{
test< boost::hash2::fnv1a_32, std::set<int> >( 2078558933ul );
test< boost::hash2::fnv1a_64, std::set<int> >( 17046016161958689285ull );
test< boost::hash2::fnv1a_32, std::multiset<int> >( 2078558933ul );
test< boost::hash2::fnv1a_64, std::multiset<int> >( 17046016161958689285ull );
test< boost::hash2::fnv1a_32, std::unordered_set<int> >( 2270492092ul );
test< boost::hash2::fnv1a_64, std::unordered_set<int> >( 3232503781718511241ull );
test< boost::hash2::fnv1a_32, std::unordered_multiset<int> >( 2270492092ul );
test< boost::hash2::fnv1a_64, std::unordered_multiset<int> >( 3232503781718511241ull );
return boost::report_errors();
}