Headers move, CMake targets merge, C++ namespaces stay unchanged: - Core: Scope, Lazy, Counted, Flags, Hash, Bits, Uuid, TypeList, TypeMap, Variant - Functional: Pipeline, Either, Result, Retry - Containers: Ring, Pool, PriorityQueue, LRU, Trie, Graph, DisjointSet, Bitset, Interval - Math: +Matrix, Numeric, Random, Histogram - Text: Str, Format, Tokenizer, Diff, Encoding, Semver - Data: Json, Csv, Ini - Async: Coro, Concurrency, EventBus, Observable - Time: +Bench - Log: Log facade + Logging framework (facade now header-only, breaking the Stacktrace<->Log link cycle the merge would have created) - System: FileSystem + Process - Configuration: +Argparse - Unchanged: Stacktrace, Plugin, StateMachine, Testing, TestingMock, Detail Module system fixes: - OPTIONAL_DEPS resolution deferred to void_finalize_modules() so it no longer depends on the alphabetical discovery order of src/ subdirs (Testing -> Text would have been silently dropped). - Every header-only module now has a tracked module.cmake; previously the empty src/<Name> marker dirs were untracked, so a fresh clone would have silently skipped those modules. - VOID_HAS_LOGGING/CONCURRENCY/STR consumers renamed to LOG/ASYNC/TEXT. Tests move to tests/standalone/<Umbrella>/<Feature>.cpp (Result suite files prefixed: ResultBasic etc.). Test count verified identical (831) before and after. README/CLAUDE.md module tables updated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
199 lines
5.5 KiB
C++
199 lines
5.5 KiB
C++
#include <Void/Containers/Bitset.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <string>
|
|
|
|
using namespace Void::Bitset;
|
|
|
|
// ── basic operations ──────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test bitset_default_all_clear()
|
|
{
|
|
const Bitset<8> b;
|
|
Void::Testing::expect(b.none());
|
|
Void::Testing::expect_eq(b.count(), std::size_t{0});
|
|
}
|
|
|
|
Void::Testing::Test bitset_set_and_test()
|
|
{
|
|
Bitset<16> b;
|
|
b.set(0);
|
|
b.set(7);
|
|
b.set(15);
|
|
Void::Testing::expect(b.test(0));
|
|
Void::Testing::expect(b.test(7));
|
|
Void::Testing::expect(b.test(15));
|
|
Void::Testing::expect(!b.test(1));
|
|
Void::Testing::expect_eq(b.count(), std::size_t{3});
|
|
}
|
|
|
|
Void::Testing::Test bitset_reset_clears_bit()
|
|
{
|
|
Bitset<8> b;
|
|
b.set(3);
|
|
Void::Testing::expect(b.test(3));
|
|
b.reset(3);
|
|
Void::Testing::expect(!b.test(3));
|
|
}
|
|
|
|
Void::Testing::Test bitset_flip()
|
|
{
|
|
Bitset<8> b;
|
|
b.set(5);
|
|
b.flip(5);
|
|
Void::Testing::expect(!b.test(5));
|
|
b.flip(5);
|
|
Void::Testing::expect(b.test(5));
|
|
}
|
|
|
|
Void::Testing::Test bitset_set_all_and_reset_all()
|
|
{
|
|
Bitset<64> b;
|
|
b.set_all();
|
|
Void::Testing::expect(b.all());
|
|
Void::Testing::expect_eq(b.count(), std::size_t{64});
|
|
b.reset_all();
|
|
Void::Testing::expect(b.none());
|
|
}
|
|
|
|
Void::Testing::Test bitset_flip_all()
|
|
{
|
|
Bitset<8> b;
|
|
b.set(0); b.set(2); b.set(4);
|
|
b.flip_all();
|
|
Void::Testing::expect(!b.test(0));
|
|
Void::Testing::expect(b.test(1));
|
|
Void::Testing::expect_eq(b.count(), std::size_t{5});
|
|
}
|
|
|
|
Void::Testing::Test bitset_out_of_range_throws()
|
|
{
|
|
Bitset<8> b;
|
|
bool threw = false;
|
|
try { b.set(8); } catch (...) { threw = true; }
|
|
Void::Testing::expect(threw);
|
|
}
|
|
|
|
// ── multi-word (N > 64) ───────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test bitset_large_set_and_test()
|
|
{
|
|
Bitset<128> b;
|
|
b.set(63);
|
|
b.set(64);
|
|
b.set(127);
|
|
Void::Testing::expect(b.test(63));
|
|
Void::Testing::expect(b.test(64));
|
|
Void::Testing::expect(b.test(127));
|
|
Void::Testing::expect_eq(b.count(), std::size_t{3});
|
|
}
|
|
|
|
// ── bitwise ops ───────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test bitset_and()
|
|
{
|
|
Bitset<8> a, b;
|
|
a.set(0); a.set(1);
|
|
b.set(1); b.set(2);
|
|
const auto c = a & b;
|
|
Void::Testing::expect(!c.test(0));
|
|
Void::Testing::expect(c.test(1));
|
|
Void::Testing::expect(!c.test(2));
|
|
}
|
|
|
|
Void::Testing::Test bitset_or()
|
|
{
|
|
Bitset<8> a, b;
|
|
a.set(0); b.set(1);
|
|
const auto c = a | b;
|
|
Void::Testing::expect(c.test(0));
|
|
Void::Testing::expect(c.test(1));
|
|
}
|
|
|
|
Void::Testing::Test bitset_xor()
|
|
{
|
|
Bitset<8> a, b;
|
|
a.set(0); a.set(1);
|
|
b.set(1); b.set(2);
|
|
const auto c = a ^ b;
|
|
Void::Testing::expect(c.test(0));
|
|
Void::Testing::expect(!c.test(1));
|
|
Void::Testing::expect(c.test(2));
|
|
}
|
|
|
|
Void::Testing::Test bitset_not()
|
|
{
|
|
Bitset<8> a;
|
|
a.set(0);
|
|
const auto b = ~a;
|
|
Void::Testing::expect(!b.test(0));
|
|
Void::Testing::expect(b.test(1));
|
|
Void::Testing::expect_eq(b.count(), std::size_t{7});
|
|
}
|
|
|
|
// ── shift ─────────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test bitset_shift_left()
|
|
{
|
|
Bitset<8> b;
|
|
b.set(0);
|
|
const auto s = b << 3;
|
|
Void::Testing::expect(!s.test(0));
|
|
Void::Testing::expect(s.test(3));
|
|
}
|
|
|
|
Void::Testing::Test bitset_shift_right()
|
|
{
|
|
Bitset<8> b;
|
|
b.set(5);
|
|
const auto s = b >> 2;
|
|
Void::Testing::expect(!s.test(5));
|
|
Void::Testing::expect(s.test(3));
|
|
}
|
|
|
|
// ── to_string ─────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test bitset_to_string()
|
|
{
|
|
Bitset<8> b;
|
|
b.set(0); // LSB → rightmost in string
|
|
const auto s = b.to_string();
|
|
Void::Testing::expect_eq(s.size(), std::size_t{8});
|
|
Void::Testing::expect_eq(s[7], '1'); // bit 0 is rightmost
|
|
Void::Testing::expect_eq(s[0], '0');
|
|
}
|
|
|
|
Void::Testing::Test bitset_to_string_all_set()
|
|
{
|
|
Bitset<4> b;
|
|
b.set_all();
|
|
Void::Testing::expect_eq(b.to_string(), std::string{"1111"});
|
|
}
|
|
|
|
// ── find_first ────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test bitset_find_first_set()
|
|
{
|
|
Bitset<64> b;
|
|
b.set(5);
|
|
b.set(10);
|
|
Void::Testing::expect_eq(b.find_first(), std::size_t{5});
|
|
}
|
|
|
|
Void::Testing::Test bitset_find_first_none()
|
|
{
|
|
const Bitset<64> b;
|
|
Void::Testing::expect_eq(b.find_first(), std::size_t{64}); // sentinel
|
|
}
|
|
|
|
// ── equality ──────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test bitset_equality()
|
|
{
|
|
Bitset<8> a, b, c;
|
|
a.set(3); b.set(3); c.set(4);
|
|
Void::Testing::expect(a == b);
|
|
Void::Testing::expect(a != c);
|
|
}
|