Fix clippy findings and related issues

This commit is contained in:
2026-10-13 21:25:50 +02:00
parent 7cfee9cce5
commit 3d1e8246a8
11 changed files with 179 additions and 254 deletions
+71 -112
View File
@@ -128,14 +128,10 @@ where
G::Vertex: Debug,
{
let (graph, vertices, _, _) = G::standard();
let expected_degrees = [2, 5, 7, 2, 7, 2, 3, 3, 2, 3];
for i in 0..graph.vertex_count() {
assert_eq!(
graph.degree(vertices[i]),
expected_degrees[i],
"unexpected degree of {:?}",
vertices[i]
);
let expected = [2, 5, 7, 2, 7, 2, 3, 3, 2, 3];
assert_eq!(vertices.len(), expected.len());
for (&v, &exp) in vertices.iter().zip(&expected) {
assert_eq!(graph.degree(v), exp, "unexpected degree of {v:?}");
}
}
@@ -200,23 +196,18 @@ where
vertices[9],
vertices[3]
);
for i in 0..graph.vertex_count() {
let exp = match i {
1 | 2 | 4 | 5 | 6 => true,
_ => false,
};
for (i, &v) in vertices.iter().enumerate() {
let exp = matches!(i, 1 | 2 | 4 | 5 | 6);
assert_eq!(
graph.are_adjacent(vertices[2], vertices[i]),
graph.are_adjacent(vertices[2], v),
exp,
"unexpected adjacency of {:?} and {:?}",
vertices[2],
vertices[i]
"unexpected adjacency of {:?} and {v:?}",
vertices[2]
);
assert_eq!(
graph.are_adjacent(vertices[i], vertices[2]),
graph.are_adjacent(v, vertices[2]),
exp,
"unexpected adjacency of {:?} and {:?}",
vertices[i],
"unexpected adjacency of {v:?} and {:?}",
vertices[2]
);
}
@@ -289,8 +280,7 @@ where
assert_eq!(
expected_adjacency.len(),
0,
"expected adjacent vertices {:?} of {:?} were not matched by iterator",
expected_adjacency,
"expected adjacent vertices {expected_adjacency:?} of {:?} were not matched by iterator",
vertices[4]
);
}
@@ -320,21 +310,19 @@ where
{
const K: usize = 3;
let (graph, vertices, _) = G::multiple_edges::<K>();
for i in 0..2 {
let mut iter = graph.adjacent_vertices(vertices[i]);
for (i, &v) in vertices.iter().enumerate() {
let mut iter = graph.adjacent_vertices(v);
for j in 0..K {
assert_eq!(
iter.next(),
Some(vertices[1 - i]),
"unexpected adjacent vertex {j} of vertex {:?}",
vertices[i]
"unexpected adjacent vertex {j} of vertex {v:?}"
);
}
assert_eq!(
iter.next(),
None,
"too many adjacent vertices of vertex {:?} from iterator",
vertices[i]
"too many adjacent vertices of vertex {v:?} from iterator"
);
}
}
@@ -372,12 +360,11 @@ where
{
let (graph, [v0, v1], edges) = G::multiple_edges::<2>();
assert_ne!(edges[0], edges[1], "edges should be distinct");
for i in 0..2 {
let (u0, u1) = graph.incident_vertices(edges[i]);
for (i, &e) in edges.iter().enumerate() {
let (u0, u1) = graph.incident_vertices(e);
assert!(
(u0 == v0 && u1 == v1) || (u0 == v1 && u1 == v0),
"unexpected incident vertices {u0:?} and {u1:?} for multi-edge {:?} (index {i})",
edges[i]
"unexpected incident vertices {u0:?} and {u1:?} for multi-edge {e:?} (index {i})"
);
}
}
@@ -436,28 +423,23 @@ where
G::Edge: Debug,
{
let (graph, vertices, _, incidences) = G::standard();
for i in 0..10 {
assert_eq!(vertices.len(), incidences.len());
for (&v, incs) in vertices.iter().zip(&incidences) {
assert_eq!(
graph.incident_edges(vertices[i]).count(),
incidences[i].len(),
"unexpected incident edge count for vertex {:?}",
vertices[i]
graph.incident_edges(v).count(),
incs.len(),
"unexpected incident edge count for vertex {v:?}"
);
let mut expected: Vec<_> = incidences[i].iter().map(|x| x.edge).collect();
for e in graph.incident_edges(vertices[i]) {
let pos = expected.iter().position(|f| *f == e).unwrap_or_else(|| {
panic!(
"unexpected incident edge {e:?} of vertex {:?} from iterator",
vertices[i]
)
let mut expected: Vec<_> = incs.iter().map(|x| x.edge).collect();
for e in graph.incident_edges(v) {
let pos = expected.iter().position(|&f| f == e).unwrap_or_else(|| {
panic!("unexpected incident edge {e:?} of vertex {v:?} from iterator")
});
expected.swap_remove(pos);
}
assert!(
expected.is_empty(),
"expected incident edges {:?} of vertex {:?} were not matched by iterator",
expected,
vertices[i]
"expected incident edges {expected:?} of vertex {v:?} were not matched by iterator"
);
}
}
@@ -488,19 +470,18 @@ where
{
const K: usize = 3;
let (graph, vertices, edges) = G::multiple_edges::<K>();
for i in 0..2 {
for &v in &vertices {
let mut expected = edges.to_vec();
for e in graph.incident_edges(vertices[i]) {
let pos = expected.iter().position(|f| *f == e).unwrap_or_else(|| {
panic!("unexpected incident edge {e:?} of vertex {:?}", vertices[i])
});
for e in graph.incident_edges(v) {
let pos = expected
.iter()
.position(|&f| f == e)
.unwrap_or_else(|| panic!("unexpected incident edge {e:?} of vertex {v:?}"));
expected.swap_remove(pos);
}
assert!(
expected.is_empty(),
"expected incident edges {:?} of vertex {:?} were not matched by iterator",
expected,
vertices[i]
"expected incident edges {expected:?} of vertex {v:?} were not matched by iterator"
);
}
}
@@ -520,31 +501,26 @@ where
G::Edge: Debug,
{
let (graph, vertices, _, incidences) = G::standard();
for i in 0..10 {
assert_eq!(vertices.len(), incidences.len());
for (&v, incs) in vertices.iter().zip(&incidences) {
assert_eq!(
graph.incidences(vertices[i]).count(),
incidences[i].len(),
"unexpected incidence count for vertex {:?}",
vertices[i]
graph.incidences(v).count(),
incs.len(),
"unexpected incidence count for vertex {v:?}"
);
let mut expected = incidences[i].clone();
for incidence in graph.incidences(vertices[i]) {
let mut expected = incs.clone();
for incidence in graph.incidences(v) {
let pos = expected
.iter()
.position(|x| *x == incidence)
.position(|&x| x == incidence)
.unwrap_or_else(|| {
panic!(
"unexpected incidence {incidence:?} of vertex {:?} from iterator",
vertices[i]
)
panic!("unexpected incidence {incidence:?} of vertex {v:?} from iterator")
});
expected.swap_remove(pos);
}
assert!(
expected.is_empty(),
"expected incidences {:?} of vertex {:?} were not matched by iterator",
expected,
vertices[i]
"expected incidences {expected:?} of vertex {v:?} were not matched by iterator"
);
}
}
@@ -613,34 +589,28 @@ where
{
const K: usize = 3;
let (graph, vertices, edges) = G::multiple_edges::<K>();
for i in 0..2 {
let mut iter = graph.incidences(vertices[i]);
for (i, &v) in vertices.iter().enumerate() {
let mut iter = graph.incidences(v);
for j in 0..K {
let current = iter.next().unwrap_or_else(|| {
panic!(
"incidence {j} missing, expected {K} incidences for vertex {:?}",
vertices[i]
)
panic!("incidence {j} missing, expected {K} incidences for vertex {v:?}")
});
assert_eq!(
current.vertex,
vertices[1 - i],
"unexpected adjacent vertex of vertex {:?} in incidence {j}",
vertices[i]
"unexpected adjacent vertex of vertex {v:?} in incidence {j}"
);
assert_eq!(
edges.iter().filter(|e| **e == current.edge).count(),
edges.iter().filter(|&&e| e == current.edge).count(),
1,
"unexpected incident edge {:?} of vertex {:?}",
current.edge,
vertices[i],
"unexpected incident edge {:?} of vertex {v:?}",
current.edge
);
}
assert_eq!(
iter.next(),
None,
"too many adjacent vertices of {:?} from iterator",
vertices[i]
"too many adjacent vertices of {v:?} from iterator"
);
}
}
@@ -665,26 +635,22 @@ where
G::Edge: Debug,
{
let (graph, vertices, _, incidences) = G::standard();
for i in 0..10 {
let mut expected = incidences[i].clone();
let mut cursor = graph.incidence_cursor(vertices[i]);
assert_eq!(vertices.len(), incidences.len());
for (&v, incs) in vertices.iter().zip(&incidences) {
let mut expected = incs.clone();
let mut cursor = graph.incidence_cursor(v);
while let Some(incidence) = cursor.next(&graph) {
let pos = expected
.iter()
.position(|x| *x == incidence)
.position(|&x| x == incidence)
.unwrap_or_else(|| {
panic!(
"unexpected incidence {incidence:?} of vertex {:?} from cursor",
vertices[i]
)
panic!("unexpected incidence {incidence:?} of vertex {v:?} from cursor")
});
expected.swap_remove(pos);
}
assert!(
expected.is_empty(),
"expected incidences {:?} of vertex {:?} were not matched by cursor",
expected,
vertices[i]
"expected incidences {expected:?} of vertex {v:?} were not matched by cursor"
);
}
}
@@ -716,34 +682,28 @@ where
{
const K: usize = 3;
let (graph, vertices, edges) = G::multiple_edges::<K>();
for i in 0..2 {
let mut cursor = graph.incidence_cursor(vertices[i]);
for (i, &v) in vertices.iter().enumerate() {
let mut cursor = graph.incidence_cursor(v);
for j in 0..K {
let current = cursor.next(&graph).unwrap_or_else(|| {
panic!(
"incidence {j} missing, expected {K} incidences for vertex {:?}",
vertices[i]
)
panic!("incidence {j} missing, expected {K} incidences for vertex {v:?}")
});
assert_eq!(
current.vertex,
vertices[1 - i],
"unexpected adjacent vertex of vertex {:?} in incidence {j}",
vertices[i]
"unexpected adjacent vertex of vertex {v:?} in incidence {j}"
);
assert_eq!(
edges.iter().filter(|e| **e == current.edge).count(),
edges.iter().filter(|&&e| e == current.edge).count(),
1,
"unexpected incident edge {:?} of vertex {:?}",
current.edge,
vertices[i],
"unexpected incident edge {:?} of vertex {v:?}",
current.edge
);
}
assert_eq!(
cursor.next(&graph),
None,
"too many incidences of {:?} from cursor",
vertices[i]
"too many incidences of {v:?} from cursor"
);
}
}
@@ -800,15 +760,14 @@ where
for u in graph.vertices() {
let mut expected: Vec<_> = graph.incidences(u).map(|x| x.edge).collect();
for e in graph.incident_edges(u) {
let pos = expected.iter().position(|f| *f == e).unwrap_or_else(|| {
let pos = expected.iter().position(|&f| f == e).unwrap_or_else(|| {
panic!("incident edge {e:?} of vertex {u:?} missing from incidences")
});
expected.swap_remove(pos);
}
assert!(
expected.is_empty(),
"incidence edges {:?} of vertex {u:?} not matched by incident_edges",
expected
"incidence edges {expected:?} of vertex {u:?} not matched by incident_edges"
);
}
}