From 7cfee9cce5dd688307acff6076afa441fc121b2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Mon, 12 Oct 2026 21:52:51 +0200 Subject: [PATCH] Remove function calls inside of 'expect' --- src/testing/fixtures.rs | 16 ++-- .../graph_topology_deletion_testing.rs | 30 +++++--- src/testing/graph_topology_testing.rs | 73 +++++++++++-------- 3 files changed, 69 insertions(+), 50 deletions(-) diff --git a/src/testing/fixtures.rs b/src/testing/fixtures.rs index 5689c28..52e8953 100644 --- a/src/testing/fixtures.rs +++ b/src/testing/fixtures.rs @@ -318,10 +318,12 @@ where G::Vertex: Debug, G::Edge: Debug, { - let path = path_option.expect(&format!( - "path should exist between source vertex {:?} and connected targets {:?}", - source, targets - )); + let path = path_option.unwrap_or_else(|| { + panic!( + "path should exist between source vertex {:?} and connected targets {:?}", + source, targets + ) + }); if targets.contains(&source) { assert!( @@ -402,9 +404,9 @@ pub fn assert_isomorphic( .position(|x| { vertex_map(x.vertex) == incidence.vertex && edge_map(x.edge) == incidence.edge }) - .expect(&format!( - "unexpected incidence {incidence:?} of vertex {v:?} in the other graph" - )); + .unwrap_or_else(|| { + panic!("unexpected incidence {incidence:?} of vertex {v:?} in the other graph") + }); expected.swap_remove(pos); } assert!( diff --git a/src/testing/graph_topology_deletion_testing.rs b/src/testing/graph_topology_deletion_testing.rs index d1d82e7..1ef5217 100644 --- a/src/testing/graph_topology_deletion_testing.rs +++ b/src/testing/graph_topology_deletion_testing.rs @@ -452,10 +452,12 @@ fn assert_vertex_incidences( let pos = expected .iter() .position(|x| *x == incidence) - .expect(&format!( - "unexpected incidence {incidence:?} of vertex {:?} from iterator after delete", - v - )); + .unwrap_or_else(|| { + panic!( + "unexpected incidence {incidence:?} of vertex {:?} from iterator after delete", + v + ) + }); expected.swap_remove(pos); } assert!( @@ -479,10 +481,12 @@ fn assert_vertex_incidence_cursor( let pos = expected .iter() .position(|x| *x == incidence) - .expect(&format!( - "unexpected incidence {incidence:?} of vertex {:?} from cursor after delete", - v - )); + .unwrap_or_else(|| { + panic!( + "unexpected incidence {incidence:?} of vertex {:?} from cursor after delete", + v + ) + }); expected.swap_remove(pos); } assert!( @@ -508,10 +512,12 @@ fn assert_incident_edges_after_delete( v ); for e in graph.incident_edges(v) { - let pos = expected.iter().position(|f| *f == e).expect(&format!( - "unexpected incident edge {e:?} of vertex {:?} after delete", - v - )); + let pos = expected.iter().position(|f| *f == e).unwrap_or_else(|| { + panic!( + "unexpected incident edge {e:?} of vertex {:?} after delete", + v + ) + }); expected.swap_remove(pos); } assert!( diff --git a/src/testing/graph_topology_testing.rs b/src/testing/graph_topology_testing.rs index d595c2d..df58962 100644 --- a/src/testing/graph_topology_testing.rs +++ b/src/testing/graph_topology_testing.rs @@ -278,10 +278,12 @@ where let i = expected_adjacency .iter() .position(|w| *w == v) - .expect(&format!( - "unexpected adjacent vertex {v:?} of {:?} from iterator", - vertices[4] - )); + .unwrap_or_else(|| { + panic!( + "unexpected adjacent vertex {v:?} of {:?} from iterator", + vertices[4] + ) + }); expected_adjacency.swap_remove(i); } assert_eq!( @@ -443,10 +445,12 @@ where ); 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).expect(&format!( - "unexpected incident edge {e:?} of vertex {:?} from iterator", - vertices[i] - )); + let pos = expected.iter().position(|f| *f == e).unwrap_or_else(|| { + panic!( + "unexpected incident edge {e:?} of vertex {:?} from iterator", + vertices[i] + ) + }); expected.swap_remove(pos); } assert!( @@ -487,10 +491,9 @@ where for i in 0..2 { let mut expected = edges.to_vec(); for e in graph.incident_edges(vertices[i]) { - let pos = expected.iter().position(|f| *f == e).expect(&format!( - "unexpected incident edge {e:?} of vertex {:?}", - vertices[i] - )); + let pos = expected.iter().position(|f| *f == e).unwrap_or_else(|| { + panic!("unexpected incident edge {e:?} of vertex {:?}", vertices[i]) + }); expected.swap_remove(pos); } assert!( @@ -529,10 +532,12 @@ where let pos = expected .iter() .position(|x| *x == incidence) - .expect(&format!( - "unexpected incidence {incidence:?} of vertex {:?} from iterator", - vertices[i] - )); + .unwrap_or_else(|| { + panic!( + "unexpected incidence {incidence:?} of vertex {:?} from iterator", + vertices[i] + ) + }); expected.swap_remove(pos); } assert!( @@ -611,10 +616,12 @@ where for i in 0..2 { let mut iter = graph.incidences(vertices[i]); for j in 0..K { - let current = iter.next().expect(&format!( - "incidence {j} missing, expected {K} incidences for vertex {:?}", - vertices[i] - )); + let current = iter.next().unwrap_or_else(|| { + panic!( + "incidence {j} missing, expected {K} incidences for vertex {:?}", + vertices[i] + ) + }); assert_eq!( current.vertex, vertices[1 - i], @@ -665,10 +672,12 @@ where let pos = expected .iter() .position(|x| *x == incidence) - .expect(&format!( - "unexpected incidence {incidence:?} of vertex {:?} from cursor", - vertices[i] - )); + .unwrap_or_else(|| { + panic!( + "unexpected incidence {incidence:?} of vertex {:?} from cursor", + vertices[i] + ) + }); expected.swap_remove(pos); } assert!( @@ -710,10 +719,12 @@ where for i in 0..2 { let mut cursor = graph.incidence_cursor(vertices[i]); for j in 0..K { - let current = cursor.next(&graph).expect(&format!( - "incidence {j} missing, expected {K} incidences for vertex {:?}", - vertices[i] - )); + let current = cursor.next(&graph).unwrap_or_else(|| { + panic!( + "incidence {j} missing, expected {K} incidences for vertex {:?}", + vertices[i] + ) + }); assert_eq!( current.vertex, vertices[1 - i], @@ -789,9 +800,9 @@ 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).expect(&format!( - "incident edge {e:?} of vertex {u:?} missing from incidences" - )); + 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!(