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

160 lines
4.6 KiB
C++

#include <Void/Containers/Graph.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <string>
#include <vector>
using G = Void::Graph::DiGraph<int>;
// ── Vertices ──────────────────────────────────────────────────────────────────
Void::Testing::Test graph_add_vertex()
{
G g;
g.add_vertex(1);
Void::Testing::expect(g.has_vertex(1));
Void::Testing::expect_eq(g.vertex_count(), std::size_t{1});
}
Void::Testing::Test graph_add_edge_creates_vertices()
{
G g;
g.add_edge(1, 2);
Void::Testing::expect(g.has_vertex(1));
Void::Testing::expect(g.has_vertex(2));
}
Void::Testing::Test graph_has_edge()
{
G g;
g.add_edge(1, 2);
Void::Testing::expect(g.has_edge(1, 2));
Void::Testing::expect(!g.has_edge(2, 1));
}
Void::Testing::Test graph_edge_count()
{
G g;
g.add_edge(1, 2);
g.add_edge(2, 3);
Void::Testing::expect_eq(g.edge_count(), std::size_t{2});
}
// ── BFS ───────────────────────────────────────────────────────────────────────
Void::Testing::Test bfs_visits_all_reachable()
{
G g;
g.add_edge(1, 2);
g.add_edge(1, 3);
g.add_edge(2, 4);
auto order = g.bfs_order(1);
Void::Testing::expect_eq(order.size(), std::size_t{4});
Void::Testing::expect_eq(order[0], 1);
}
Void::Testing::Test bfs_unreachable_vertex_not_visited()
{
G g;
g.add_edge(1, 2);
g.add_vertex(5);
auto order = g.bfs_order(1);
Void::Testing::expect_eq(order.size(), std::size_t{2});
}
// ── DFS ───────────────────────────────────────────────────────────────────────
Void::Testing::Test dfs_visits_all_reachable()
{
G g;
g.add_edge(1, 2);
g.add_edge(2, 3);
auto order = g.dfs_order(1);
Void::Testing::expect_eq(order.size(), std::size_t{3});
Void::Testing::expect_eq(order[0], 1);
}
// ── Topological sort ──────────────────────────────────────────────────────────
Void::Testing::Test topo_sort_dag()
{
G g;
g.add_edge(1, 2);
g.add_edge(1, 3);
g.add_edge(2, 4);
g.add_edge(3, 4);
const auto order = g.topological_sort();
Void::Testing::expect(order.has_value());
Void::Testing::expect_eq(order->size(), std::size_t{4});
// 1 must come before 2, 3; 2 and 3 before 4
Void::Testing::expect_eq(order->front(), 1);
Void::Testing::expect_eq(order->back(), 4);
}
Void::Testing::Test topo_sort_cycle_returns_nullopt()
{
G g;
g.add_edge(1, 2);
g.add_edge(2, 3);
g.add_edge(3, 1); // cycle
Void::Testing::expect(!g.topological_sort().has_value());
}
// ── Reachability ─────────────────────────────────────────────────────────────
Void::Testing::Test can_reach_direct()
{
G g;
g.add_edge(1, 2);
Void::Testing::expect(g.can_reach(1, 2));
}
Void::Testing::Test can_reach_indirect()
{
G g;
g.add_edge(1, 2);
g.add_edge(2, 3);
Void::Testing::expect(g.can_reach(1, 3));
}
Void::Testing::Test cannot_reach_reverse()
{
G g;
g.add_edge(1, 2);
Void::Testing::expect(!g.can_reach(2, 1));
}
// ── Shortest path ─────────────────────────────────────────────────────────────
Void::Testing::Test shortest_path_direct()
{
G g;
g.add_edge(1, 2);
const auto p = g.shortest_path(1, 2);
Void::Testing::expect(p.has_value());
Void::Testing::expect_eq(p->size(), std::size_t{2});
Void::Testing::expect_eq((*p)[0], 1);
Void::Testing::expect_eq((*p)[1], 2);
}
Void::Testing::Test shortest_path_longer()
{
G g;
g.add_edge(1, 2);
g.add_edge(2, 3);
g.add_edge(1, 3); // shortcut
const auto p = g.shortest_path(1, 3);
Void::Testing::expect(p.has_value());
// BFS finds shortest (length 2: 1→3)
Void::Testing::expect_eq(p->size(), std::size_t{2});
}
Void::Testing::Test shortest_path_no_path()
{
G g;
g.add_vertex(1);
g.add_vertex(2);
Void::Testing::expect(!g.shortest_path(1, 2).has_value());
}