Add new assert helper function for GraphTopologyDeletion tests

This commit is contained in:
2026-09-03 20:40:15 +02:00
parent 1209d75e15
commit 3ad448974e
2 changed files with 37 additions and 46 deletions
+6 -8
View File
@@ -262,18 +262,16 @@ mod trait_tests {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::testing::fixtures::MakeTestGraph;
#[test] #[test]
fn incident_vertices_paired_index() { fn incident_vertices_paired_index() {
let mut graph = AppendGraph::new(); let (graph, [v0, v1], e) = AppendGraph::single_edge();
let v1 = graph.add_vertex(); let f = Edge::new(e.index() + 1);
let v2 = graph.add_vertex(); let (u0, u1) = graph.incident_vertices(f);
let e = graph.add_edge(v1, v2);
let f = Edge(e.0 + 1);
let (u1, u2) = graph.incident_vertices(f);
assert!( assert!(
(u1 == v1 && u2 == v2) || (u1 == v2 && u2 == v1), (u0 == v0 && u1 == v1) || (u0 == v1 && u1 == v0),
"unexpected incident vertices {u1:?} and {u2:?} for edge {f:?}" "unexpected incident vertices {u0:?} and {u1:?} for edge {f:?}"
); );
} }
} }
+31 -38
View File
@@ -354,25 +354,7 @@ where
.iter() .iter()
.filter_map(|x| (x.edge != edges[2].0).then_some(x.edge)) .filter_map(|x| (x.edge != edges[2].0).then_some(x.edge))
.collect(); .collect();
assert_eq!( assert_incident_edges_after_delete(&graph, vertices[i], &mut expected);
graph.incident_edges(vertices[i]).count(),
expected.len(),
"unexpected incident edge count for vertex {:?} after delete",
vertices[i]
);
for e in graph.incident_edges(vertices[i]) {
let pos = expected.iter().position(|f| *f == e).expect(&format!(
"unexpected incident edge {e:?} of vertex {:?} after delete",
vertices[i]
));
expected.swap_remove(pos);
}
assert!(
expected.is_empty(),
"expected incident edges {:?} of vertex {:?} not matched after delete",
expected,
vertices[i]
);
} }
} }
@@ -388,25 +370,7 @@ where
.iter() .iter()
.filter_map(|x| (x.vertex != vertices[2]).then_some(x.edge)) .filter_map(|x| (x.vertex != vertices[2]).then_some(x.edge))
.collect(); .collect();
assert_eq!( assert_incident_edges_after_delete(&graph, vertices[i], &mut expected);
graph.incident_edges(vertices[i]).count(),
expected.len(),
"unexpected incident edge count for vertex {:?} after delete",
vertices[i]
);
for e in graph.incident_edges(vertices[i]) {
let pos = expected.iter().position(|f| *f == e).expect(&format!(
"unexpected incident edge {e:?} of vertex {:?} after delete",
vertices[i]
));
expected.swap_remove(pos);
}
assert!(
expected.is_empty(),
"expected incident edges {:?} of vertex {:?} not matched after delete",
expected,
vertices[i]
);
} }
} }
@@ -536,3 +500,32 @@ fn assert_vertex_incidence_cursor<G: GraphTopology>(
v v
); );
} }
fn assert_incident_edges_after_delete<G: GraphTopology>(
graph: &G,
v: G::Vertex,
expected: &mut Vec<G::Edge>,
) where
G::Vertex: Debug,
G::Edge: Debug,
{
assert_eq!(
graph.incident_edges(v).count(),
expected.len(),
"unexpected incident edge count for vertex {:?} after delete",
v
);
for e in graph.incident_edges(v) {
let pos = expected.iter().position(|f| *f == e).expect(&format!(
"unexpected incident edge {e:?} of vertex {:?} after delete",
v
));
expected.swap_remove(pos);
}
assert!(
expected.is_empty(),
"expected incident edges {:?} of vertex {:?} not matched after delete",
expected,
v
);
}