New header-only modules: - Void::Hash — FNV-1a 32/64, CRC-32, DJB2, MurmurHash3-32, UDL literals - Void::Random — Xoshiro256** PRNG, uniform_int/real, coin_flip, shuffle, random_string - Void::Uuid — v4 (random), v5_lite (name-based), parse, RFC 4122 namespaces - Void::Encoding — Base64 (standard + URL-safe), Hex encode/decode - Void::Bits — popcount, bit extract/deposit, rotation, align, byteswap, masks - Void::Math — Vec2/Vec3/Vec4, Mat4 (identity, translation, scale, rotation) Testing module: move Stacktrace from INTERNAL_DEPS to OPTIONAL_DEPS. Added Detail/Color.hpp shim that delegates to Stacktrace::Color when present or provides inline ANSI fallback otherwise. All Stacktrace calls in SignalHandler, ConsoleReporter, and Runner are gated on VOID_HAS_STACKTRACE. Fix Repr.hpp reflect_struct to handle template specializations that lack std::meta::identifier_of (now guarded by has_identifier check). 33/33 tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
139 lines
4.8 KiB
C++
139 lines
4.8 KiB
C++
#include <Void/Bits/Bits.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <cstdint>
|
|
|
|
// ── popcount ──────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test popcount_zero()
|
|
{
|
|
Void::Testing::expect_eq(Void::Bits::popcount(0u), 0);
|
|
}
|
|
|
|
Void::Testing::Test popcount_all_ones_u8()
|
|
{
|
|
Void::Testing::expect_eq(Void::Bits::popcount(std::uint8_t{0xFF}), 8);
|
|
}
|
|
|
|
Void::Testing::Test popcount_u32()
|
|
{
|
|
Void::Testing::expect_eq(Void::Bits::popcount(std::uint32_t{0x0F0F0F0F}), 16);
|
|
}
|
|
|
|
// ── test/set/clear/toggle ────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test test_bit_set()
|
|
{
|
|
Void::Testing::expect(Void::Bits::test_bit(std::uint8_t{0b00000100u}, 2));
|
|
}
|
|
|
|
Void::Testing::Test test_bit_clear()
|
|
{
|
|
Void::Testing::expect(!Void::Bits::test_bit(std::uint8_t{0b00000100u}, 0));
|
|
}
|
|
|
|
Void::Testing::Test set_bit_works()
|
|
{
|
|
Void::Testing::expect_eq(Void::Bits::set_bit(std::uint8_t{0u}, 3),
|
|
std::uint8_t{0b00001000u});
|
|
}
|
|
|
|
Void::Testing::Test clear_bit_works()
|
|
{
|
|
Void::Testing::expect_eq(Void::Bits::clear_bit(std::uint8_t{0xFF}, 3),
|
|
std::uint8_t{0b11110111u});
|
|
}
|
|
|
|
Void::Testing::Test toggle_bit_works()
|
|
{
|
|
Void::Testing::expect_eq(Void::Bits::toggle_bit(std::uint8_t{0u}, 5),
|
|
std::uint8_t{0b00100000u});
|
|
}
|
|
|
|
// ── extract / deposit ─────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test extract_bits_works()
|
|
{
|
|
// bits 4-7 of 0b10110100 = 0b1011
|
|
Void::Testing::expect_eq(
|
|
Void::Bits::extract_bits(std::uint8_t{0b10110100u}, 4, 4),
|
|
std::uint8_t{0b1011u});
|
|
}
|
|
|
|
Void::Testing::Test deposit_bits_works()
|
|
{
|
|
// deposit 0b1010 into bits 4-7 of 0x00
|
|
Void::Testing::expect_eq(
|
|
Void::Bits::deposit_bits(std::uint8_t{0u}, std::uint8_t{0b1010u}, 4, 4),
|
|
std::uint8_t{0b10100000u});
|
|
}
|
|
|
|
// ── rotation ─────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test rotl_8()
|
|
{
|
|
Void::Testing::expect_eq(Void::Bits::rotl(std::uint8_t{0b10000001u}, 1),
|
|
std::uint8_t{0b00000011u});
|
|
}
|
|
|
|
Void::Testing::Test rotr_8()
|
|
{
|
|
Void::Testing::expect_eq(Void::Bits::rotr(std::uint8_t{0b10000001u}, 1),
|
|
std::uint8_t{0b11000000u});
|
|
}
|
|
|
|
// ── pow2 helpers ──────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test has_single_bit()
|
|
{
|
|
Void::Testing::expect(Void::Bits::has_single_bit(64u));
|
|
Void::Testing::expect(!Void::Bits::has_single_bit(63u));
|
|
}
|
|
|
|
Void::Testing::Test ceil_pow2_works()
|
|
{
|
|
Void::Testing::expect_eq(Void::Bits::ceil_pow2(5u), 8u);
|
|
Void::Testing::expect_eq(Void::Bits::ceil_pow2(8u), 8u);
|
|
}
|
|
|
|
Void::Testing::Test floor_pow2_works()
|
|
{
|
|
Void::Testing::expect_eq(Void::Bits::floor_pow2(5u), 4u);
|
|
}
|
|
|
|
// ── align ────────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test align_up_works()
|
|
{
|
|
Void::Testing::expect_eq(Void::Bits::align_up(13u, 8u), 16u);
|
|
Void::Testing::expect_eq(Void::Bits::align_up(8u, 8u), 8u);
|
|
}
|
|
|
|
Void::Testing::Test align_down_works()
|
|
{
|
|
Void::Testing::expect_eq(Void::Bits::align_down(13u, 8u), 8u);
|
|
}
|
|
|
|
// ── masks ────────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test low_mask_works()
|
|
{
|
|
Void::Testing::expect_eq(Void::Bits::low_mask<std::uint8_t>(4),
|
|
std::uint8_t{0x0F});
|
|
}
|
|
|
|
Void::Testing::Test range_mask_works()
|
|
{
|
|
Void::Testing::expect_eq(Void::Bits::range_mask<std::uint8_t>(2, 5),
|
|
std::uint8_t{0b00111100u});
|
|
}
|
|
|
|
// ── byteswap / endian ────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test byteswap_u32()
|
|
{
|
|
Void::Testing::expect_eq(Void::Bits::byteswap(std::uint32_t{0x12345678u}),
|
|
std::uint32_t{0x78563412u});
|
|
}
|