Add test for Graph vertex deletion with loop

This commit is contained in:
2026-04-29 20:49:34 +02:00
parent 5b0d6ca1ad
commit b3dc0ea666
+30
View File
@@ -479,6 +479,36 @@ mod tests {
);
}
#[test]
fn delete_vertex_loop() {
let mut graph = Graph::new();
let v = graph.add_vertex();
graph.add_edge(v, v);
assert_eq!(
graph.vertex_count(),
1,
"unexpected vertex count before delete"
);
assert_eq!(graph.edge_count(), 1, "unexpected edge count before delete");
assert!(
graph.are_adjacent(v, v),
"expected vertex to be self-adjacent before delete"
);
assert_eq!(graph.degree(v), 2, "unexpected vertex degree before delete");
graph.delete_vertex(v);
assert_eq!(
graph.vertex_count(),
0,
"unexpected vertex count after delete"
);
assert_eq!(graph.edge_count(), 0, "unexpected edge count after delete");
assert_ne!(
graph.add_vertex(),
v,
"unexpected duplicate vertex after delete"
);
}
#[test]
fn delete_vertex_invalid_index() {
let mut graph = Graph::new();