Add new assert helper function for GraphTopologyDeletion tests
This commit is contained in:
@@ -262,18 +262,16 @@ mod trait_tests {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::testing::fixtures::MakeTestGraph;
|
||||
|
||||
#[test]
|
||||
fn incident_vertices_paired_index() {
|
||||
let mut graph = AppendGraph::new();
|
||||
let v1 = graph.add_vertex();
|
||||
let v2 = graph.add_vertex();
|
||||
let e = graph.add_edge(v1, v2);
|
||||
let f = Edge(e.0 + 1);
|
||||
let (u1, u2) = graph.incident_vertices(f);
|
||||
let (graph, [v0, v1], e) = AppendGraph::single_edge();
|
||||
let f = Edge::new(e.index() + 1);
|
||||
let (u0, u1) = graph.incident_vertices(f);
|
||||
assert!(
|
||||
(u1 == v1 && u2 == v2) || (u1 == v2 && u2 == v1),
|
||||
"unexpected incident vertices {u1:?} and {u2:?} for edge {f:?}"
|
||||
(u0 == v0 && u1 == v1) || (u0 == v1 && u1 == v0),
|
||||
"unexpected incident vertices {u0:?} and {u1:?} for edge {f:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,25 +354,7 @@ where
|
||||
.iter()
|
||||
.filter_map(|x| (x.edge != edges[2].0).then_some(x.edge))
|
||||
.collect();
|
||||
assert_eq!(
|
||||
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]
|
||||
);
|
||||
assert_incident_edges_after_delete(&graph, vertices[i], &mut expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,25 +370,7 @@ where
|
||||
.iter()
|
||||
.filter_map(|x| (x.vertex != vertices[2]).then_some(x.edge))
|
||||
.collect();
|
||||
assert_eq!(
|
||||
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]
|
||||
);
|
||||
assert_incident_edges_after_delete(&graph, vertices[i], &mut expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -536,3 +500,32 @@ fn assert_vertex_incidence_cursor<G: GraphTopology>(
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user