63 lines
1.6 KiB
Rust
63 lines
1.6 KiB
Rust
use std::fmt::Debug;
|
|
|
|
use crate::testing::fixtures::MakeTestGraph;
|
|
use crate::traits::{GraphTopologyAddition, GraphTopologyDeletion};
|
|
|
|
#[doc(hidden)]
|
|
#[macro_export]
|
|
macro_rules! graph_topology_addition_deletion_tests {
|
|
($T:ty) => {
|
|
$crate::graph_topology_addition_deletion_tests!(@wrap $T,
|
|
delete_vertex_add_vertex,
|
|
delete_edge_add_edge,
|
|
);
|
|
};
|
|
|
|
(@wrap $T:ty, $($name:ident),* $(,)?) => {
|
|
$(
|
|
#[test]
|
|
fn $name() {
|
|
$crate::testing::graph_topology_addition_deletion_testing::$name::<$T>();
|
|
}
|
|
)*
|
|
};
|
|
}
|
|
|
|
pub fn delete_vertex_add_vertex<G: GraphTopologyDeletion + GraphTopologyAddition>()
|
|
where
|
|
G::Vertex: Debug,
|
|
{
|
|
let (mut graph, v) = G::single_vertex();
|
|
graph.delete_vertex(v);
|
|
assert_eq!(
|
|
graph.vertex_count(),
|
|
0,
|
|
"unexpected vertex count after delete"
|
|
);
|
|
assert_ne!(
|
|
graph.add_vertex(),
|
|
v,
|
|
"unexpected duplicate vertex after delete"
|
|
);
|
|
assert_eq!(
|
|
graph.vertex_count(),
|
|
1,
|
|
"unexpected vertex count after re-add"
|
|
);
|
|
}
|
|
|
|
pub fn delete_edge_add_edge<G: GraphTopologyDeletion + GraphTopologyAddition>()
|
|
where
|
|
G::Edge: Debug,
|
|
{
|
|
let (mut graph, [v0, v1], e) = G::single_edge();
|
|
graph.delete_edge(e);
|
|
assert_eq!(graph.edge_count(), 0, "unexpected edge count after delete");
|
|
assert_ne!(
|
|
graph.add_edge(v0, v1),
|
|
e,
|
|
"unexpected duplicate edge after re-add"
|
|
);
|
|
assert_eq!(graph.edge_count(), 1, "unexpected edge count after re-add");
|
|
}
|