78bb1d1571
0172df743 CMakeLists: Only add tests if MASTER_PROJECT 52e8dff62 0.1.11 fc8d745cc container: hmap fixups 5b5c0130d memory: Add overaligned_unique_ptr c7c9bbd17 mcl: Increment version to 0.1.10 678aa32a8 assert: Handle expr strings separately b38a9d2ef tests: Update to Catch 3.0.1 8aeacfe32 mcl: Increment version to 0.1.9 b468a2ab5 mcl: meta_byte: Split off meta_byte_group d3ae1ae47 mcl: ihmap: Implement inline variant of hmap 5cbfe6eed mcl: hmap: Split detail into headers ee7467677 mcl: hmap: Better default hash f1d902ce9 mcl: hash: Add xmrx 322a221f0 mcl: hmap: Bugfix skip_empty_or_tombstone 689f393f7 mcl: hmap: x64 implementation fa6ff746a mcl: hmap: Add generic meta_byte_group implementation 91e3073ad mcl: hmap: Add more member functions 4998335a5 mcl: Install only if master project 7ff4d2549 mcl: hmap prototype 416a2c6b5 mcl: clang-format: Adopt WebKit style bracing d5a46fa70 mcl/assert: Flush stderr e3b6cc79e externals: Update mcl to 0.1.7 190c68475 mcl: Build as PIC git-subtree-dir: externals/mcl git-subtree-split: 0172df74316351868c215f735e5a2538b10d71fb
42 lines
1.5 KiB
C++
42 lines
1.5 KiB
C++
// This file is part of the mcl project.
|
|
// Copyright (c) 2022 merryhime
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#include <array>
|
|
#include <tuple>
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
#include <mcl/bit/bit_field.hpp>
|
|
#include <mcl/stdint.hpp>
|
|
|
|
TEST_CASE("mcl::bit::ones", "[bit]")
|
|
{
|
|
const std::array cases{
|
|
std::make_tuple<size_t, u8>(0, 0x00),
|
|
std::make_tuple<size_t, u8>(1, 0x01),
|
|
std::make_tuple<size_t, u8>(2, 0x03),
|
|
std::make_tuple<size_t, u8>(3, 0x07),
|
|
std::make_tuple<size_t, u8>(4, 0x0f),
|
|
std::make_tuple<size_t, u8>(5, 0x1f),
|
|
std::make_tuple<size_t, u8>(6, 0x3f),
|
|
std::make_tuple<size_t, u8>(7, 0x7f),
|
|
std::make_tuple<size_t, u8>(8, 0xff),
|
|
};
|
|
|
|
for (const auto [count, expected] : cases) {
|
|
REQUIRE(mcl::bit::ones<u8>(count) == expected);
|
|
REQUIRE(mcl::bit::ones<u16>(count) == expected);
|
|
REQUIRE(mcl::bit::ones<u32>(count) == expected);
|
|
REQUIRE(mcl::bit::ones<u64>(count) == expected);
|
|
REQUIRE(mcl::bit::ones<uptr>(count) == expected);
|
|
REQUIRE(mcl::bit::ones<size_t>(count) == expected);
|
|
}
|
|
}
|
|
|
|
static_assert(mcl::bit::ones<3, u8>() == 0x7);
|
|
static_assert(mcl::bit::ones<15, u16>() == 0x7fff);
|
|
static_assert(mcl::bit::ones<16, u16>() == 0xffff);
|
|
static_assert(mcl::bit::ones<31, u32>() == 0x7fff'ffff);
|
|
static_assert(mcl::bit::ones<32, u32>() == 0xffff'ffff);
|
|
static_assert(mcl::bit::ones<63, u64>() == 0x7fff'ffff'ffff'ffff);
|
|
static_assert(mcl::bit::ones<64, u64>() == 0xffff'ffff'ffff'ffff);
|