Files
faumarayandClaude Fable 5 28b94883fd Restructure into umbrella modules (~55 -> 16 targets)
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>
2026-06-12 18:50:02 +03:00

147 lines
4.3 KiB
C++

#include <Void/Containers/Trie.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <algorithm>
#include <string>
#include <vector>
using BoolTrie = Void::Trie::Trie<bool>;
using IntTrie = Void::Trie::Trie<int>;
// ── insert / contains ─────────────────────────────────────────────────────────
Void::Testing::Test trie_insert_and_contains()
{
BoolTrie t;
t.insert("hello");
Void::Testing::expect(t.contains("hello"));
}
Void::Testing::Test trie_does_not_contain_prefix_only()
{
BoolTrie t;
t.insert("hello");
Void::Testing::expect(!t.contains("hell"));
}
Void::Testing::Test trie_does_not_contain_extension()
{
BoolTrie t;
t.insert("hell");
Void::Testing::expect(!t.contains("hello"));
}
Void::Testing::Test trie_insert_empty_key()
{
BoolTrie t;
t.insert("");
Void::Testing::expect(t.contains(""));
}
Void::Testing::Test trie_multiple_words()
{
BoolTrie t;
t.insert("car");
t.insert("card");
t.insert("care");
Void::Testing::expect(t.contains("car"));
Void::Testing::expect(t.contains("card"));
Void::Testing::expect(t.contains("care"));
Void::Testing::expect(!t.contains("ca"));
}
// ── get ───────────────────────────────────────────────────────────────────────
Void::Testing::Test trie_get_value()
{
IntTrie t;
t.insert("key", 42);
const auto v = t.get("key");
Void::Testing::expect(v.has_value());
Void::Testing::expect_eq(*v, 42);
}
Void::Testing::Test trie_get_missing_returns_nullopt()
{
IntTrie t;
Void::Testing::expect(!t.get("nope").has_value());
}
// ── starts_with ───────────────────────────────────────────────────────────────
Void::Testing::Test trie_starts_with_true()
{
BoolTrie t;
t.insert("hello");
Void::Testing::expect(t.starts_with("hel"));
}
Void::Testing::Test trie_starts_with_false()
{
BoolTrie t;
t.insert("hello");
Void::Testing::expect(!t.starts_with("world"));
}
// ── erase ────────────────────────────────────────────────────────────────────
Void::Testing::Test trie_erase_removes_word()
{
BoolTrie t;
t.insert("hello");
Void::Testing::expect(t.erase("hello"));
Void::Testing::expect(!t.contains("hello"));
}
Void::Testing::Test trie_erase_prefix_word_keeps_extension()
{
BoolTrie t;
t.insert("car");
t.insert("card");
t.erase("car");
Void::Testing::expect(!t.contains("car"));
Void::Testing::expect(t.contains("card"));
}
Void::Testing::Test trie_erase_missing_returns_false()
{
BoolTrie t;
Void::Testing::expect(!t.erase("nope"));
}
// ── keys_with_prefix ──────────────────────────────────────────────────────────
Void::Testing::Test trie_keys_with_prefix()
{
BoolTrie t;
t.insert("car");
t.insert("card");
t.insert("care");
t.insert("dog");
auto keys = t.keys_with_prefix("car");
std::sort(keys.begin(), keys.end());
Void::Testing::expect_eq(keys.size(), std::size_t{3});
Void::Testing::expect_eq(keys[0], std::string{"car"});
Void::Testing::expect_eq(keys[1], std::string{"card"});
Void::Testing::expect_eq(keys[2], std::string{"care"});
}
Void::Testing::Test trie_keys_with_prefix_no_match()
{
BoolTrie t;
t.insert("hello");
Void::Testing::expect(t.keys_with_prefix("xyz").empty());
}
// ── size ─────────────────────────────────────────────────────────────────────
Void::Testing::Test trie_size_tracks_inserts()
{
BoolTrie t;
Void::Testing::expect_eq(t.size(), std::size_t{0});
t.insert("a");
t.insert("b");
Void::Testing::expect_eq(t.size(), std::size_t{2});
}