use knotrel_core::{ConnectivityGraph, EngineConfig, NodeId};
use std::error::Error;
enum Action {
AddNode(NodeId),
Link(NodeId, NodeId),
Cut(NodeId, NodeId),
CheckConnected(NodeId, NodeId, bool),
}
fn exercise_engine(config: EngineConfig) -> Result<(), Box<dyn Error>> {
println!(
"--- Testing Engine: {:?} (as_str: '{}', experimental: {}) ---",
config,
config.as_str(),
config.is_experimental()
);
let mut graph = ConnectivityGraph::new(config);
assert_eq!(graph.engine(), config);
let actions = [
Action::AddNode(1),
Action::AddNode(2),
Action::AddNode(3),
Action::AddNode(4),
Action::AddNode(5),
Action::AddNode(6),
Action::AddNode(7),
Action::Link(1, 2),
Action::Link(2, 3),
Action::Link(3, 1),
Action::Link(3, 4),
Action::Link(4, 5),
Action::Link(6, 7),
Action::CheckConnected(1, 2, true),
Action::CheckConnected(1, 5, true),
Action::CheckConnected(1, 6, false),
Action::CheckConnected(6, 7, true),
Action::Cut(1, 2),
Action::CheckConnected(1, 2, true),
Action::Cut(3, 4),
Action::CheckConnected(1, 4, false),
Action::CheckConnected(1, 5, false),
Action::CheckConnected(4, 5, true),
Action::Cut(4, 5),
Action::CheckConnected(4, 5, false),
Action::Link(1, 5),
Action::CheckConnected(2, 5, true),
Action::CheckConnected(1, 5, true),
Action::CheckConnected(4, 5, false),
];
for action in actions {
match action {
Action::AddNode(node) => {
graph.add_node(node)?;
}
Action::Link(u, v) => {
graph.link(u, v)?;
}
Action::Cut(u, v) => {
graph.cut(u, v)?;
}
Action::CheckConnected(u, v, expected) => {
let actual = graph.connected(u, v)?;
assert_eq!(
actual, expected,
"Engine {:?} mismatch for connected({}, {}): expected {}, got {}",
config, u, v, expected, actual
);
}
}
}
println!(
"Engine {:?} passed all equivalence checks (nodes: {}, edges: {}).\n",
config,
graph.node_count(),
graph.edge_count()
);
Ok(())
}
fn main() -> Result<(), Box<dyn Error>> {
println!("=== Knotrel Engine Selection & Equivalence Example ===\n");
let engines = [
EngineConfig::CompactBfs,
EngineConfig::EulerTour,
EngineConfig::Hdt,
];
for &engine in &engines {
exercise_engine(engine)?;
}
println!("All three engines produced identical, exact connectivity results.");
Ok(())
}