Remove function calls inside of 'expect'

This commit is contained in:
2026-10-12 21:52:51 +02:00
parent b124e58b38
commit 7cfee9cce5
3 changed files with 69 additions and 50 deletions
+9 -7
View File
@@ -318,10 +318,12 @@ where
G::Vertex: Debug, G::Vertex: Debug,
G::Edge: Debug, G::Edge: Debug,
{ {
let path = path_option.expect(&format!( let path = path_option.unwrap_or_else(|| {
"path should exist between source vertex {:?} and connected targets {:?}", panic!(
source, targets "path should exist between source vertex {:?} and connected targets {:?}",
)); source, targets
)
});
if targets.contains(&source) { if targets.contains(&source) {
assert!( assert!(
@@ -402,9 +404,9 @@ pub fn assert_isomorphic<G: GraphTopology, H: GraphTopology>(
.position(|x| { .position(|x| {
vertex_map(x.vertex) == incidence.vertex && edge_map(x.edge) == incidence.edge vertex_map(x.vertex) == incidence.vertex && edge_map(x.edge) == incidence.edge
}) })
.expect(&format!( .unwrap_or_else(|| {
"unexpected incidence {incidence:?} of vertex {v:?} in the other graph" panic!("unexpected incidence {incidence:?} of vertex {v:?} in the other graph")
)); });
expected.swap_remove(pos); expected.swap_remove(pos);
} }
assert!( assert!(
+18 -12
View File
@@ -452,10 +452,12 @@ fn assert_vertex_incidences<G: GraphTopology>(
let pos = expected let pos = expected
.iter() .iter()
.position(|x| *x == incidence) .position(|x| *x == incidence)
.expect(&format!( .unwrap_or_else(|| {
"unexpected incidence {incidence:?} of vertex {:?} from iterator after delete", panic!(
v "unexpected incidence {incidence:?} of vertex {:?} from iterator after delete",
)); v
)
});
expected.swap_remove(pos); expected.swap_remove(pos);
} }
assert!( assert!(
@@ -479,10 +481,12 @@ fn assert_vertex_incidence_cursor<G: GraphTopology>(
let pos = expected let pos = expected
.iter() .iter()
.position(|x| *x == incidence) .position(|x| *x == incidence)
.expect(&format!( .unwrap_or_else(|| {
"unexpected incidence {incidence:?} of vertex {:?} from cursor after delete", panic!(
v "unexpected incidence {incidence:?} of vertex {:?} from cursor after delete",
)); v
)
});
expected.swap_remove(pos); expected.swap_remove(pos);
} }
assert!( assert!(
@@ -508,10 +512,12 @@ fn assert_incident_edges_after_delete<G: GraphTopology>(
v v
); );
for e in graph.incident_edges(v) { for e in graph.incident_edges(v) {
let pos = expected.iter().position(|f| *f == e).expect(&format!( let pos = expected.iter().position(|f| *f == e).unwrap_or_else(|| {
"unexpected incident edge {e:?} of vertex {:?} after delete", panic!(
v "unexpected incident edge {e:?} of vertex {:?} after delete",
)); v
)
});
expected.swap_remove(pos); expected.swap_remove(pos);
} }
assert!( assert!(
+42 -31
View File
@@ -278,10 +278,12 @@ where
let i = expected_adjacency let i = expected_adjacency
.iter() .iter()
.position(|w| *w == v) .position(|w| *w == v)
.expect(&format!( .unwrap_or_else(|| {
"unexpected adjacent vertex {v:?} of {:?} from iterator", panic!(
vertices[4] "unexpected adjacent vertex {v:?} of {:?} from iterator",
)); vertices[4]
)
});
expected_adjacency.swap_remove(i); expected_adjacency.swap_remove(i);
} }
assert_eq!( assert_eq!(
@@ -443,10 +445,12 @@ where
); );
let mut expected: Vec<_> = incidences[i].iter().map(|x| x.edge).collect(); let mut expected: Vec<_> = incidences[i].iter().map(|x| x.edge).collect();
for e in graph.incident_edges(vertices[i]) { for e in graph.incident_edges(vertices[i]) {
let pos = expected.iter().position(|f| *f == e).expect(&format!( let pos = expected.iter().position(|f| *f == e).unwrap_or_else(|| {
"unexpected incident edge {e:?} of vertex {:?} from iterator", panic!(
vertices[i] "unexpected incident edge {e:?} of vertex {:?} from iterator",
)); vertices[i]
)
});
expected.swap_remove(pos); expected.swap_remove(pos);
} }
assert!( assert!(
@@ -487,10 +491,9 @@ where
for i in 0..2 { for i in 0..2 {
let mut expected = edges.to_vec(); let mut expected = edges.to_vec();
for e in graph.incident_edges(vertices[i]) { for e in graph.incident_edges(vertices[i]) {
let pos = expected.iter().position(|f| *f == e).expect(&format!( let pos = expected.iter().position(|f| *f == e).unwrap_or_else(|| {
"unexpected incident edge {e:?} of vertex {:?}", panic!("unexpected incident edge {e:?} of vertex {:?}", vertices[i])
vertices[i] });
));
expected.swap_remove(pos); expected.swap_remove(pos);
} }
assert!( assert!(
@@ -529,10 +532,12 @@ where
let pos = expected let pos = expected
.iter() .iter()
.position(|x| *x == incidence) .position(|x| *x == incidence)
.expect(&format!( .unwrap_or_else(|| {
"unexpected incidence {incidence:?} of vertex {:?} from iterator", panic!(
vertices[i] "unexpected incidence {incidence:?} of vertex {:?} from iterator",
)); vertices[i]
)
});
expected.swap_remove(pos); expected.swap_remove(pos);
} }
assert!( assert!(
@@ -611,10 +616,12 @@ where
for i in 0..2 { for i in 0..2 {
let mut iter = graph.incidences(vertices[i]); let mut iter = graph.incidences(vertices[i]);
for j in 0..K { for j in 0..K {
let current = iter.next().expect(&format!( let current = iter.next().unwrap_or_else(|| {
"incidence {j} missing, expected {K} incidences for vertex {:?}", panic!(
vertices[i] "incidence {j} missing, expected {K} incidences for vertex {:?}",
)); vertices[i]
)
});
assert_eq!( assert_eq!(
current.vertex, current.vertex,
vertices[1 - i], vertices[1 - i],
@@ -665,10 +672,12 @@ where
let pos = expected let pos = expected
.iter() .iter()
.position(|x| *x == incidence) .position(|x| *x == incidence)
.expect(&format!( .unwrap_or_else(|| {
"unexpected incidence {incidence:?} of vertex {:?} from cursor", panic!(
vertices[i] "unexpected incidence {incidence:?} of vertex {:?} from cursor",
)); vertices[i]
)
});
expected.swap_remove(pos); expected.swap_remove(pos);
} }
assert!( assert!(
@@ -710,10 +719,12 @@ where
for i in 0..2 { for i in 0..2 {
let mut cursor = graph.incidence_cursor(vertices[i]); let mut cursor = graph.incidence_cursor(vertices[i]);
for j in 0..K { for j in 0..K {
let current = cursor.next(&graph).expect(&format!( let current = cursor.next(&graph).unwrap_or_else(|| {
"incidence {j} missing, expected {K} incidences for vertex {:?}", panic!(
vertices[i] "incidence {j} missing, expected {K} incidences for vertex {:?}",
)); vertices[i]
)
});
assert_eq!( assert_eq!(
current.vertex, current.vertex,
vertices[1 - i], vertices[1 - i],
@@ -789,9 +800,9 @@ where
for u in graph.vertices() { for u in graph.vertices() {
let mut expected: Vec<_> = graph.incidences(u).map(|x| x.edge).collect(); let mut expected: Vec<_> = graph.incidences(u).map(|x| x.edge).collect();
for e in graph.incident_edges(u) { for e in graph.incident_edges(u) {
let pos = expected.iter().position(|f| *f == e).expect(&format!( let pos = expected.iter().position(|f| *f == e).unwrap_or_else(|| {
"incident edge {e:?} of vertex {u:?} missing from incidences" panic!("incident edge {e:?} of vertex {u:?} missing from incidences")
)); });
expected.swap_remove(pos); expected.swap_remove(pos);
} }
assert!( assert!(