Refactor tests: use MakeTestGraph in model-specific tests, deconstruct vertex arrays where useful, adjust local variable names

This commit is contained in:
2026-09-04 09:28:00 +02:00
parent 016d127bd1
commit 4c6a8a43e4
11 changed files with 153 additions and 195 deletions
+15 -16
View File
@@ -161,9 +161,9 @@ fn bfs_find_source<G: MakeTestGraph>() {
}
fn bfs_find_disconnected<G: MakeTestGraph>() {
let (graph, vertices) = G::disconnected();
let (graph, [v0, v1, _]) = G::disconnected();
assert_eq!(
algorithms::bfs_find(&graph, vertices[0], vertices[1]),
algorithms::bfs_find(&graph, v0, v1),
None,
"disconnected target should not be found"
);
@@ -196,12 +196,11 @@ fn bfs_find_where_disconnected<G: MakeTestGraph>()
where
G::Vertex: Debug,
{
let (graph, vertices) = G::disconnected();
let (graph, [v0, v1, _]) = G::disconnected();
assert_eq!(
algorithms::bfs_find_where(&graph, vertices[0], |v| v == vertices[1]),
algorithms::bfs_find_where(&graph, v0, |v| v == v1),
None,
"disconnected vertex {:?} should not be found",
vertices[1]
"disconnected vertex {v1:?} should not be found"
);
}
@@ -209,9 +208,9 @@ fn bfs_find_where_no_match<G: MakeTestGraph>()
where
G::Vertex: Debug,
{
let (graph, vertices, _, _) = G::standard();
let (graph, [v0, ..], _, _) = G::standard();
assert_eq!(
algorithms::bfs_find_where(&graph, vertices[0], |_| false),
algorithms::bfs_find_where(&graph, v0, |_| false),
None,
"no vertex should match an always-false predicate"
);
@@ -258,9 +257,9 @@ fn bfs_find_path_disconnected<G: MakeTestGraph>()
where
G::Edge: Debug,
{
let (graph, vertices) = G::disconnected();
let (graph, [v0, v1, _]) = G::disconnected();
assert_eq!(
algorithms::bfs_find_path(&graph, vertices[0], vertices[1]),
algorithms::bfs_find_path(&graph, v0, v1),
None,
"no path should exist to disconnected vertex"
);
@@ -270,8 +269,8 @@ fn bfs_find_path_adjacent<G: MakeTestGraph>()
where
G::Edge: Debug,
{
let (graph, vertices, e) = G::single_edge();
let path = algorithms::bfs_find_path(&graph, vertices[0], vertices[1])
let (graph, [v0, v1], e) = G::single_edge();
let path = algorithms::bfs_find_path(&graph, v0, v1)
.expect("path should exist between adjacent vertices");
assert_eq!(path, [e], "path should contain only the connecting edge");
}
@@ -308,9 +307,9 @@ fn bfs_find_path_where_disconnected<G: MakeTestGraph>()
where
G::Edge: Debug,
{
let (graph, vertices) = G::disconnected();
let (graph, [v0, v1, _]) = G::disconnected();
assert_eq!(
algorithms::bfs_find_path_where(&graph, vertices[0], |v| v == vertices[1]),
algorithms::bfs_find_path_where(&graph, v0, |v| v == v1),
None,
"no path should exist to disconnected vertex"
);
@@ -320,9 +319,9 @@ fn bfs_find_path_where_no_match<G: MakeTestGraph>()
where
G::Edge: Debug,
{
let (graph, vertices, _, _) = G::standard();
let (graph, [v0, ..], _, _) = G::standard();
assert_eq!(
algorithms::bfs_find_path_where(&graph, vertices[0], |_| false),
algorithms::bfs_find_path_where(&graph, v0, |_| false),
None,
"no path should exist when predicate never matches"
);