-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change test/get_integral_result.cpp to only test whether invocations …
…compile, and not the exact output values
- Loading branch information
Showing
1 changed file
with
48 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,65 @@ | ||
// Copyright 2017, 2018 Peter Dimov. | ||
// Copyright 2017, 2018, 2024 Peter Dimov | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <boost/hash2/get_integral_result.hpp> | ||
#include <boost/core/lightweight_test.hpp> | ||
#include <cstdint> | ||
#include <boost/hash2/digest.hpp> | ||
#include <boost/array.hpp> | ||
#include <array> | ||
#include <cstddef> | ||
|
||
int main() | ||
template<class R> void test() | ||
{ | ||
using boost::hash2::get_integral_result; | ||
|
||
{ | ||
std::uint32_t u32 = 0x12345678; | ||
|
||
BOOST_TEST_EQ( get_integral_result<std::uint8_t>( u32 ), 0x78 ); | ||
BOOST_TEST_EQ( get_integral_result<std::int8_t>( u32 ), 0x78 ); | ||
BOOST_TEST_EQ( get_integral_result<std::uint16_t>( u32 ), 0x5678 ); | ||
BOOST_TEST_EQ( get_integral_result<std::int16_t>( u32 ), 0x5678 ); | ||
BOOST_TEST_EQ( get_integral_result<std::uint32_t>( u32 ), 0x12345678 ); | ||
BOOST_TEST_EQ( get_integral_result<std::int32_t>( u32 ), 0x12345678 ); | ||
BOOST_TEST_EQ( get_integral_result<std::uint64_t>( u32 ), 0x1234567812345678ull ); | ||
BOOST_TEST_EQ( get_integral_result<std::int64_t>( u32 ), 0x1234567812345678ull ); | ||
} | ||
|
||
{ | ||
std::uint32_t s32 = 0xFFFFFFFFu; | ||
|
||
BOOST_TEST_EQ( get_integral_result<std::uint8_t>( s32 ), 0xFF ); | ||
BOOST_TEST_EQ( get_integral_result<std::int8_t>( s32 ), -1 ); | ||
BOOST_TEST_EQ( get_integral_result<std::uint16_t>( s32 ), 0xFFFF ); | ||
BOOST_TEST_EQ( get_integral_result<std::int16_t>( s32 ), -1 ); | ||
BOOST_TEST_EQ( get_integral_result<std::uint32_t>( s32 ), 0xFFFFFFFFu ); | ||
BOOST_TEST_EQ( get_integral_result<std::int32_t>( s32 ), -1 ); | ||
BOOST_TEST_EQ( get_integral_result<std::uint64_t>( s32 ), 0xFFFFFFFFFFFFFFFFull ); | ||
BOOST_TEST_EQ( get_integral_result<std::int64_t>( s32 ), -1 ); | ||
} | ||
|
||
{ | ||
std::uint64_t u64 = 0x0123456789ABCDEFull; | ||
R r = {}; | ||
|
||
BOOST_TEST_EQ( get_integral_result<std::uint8_t>( u64 ), 0xEF ); | ||
BOOST_TEST_EQ( get_integral_result<std::int8_t>( u64 ), -0x11 ); | ||
BOOST_TEST_EQ( get_integral_result<std::uint16_t>( u64 ), 0xCDEF ); | ||
BOOST_TEST_EQ( get_integral_result<std::int16_t>( u64 ), -0x3211 ); | ||
BOOST_TEST_EQ( get_integral_result<std::uint32_t>( u64 ), 0x89ABCDEF ); | ||
BOOST_TEST_EQ( get_integral_result<std::int32_t>( u64 ), 0x89ABCDEF ); | ||
BOOST_TEST_EQ( get_integral_result<std::uint64_t>( u64 ), 0x0123456789ABCDEFull ); | ||
BOOST_TEST_EQ( get_integral_result<std::int64_t>( u64 ), 0x0123456789ABCDEFull ); | ||
} | ||
get_integral_result<signed char>( r ); | ||
get_integral_result<unsigned char>( r ); | ||
get_integral_result<short>( r ); | ||
get_integral_result<unsigned short>( r ); | ||
get_integral_result<int>( r ); | ||
get_integral_result<unsigned int>( r ); | ||
get_integral_result<long>( r ); | ||
get_integral_result<unsigned long>( r ); | ||
get_integral_result<long long>( r ); | ||
get_integral_result<unsigned long long>( r ); | ||
|
||
{ | ||
std::uint64_t s64 = 0xFFFFFFFFFFFFFFFFull; | ||
|
||
BOOST_TEST_EQ( get_integral_result<std::uint8_t>( s64 ), 0xFF ); | ||
BOOST_TEST_EQ( get_integral_result<std::int8_t>( s64 ), -1 ); | ||
BOOST_TEST_EQ( get_integral_result<std::uint16_t>( s64 ), 0xFFFF ); | ||
BOOST_TEST_EQ( get_integral_result<std::int16_t>( s64 ), -1 ); | ||
BOOST_TEST_EQ( get_integral_result<std::uint32_t>( s64 ), 0xFFFFFFFFu ); | ||
BOOST_TEST_EQ( get_integral_result<std::int32_t>( s64 ), -1 ); | ||
BOOST_TEST_EQ( get_integral_result<std::uint64_t>( s64 ), 0xFFFFFFFFFFFFFFFFull ); | ||
BOOST_TEST_EQ( get_integral_result<std::int64_t>( s64 ), -1 ); | ||
} | ||
get_integral_result<char>( r ); | ||
get_integral_result<char16_t>( r ); | ||
get_integral_result<char32_t>( r ); | ||
} | ||
|
||
{ | ||
std::array<unsigned char, 8> a64 = {{ 0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01 }}; | ||
int main() | ||
{ | ||
using boost::hash2::get_integral_result; | ||
|
||
BOOST_TEST_EQ( get_integral_result<std::uint8_t>( a64 ), 0xEF ); | ||
BOOST_TEST_EQ( get_integral_result<std::int8_t>( a64 ), -0x11 ); | ||
BOOST_TEST_EQ( get_integral_result<std::uint16_t>( a64 ), 0xCDEF ); | ||
BOOST_TEST_EQ( get_integral_result<std::int16_t>( a64 ), -0x3211 ); | ||
BOOST_TEST_EQ( get_integral_result<std::uint32_t>( a64 ), 0x89ABCDEF ); | ||
BOOST_TEST_EQ( get_integral_result<std::int32_t>( a64 ), 0x89ABCDEF ); | ||
BOOST_TEST_EQ( get_integral_result<std::uint64_t>( a64 ), 0x0123456789ABCDEFull ); | ||
BOOST_TEST_EQ( get_integral_result<std::int64_t>( a64 ), 0x0123456789ABCDEFull ); | ||
} | ||
test<unsigned char>(); | ||
test<unsigned short>(); | ||
test<unsigned int>(); | ||
test<unsigned long>(); | ||
test<unsigned long long>(); | ||
|
||
{ | ||
std::array<unsigned char, 8> b64 = {{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }}; | ||
test< std::array<unsigned char, 8> >(); | ||
test< std::array<unsigned char, 16> >(); | ||
test< std::array<unsigned char, 20> >(); | ||
test< std::array<unsigned char, 28> >(); | ||
test< std::array<unsigned char, 32> >(); | ||
test< std::array<unsigned char, 48> >(); | ||
test< std::array<unsigned char, 64> >(); | ||
|
||
BOOST_TEST_EQ( get_integral_result<std::uint8_t>( b64 ), 0xFF ); | ||
BOOST_TEST_EQ( get_integral_result<std::int8_t>( b64 ), -1 ); | ||
BOOST_TEST_EQ( get_integral_result<std::uint16_t>( b64 ), 0xFFFF ); | ||
BOOST_TEST_EQ( get_integral_result<std::int16_t>( b64 ), -1 ); | ||
BOOST_TEST_EQ( get_integral_result<std::uint32_t>( b64 ), 0xFFFFFFFFu ); | ||
BOOST_TEST_EQ( get_integral_result<std::int32_t>( b64 ), -1 ); | ||
BOOST_TEST_EQ( get_integral_result<std::uint64_t>( b64 ), 0xFFFFFFFFFFFFFFFFull ); | ||
BOOST_TEST_EQ( get_integral_result<std::int64_t>( b64 ), -1 ); | ||
} | ||
test< boost::array<unsigned char, 8> >(); | ||
test< boost::array<unsigned char, 16> >(); | ||
test< boost::array<unsigned char, 20> >(); | ||
test< boost::array<unsigned char, 28> >(); | ||
test< boost::array<unsigned char, 32> >(); | ||
test< boost::array<unsigned char, 48> >(); | ||
test< boost::array<unsigned char, 64> >(); | ||
|
||
return boost::report_errors(); | ||
test< boost::hash2::digest<8> >(); | ||
test< boost::hash2::digest<16> >(); | ||
test< boost::hash2::digest<20> >(); | ||
test< boost::hash2::digest<28> >(); | ||
test< boost::hash2::digest<32> >(); | ||
test< boost::hash2::digest<48> >(); | ||
test< boost::hash2::digest<64> >(); | ||
} |