Initial release #1
+19
-15
@@ -203,15 +203,14 @@ mod tests {
|
|||||||
let (graph, vertices) = make_test_graph();
|
let (graph, vertices) = make_test_graph();
|
||||||
assert_eq!(graph.vertices().count(), 10, "unexpected vertex count");
|
assert_eq!(graph.vertices().count(), 10, "unexpected vertex count");
|
||||||
|
|
||||||
let mut vertices: Vec<Vertex> = vertices.into_iter().collect();
|
// Expects each vertex to appear exactly once.
|
||||||
for v in graph.vertices() {
|
for v in graph.vertices() {
|
||||||
if let Some(index) = vertices.iter().position(|&x| x == v) {
|
assert_eq!(
|
||||||
vertices.swap_remove(index);
|
vertices.iter().filter(|&x| *x == v).count(),
|
||||||
} else {
|
1,
|
||||||
panic!("unexpected vertex of {v:?} from iterator");
|
"unexpected vertex {v:?} from the iterator"
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
println!("vertices: {:?}", vertices);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -229,17 +228,22 @@ mod tests {
|
|||||||
fn neighbors() {
|
fn neighbors() {
|
||||||
let (graph, vertices) = make_test_graph();
|
let (graph, vertices) = make_test_graph();
|
||||||
// Checks neighbors of vertex 4.
|
// Checks neighbors of vertex 4.
|
||||||
assert_eq!(graph.neighbors(vertices[4]).count(), 4, "unexpected vertex count");
|
assert_eq!(
|
||||||
|
graph.neighbors(vertices[4]).count(),
|
||||||
|
4,
|
||||||
|
"unexpected vertex count"
|
||||||
|
);
|
||||||
|
|
||||||
let mut neighbors: Vec<Vertex> = vec![vertices[1], vertices[2], vertices[7], vertices[8]];
|
// Expects each neighbor to appear exactly once. This will not work if there are multiple edges.
|
||||||
|
let neighbors: Vec<Vertex> = vec![vertices[1], vertices[2], vertices[7], vertices[8]];
|
||||||
for v in graph.neighbors(vertices[4]) {
|
for v in graph.neighbors(vertices[4]) {
|
||||||
if let Some(index) = neighbors.iter().position(|&x| x == v) {
|
assert_eq!(
|
||||||
neighbors.swap_remove(index);
|
neighbors.iter().filter(|&x| *x == v).count(),
|
||||||
} else {
|
1,
|
||||||
panic!("unexpected vertex of {v:?} from iterator");
|
"unexpected neighbor {v:?} of {:?} from the iterator",
|
||||||
}
|
vertices[4]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
println!("vertices: {:?}", vertices);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_test_graph() -> (Graph, [Vertex; 10]) {
|
fn make_test_graph() -> (Graph, [Vertex; 10]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user