mirror of
https://github.com/boostorg/core.git
synced 2025-07-29 12:27:42 +02:00
Add constexpr tests for bit.hpp. Refs #109.
This commit is contained in:
@ -300,6 +300,15 @@ run bit_endian_test.cpp
|
||||
compile-fail bit_width_fail.cpp
|
||||
: <warnings>off ;
|
||||
|
||||
compile bit_rotate_test_cx.cpp ;
|
||||
compile bit_countr_test_cx.cpp ;
|
||||
compile bit_countl_test_cx.cpp ;
|
||||
compile bit_width_test_cx.cpp ;
|
||||
compile has_single_bit_test_cx.cpp ;
|
||||
compile bit_floor_test_cx.cpp ;
|
||||
compile bit_ceil_test_cx.cpp ;
|
||||
compile bit_popcount_test_cx.cpp ;
|
||||
|
||||
run type_name_test.cpp ;
|
||||
|
||||
run snprintf_test.cpp ;
|
||||
|
26
test/bit_ceil_test_cx.cpp
Normal file
26
test/bit_ceil_test_cx.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
// constexpr test for boost/core/bit.hpp (bit_ceil)
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/core/bit.hpp>
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
STATIC_ASSERT( boost::core::bit_ceil( (unsigned char)0x74 ) == 0x80 );
|
||||
STATIC_ASSERT( boost::core::bit_ceil( (unsigned short)0x7400 ) == 0x8000 );
|
||||
STATIC_ASSERT( boost::core::bit_ceil( 0x740000u ) == 0x800000u );
|
||||
STATIC_ASSERT( boost::core::bit_ceil( 0x74000000ul ) == 0x80000000ul );
|
||||
STATIC_ASSERT( boost::core::bit_ceil( 0x7400000000ull ) == 0x8000000000ull );
|
||||
|
||||
#endif
|
33
test/bit_countl_test_cx.cpp
Normal file
33
test/bit_countl_test_cx.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
// constexpr test for boost/core/bit.hpp (countl_zero, countl_one)
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/core/bit.hpp>
|
||||
#include <climits>
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
STATIC_ASSERT( boost::core::countl_zero( (unsigned char)0x1F ) == CHAR_BIT - 5 );
|
||||
STATIC_ASSERT( boost::core::countl_zero( (unsigned short)0x1F ) == sizeof(unsigned short) * CHAR_BIT - 5 );
|
||||
STATIC_ASSERT( boost::core::countl_zero( 0x1Fu ) == sizeof(unsigned int) * CHAR_BIT - 5 );
|
||||
STATIC_ASSERT( boost::core::countl_zero( 0x1Ful ) == sizeof(unsigned long) * CHAR_BIT - 5 );
|
||||
STATIC_ASSERT( boost::core::countl_zero( 0x1Full ) == sizeof(unsigned long long) * CHAR_BIT - 5 );
|
||||
|
||||
STATIC_ASSERT( boost::core::countl_one( (unsigned char)~0x1Fu ) == CHAR_BIT - 5 );
|
||||
STATIC_ASSERT( boost::core::countl_one( (unsigned short)~0x1Fu ) == sizeof(unsigned short) * CHAR_BIT - 5 );
|
||||
STATIC_ASSERT( boost::core::countl_one( ~0x1Fu ) == sizeof(unsigned int) * CHAR_BIT - 5 );
|
||||
STATIC_ASSERT( boost::core::countl_one( ~0x1Ful ) == sizeof(unsigned long) * CHAR_BIT - 5 );
|
||||
STATIC_ASSERT( boost::core::countl_one( ~0x1Full ) == sizeof(unsigned long long) * CHAR_BIT - 5 );
|
||||
|
||||
#endif
|
33
test/bit_countr_test_cx.cpp
Normal file
33
test/bit_countr_test_cx.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
// constexpr test for boost/core/bit.hpp (countr_zero, countr_one)
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/core/bit.hpp>
|
||||
#include <climits>
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
STATIC_ASSERT( boost::core::countr_zero( (unsigned char)0xF8 ) == 3 );
|
||||
STATIC_ASSERT( boost::core::countr_zero( (unsigned short)0xF800 ) == 11 );
|
||||
STATIC_ASSERT( boost::core::countr_zero( 0xF80000u ) == 19 );
|
||||
STATIC_ASSERT( boost::core::countr_zero( 0xF8000000ul ) == 27 );
|
||||
STATIC_ASSERT( boost::core::countr_zero( 0xF800000000ull ) == 35 );
|
||||
|
||||
STATIC_ASSERT( boost::core::countr_one( (unsigned char)~0xF8u ) == 3 );
|
||||
STATIC_ASSERT( boost::core::countr_one( (unsigned short)~0xF800u ) == 11 );
|
||||
STATIC_ASSERT( boost::core::countr_one( ~0xF80000u ) == 19 );
|
||||
STATIC_ASSERT( boost::core::countr_one( ~0xF8000000ul ) == 27 );
|
||||
STATIC_ASSERT( boost::core::countr_one( ~0xF800000000ull ) == 35 );
|
||||
|
||||
#endif
|
26
test/bit_floor_test_cx.cpp
Normal file
26
test/bit_floor_test_cx.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
// constexpr test for boost/core/bit.hpp (bit_floor)
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/core/bit.hpp>
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
STATIC_ASSERT( boost::core::bit_floor( (unsigned char)0x74 ) == 0x40 );
|
||||
STATIC_ASSERT( boost::core::bit_floor( (unsigned short)0x7400 ) == 0x4000 );
|
||||
STATIC_ASSERT( boost::core::bit_floor( 0x740000u ) == 0x400000u );
|
||||
STATIC_ASSERT( boost::core::bit_floor( 0x74000000ul ) == 0x40000000ul );
|
||||
STATIC_ASSERT( boost::core::bit_floor( 0x7400000000ull ) == 0x4000000000ull );
|
||||
|
||||
#endif
|
@ -1,4 +1,4 @@
|
||||
// Test for boost/core/bit.hpp (bit_ceil)
|
||||
// Test for boost/core/bit.hpp (popcount)
|
||||
//
|
||||
// Copyright 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
|
26
test/bit_popcount_test_cx.cpp
Normal file
26
test/bit_popcount_test_cx.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
// constexpr test for boost/core/bit.hpp (popcount)
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/core/bit.hpp>
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
STATIC_ASSERT( boost::core::popcount( (unsigned char)0x74 ) == 4 );
|
||||
STATIC_ASSERT( boost::core::popcount( (unsigned short)0x7400 ) == 4 );
|
||||
STATIC_ASSERT( boost::core::popcount( 0x740000u ) == 4 );
|
||||
STATIC_ASSERT( boost::core::popcount( 0x74000000ul ) == 4 );
|
||||
STATIC_ASSERT( boost::core::popcount( 0x7400000000ull ) == 4 );
|
||||
|
||||
#endif
|
33
test/bit_rotate_test_cx.cpp
Normal file
33
test/bit_rotate_test_cx.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
// constexpr test for boost/core/bit.hpp (rotl, rotr)
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/core/bit.hpp>
|
||||
#include <cstdint>
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
STATIC_ASSERT( boost::core::rotl( (std::uint8_t)0x11, 1 ) == 0x22 );
|
||||
STATIC_ASSERT( boost::core::rotr( (std::uint8_t)0x11, 1 ) == 0x88 );
|
||||
|
||||
STATIC_ASSERT( boost::core::rotl( (std::uint16_t)0x1111, 1 ) == 0x2222 );
|
||||
STATIC_ASSERT( boost::core::rotr( (std::uint16_t)0x1111, 1 ) == 0x8888 );
|
||||
|
||||
STATIC_ASSERT( boost::core::rotl( (std::uint32_t)0x11111111, 1 ) == 0x22222222 );
|
||||
STATIC_ASSERT( boost::core::rotr( (std::uint32_t)0x11111111, 1 ) == 0x88888888 );
|
||||
|
||||
STATIC_ASSERT( boost::core::rotl( (std::uint64_t)0x1111111111111111, 1 ) == 0x2222222222222222 );
|
||||
STATIC_ASSERT( boost::core::rotr( (std::uint64_t)0x1111111111111111, 1 ) == 0x8888888888888888 );
|
||||
|
||||
#endif
|
26
test/bit_width_test_cx.cpp
Normal file
26
test/bit_width_test_cx.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
// constexpr test for boost/core/bit.hpp (bit_width)
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/core/bit.hpp>
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
STATIC_ASSERT( boost::core::bit_width( (unsigned char)0x74 ) == 7 );
|
||||
STATIC_ASSERT( boost::core::bit_width( (unsigned short)0x7400 ) == 15 );
|
||||
STATIC_ASSERT( boost::core::bit_width( 0x740000u ) == 23 );
|
||||
STATIC_ASSERT( boost::core::bit_width( 0x74000000ul ) == 31 );
|
||||
STATIC_ASSERT( boost::core::bit_width( 0x7400000000ull ) == 39 );
|
||||
|
||||
#endif
|
35
test/has_single_bit_test_cx.cpp
Normal file
35
test/has_single_bit_test_cx.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
// constexpr test for boost/core/bit.hpp (has_single_bit)
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/core/bit.hpp>
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
STATIC_ASSERT( boost::core::has_single_bit( (unsigned char)0x80 ) == true );
|
||||
STATIC_ASSERT( boost::core::has_single_bit( (unsigned char)0x90 ) == false );
|
||||
|
||||
STATIC_ASSERT( boost::core::has_single_bit( (unsigned short)0x8000 ) == true );
|
||||
STATIC_ASSERT( boost::core::has_single_bit( (unsigned short)0x9000 ) == false );
|
||||
|
||||
STATIC_ASSERT( boost::core::has_single_bit( 0x800000u ) == true );
|
||||
STATIC_ASSERT( boost::core::has_single_bit( 0x900000u ) == false );
|
||||
|
||||
STATIC_ASSERT( boost::core::has_single_bit( 0x80000000ul ) == true );
|
||||
STATIC_ASSERT( boost::core::has_single_bit( 0x90000000ul ) == false );
|
||||
|
||||
STATIC_ASSERT( boost::core::has_single_bit( 0x8000000000ull ) == true );
|
||||
STATIC_ASSERT( boost::core::has_single_bit( 0x9000000000ull ) == false );
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user