Add test for Graph vertex deletion with loop
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user