Refactor graph trait tests to minimize macro code, and split into separate files per macro
The tests only declare a list of tests in the macro, no longer the test functions themselves. This allows better tooling support (e.g. IDE and rustfmt).
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
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(crate) 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(crate) fn delete_edge_add_edge<G: GraphTopologyDeletion + GraphTopologyAddition>()
|
||||
where
|
||||
G::Edge: Debug,
|
||||
{
|
||||
let (mut graph, vertices, e) = G::single_edge();
|
||||
graph.delete_edge(e);
|
||||
assert_eq!(graph.edge_count(), 0, "unexpected edge count after delete");
|
||||
assert_ne!(
|
||||
graph.add_edge(vertices[0], vertices[1]),
|
||||
e,
|
||||
"unexpected duplicate edge after re-add"
|
||||
);
|
||||
assert_eq!(graph.edge_count(), 1, "unexpected edge count after re-add");
|
||||
}
|
||||
Reference in New Issue
Block a user