Utilities - Hash combining helper
This commit is contained in:
parent
90cf63c592
commit
3889efde67
3 changed files with 35 additions and 0 deletions
tests
|
@ -13,6 +13,7 @@ class ComputeHashTest : public CppUnit::TestFixture
|
|||
CPPUNIT_TEST( testInt32 );
|
||||
CPPUNIT_TEST( testInt64 );
|
||||
CPPUNIT_TEST( testStructDefault );
|
||||
CPPUNIT_TEST( testPair );
|
||||
CPPUNIT_TEST_SUITE_END( );
|
||||
|
||||
public:
|
||||
|
@ -21,6 +22,7 @@ public:
|
|||
void testInt32( );
|
||||
void testInt64( );
|
||||
void testStructDefault( );
|
||||
void testPair( );
|
||||
};
|
||||
|
||||
|
||||
|
@ -74,3 +76,13 @@ void ComputeHashTest::testStructDefault( )
|
|||
CPPUNIT_ASSERT_EQUAL( uint32_t( HashData( test.meh , 16 ) ) ,
|
||||
ComputeHash( test ) );
|
||||
}
|
||||
|
||||
void ComputeHashTest::testPair( )
|
||||
{
|
||||
auto p{ std::make_pair< uint8_t , uint32_t >( 12 , 128 ) };
|
||||
|
||||
uint32_t hv = 0x9e3779b9 + 12;
|
||||
hv = 128 + 0x9e3779b9 + ( hv << 6 ) + ( hv >> 2 );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( hv , ComputeHash( p ) );
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue