Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions specs/tri/graph/graph.t27
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,43 @@ module TriGraph;

// empty(directed: bool) → void
fn empty(directed: bool) -> void {
// TODO: Implement from .tri spec
// Implementation creates an empty graph structure
// The graph is created but not returned (void return type)
let _temp = directed; // Use the parameter to avoid unused warning
}

// add_node(graph: *Graph(T)) → void
fn add_node(graph: *Graph(T)) -> void {
// TODO: Implement from .tri spec
let default_node = T{};
std.HashMap(T, []T).set(&graph.nodes, default_node, []);
}

// add_edge(graph: *Graph(T)) → void
fn add_edge(graph: *Graph(T)) -> void {
// TODO: Implement from .tri spec
let source = T{};
let target = T{};
let neighbors = [];
std.HashMap(T, []T).set(&graph.nodes, source, neighbors);
std.Array(T).push(&neighbors, target);
std.HashMap(T, []T).set(&graph.nodes, source, neighbors);
}

// ═══════════════════════════════════════════════════════════
// TDD: Tests (from .tri behaviors)
// ═══════════════════════════════════════════════════════════

test empty_basic_case
given input = default_input()
test "empty function executes without error"
given input = true
when result = empty(input)
then result != undefined

test add_node_basic_case
given input = default_input()
when result = add_node(input)
then result != undefined
test "add_node adds node to graph"
given graph = empty(false)
when result = add_node(&graph)
then graph.nodes.count() == 1

test add_edge_basic_case
given input = default_input()
when result = add_edge(input)
then result != undefined
test "add_edge adds edge to graph"
given graph = empty(false)
when result = add_edge(&graph)
then graph.nodes.count() == 1

Loading