Skip to content

Commit

Permalink
Add test/detail_rot.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Oct 25, 2024
1 parent 8742497 commit 3e60ca1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ run get_integral_result.cpp ;

run detail_read.cpp ;
run detail_write.cpp ;
run detail_rot.cpp ;

# hash_append

Expand Down
34 changes: 34 additions & 0 deletions test/detail_rot.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2024 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/hash2/detail/rot.hpp>
#include <boost/core/lightweight_test.hpp>
#include <array>

int main()
{
using namespace boost::hash2::detail;

{
std::uint32_t v = 0x9e3779b9;

for( int k = 1; k < 32; ++k )
{
BOOST_TEST_EQ( rotl( v, k ), ( v << k ) + ( v >> ( 32 - k ) ) );
BOOST_TEST_EQ( rotr( v, k ), ( v >> k ) + ( v << ( 32 - k ) ) );
}
}

{
std::uint64_t v = 0x9e3779b97f4a7c15;

for( int k = 1; k < 64; ++k )
{
BOOST_TEST_EQ( rotl( v, k ), ( v << k ) + ( v >> ( 64 - k ) ) );
BOOST_TEST_EQ( rotr( v, k ), ( v >> k ) + ( v << ( 64 - k ) ) );
}
}

return boost::report_errors();
}

0 comments on commit 3e60ca1

Please sign in to comment.