Add tests for Graph::vertices()

This commit is contained in:
2025-10-24 23:14:04 +02:00
parent 72d3c06f1e
commit 74ca390ac2
+26
View File
@@ -188,6 +188,32 @@ mod tests {
}
}
#[test]
fn vertices_empty() {
let graph = Graph::new();
assert_eq!(
graph.vertices().count(),
0,
"vertex iterator of empty graph should have no elements"
);
}
#[test]
fn vertices() {
let (graph, vertices) = make_test_graph();
assert_eq!(graph.vertices().count(), 10, "unexpected vertex count");
let mut vertices: Vec<Vertex> = vertices.into_iter().collect();
for v in graph.vertices() {
if let Some(index) = vertices.iter().position(|&x| x == v) {
vertices.swap_remove(index);
} else {
panic!("unexpected vertex of {v:?} from iterator");
}
}
println!("vertices: {:?}", vertices);
}
fn make_test_graph() -> (Graph, [Vertex; 10]) {
let mut graph = Graph::new();
let vertices: [Vertex; 10] = core::array::from_fn(|_| graph.add_vertex());