Add tests for Graph::vertices()
This commit is contained in:
@@ -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]) {
|
fn make_test_graph() -> (Graph, [Vertex; 10]) {
|
||||||
let mut graph = Graph::new();
|
let mut graph = Graph::new();
|
||||||
let vertices: [Vertex; 10] = core::array::from_fn(|_| graph.add_vertex());
|
let vertices: [Vertex; 10] = core::array::from_fn(|_| graph.add_vertex());
|
||||||
|
|||||||
Reference in New Issue
Block a user