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
+18 -19
View File
@@ -150,9 +150,9 @@ fn dfs_find_source<G: MakeTestGraph>() {
}
fn dfs_find_disconnected<G: MakeTestGraph>() {
let (graph, vertices) = G::disconnected();
let (graph, [v0, v1, _]) = G::disconnected();
assert!(
!algorithms::dfs_find(&graph, vertices[0], vertices[1]),
!algorithms::dfs_find(&graph, v0, v1),
"disconnected target should not be found"
);
}
@@ -188,12 +188,11 @@ fn dfs_find_where_disconnected<G: MakeTestGraph>()
where
G::Vertex: Debug,
{
let (graph, vertices) = G::disconnected();
let (graph, [v0, v1, _]) = G::disconnected();
assert_eq!(
algorithms::dfs_find_where(&graph, vertices[0], |v| v == vertices[1]),
algorithms::dfs_find_where(&graph, v0, |v| v == v1),
None,
"disconnected vertex {:?} should not be found",
vertices[1]
"disconnected vertex {v1:?} should not be found"
);
}
@@ -201,9 +200,9 @@ fn dfs_find_where_no_match<G: MakeTestGraph>()
where
G::Vertex: Debug,
{
let (graph, vertices, _, _) = G::standard();
let (graph, [v0, ..], _, _) = G::standard();
assert_eq!(
algorithms::dfs_find_where(&graph, vertices[0], |_| false),
algorithms::dfs_find_where(&graph, v0, |_| false),
None,
"no vertex should match an always-false predicate"
);
@@ -213,10 +212,10 @@ fn dfs_find_where_adjacent<G: MakeTestGraph>()
where
G::Vertex: Debug,
{
let (graph, vertices, _, _) = G::standard();
let (graph, [v0, v1, ..], _, _) = G::standard();
assert_eq!(
algorithms::dfs_find_where(&graph, vertices[0], |v| v == vertices[1]),
Some(vertices[1]),
algorithms::dfs_find_where(&graph, v0, |v| v == v1),
Some(v1),
"expected to find adjacent vertex"
);
}
@@ -249,9 +248,9 @@ fn dfs_find_path_disconnected<G: MakeTestGraph>()
where
G::Edge: Debug,
{
let (graph, vertices) = G::disconnected();
let (graph, [v0, v1, _]) = G::disconnected();
assert_eq!(
algorithms::dfs_find_path(&graph, vertices[0], vertices[1]),
algorithms::dfs_find_path(&graph, v0, v1),
None,
"no path should exist to disconnected vertex"
);
@@ -261,8 +260,8 @@ fn dfs_find_path_adjacent<G: MakeTestGraph>()
where
G::Edge: Debug,
{
let (graph, vertices, e) = G::single_edge();
let path = algorithms::dfs_find_path(&graph, vertices[0], vertices[1])
let (graph, [v0, v1], e) = G::single_edge();
let path = algorithms::dfs_find_path(&graph, v0, v1)
.expect("path should exist between adjacent vertices");
assert_eq!(path, [e], "path should contain only the connecting edge");
}
@@ -293,9 +292,9 @@ fn dfs_find_path_where_disconnected<G: MakeTestGraph>()
where
G::Edge: Debug,
{
let (graph, vertices) = G::disconnected();
let (graph, [v0, v1, _]) = G::disconnected();
assert_eq!(
algorithms::dfs_find_path_where(&graph, vertices[0], |v| v == vertices[1]),
algorithms::dfs_find_path_where(&graph, v0, |v| v == v1),
None,
"no path should exist to disconnected vertex"
);
@@ -305,9 +304,9 @@ fn dfs_find_path_where_no_match<G: MakeTestGraph>()
where
G::Edge: Debug,
{
let (graph, vertices, _, _) = G::standard();
let (graph, [v0, ..], _, _) = G::standard();
assert_eq!(
algorithms::dfs_find_path_where(&graph, vertices[0], |_| false),
algorithms::dfs_find_path_where(&graph, v0, |_| false),
None,
"no path should exist when predicate never matches"
);