Extract asserts from Clone tests to be reusable

This commit is contained in:
2026-09-25 08:36:30 +02:00
parent 0dea90ceff
commit d438a4288a
3 changed files with 147 additions and 77 deletions
+2 -44
View File
@@ -1,5 +1,6 @@
use std::fmt::Debug;
use crate::testing::fixtures;
use crate::testing::fixtures::MakeTestGraph;
#[doc(hidden)]
@@ -7,7 +8,6 @@ use crate::testing::fixtures::MakeTestGraph;
macro_rules! graph_topology_clone_tests {
($T:ty) => {
$crate::graph_topology_clone_tests!(@wrap $T,
clone_preserves_vertex_and_edge_count,
clone_handles_interchangeable,
);
};
@@ -22,21 +22,6 @@ macro_rules! graph_topology_clone_tests {
};
}
pub fn clone_preserves_vertex_and_edge_count<G: Clone + MakeTestGraph>() {
let (graph, ..) = G::standard();
let clone = graph.clone();
assert_eq!(
clone.vertex_count(),
graph.vertex_count(),
"clone should have the same vertex count as the original"
);
assert_eq!(
clone.edge_count(),
graph.edge_count(),
"clone should have the same edge count as the original"
);
}
/// Queries the clone using vertex and edge handles obtained from the original graph, and asserts
/// that the results are identical to querying the original with those same handles. This is only
/// meaningful because Vertex and Edge handles are not tied to a particular graph instance.
@@ -47,32 +32,5 @@ where
{
let (graph, vertices, edges, _) = G::standard();
let clone = graph.clone();
for &v in vertices.iter() {
assert_eq!(
clone.degree(v),
graph.degree(v),
"vertex {v:?} should have the same degree in the clone as in the original"
);
let mut expected: Vec<_> = graph.incidences(v).collect();
for incidence in clone.incidences(v) {
let pos = expected
.iter()
.position(|x| *x == incidence)
.expect(&format!(
"unexpected incidence {incidence:?} of vertex {v:?} in the clone"
));
expected.swap_remove(pos);
}
assert!(
expected.is_empty(),
"expected incidences {expected:?} of vertex {v:?} are missing in the clone"
);
}
for &(e, u, v) in edges.iter() {
assert_eq!(
clone.incident_vertices(e),
(u, v),
"edge {e:?} should have the same incident vertices in the clone as in the original"
);
}
fixtures::assert_isomorphic(&graph, &clone, &vertices, |v| v, &edges, |e| e);
}