2
0
mirror of https://github.com/boostorg/hash2.git synced 2026-01-19 16:22:15 +00:00
Files
hash2/test/append_set.cpp

80 lines
1.8 KiB
C++

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