Skip to content

Commit ee5e2ce

Browse files
authored
Fix cargo clippy not covering rustworkx-core tests (#1417)
* First batch of fixes * Second batch of fixes * Third batch of fixes * Fourth batch of fixes * Last batch of fixes
1 parent 6ffa9bd commit ee5e2ce

File tree

10 files changed

+64
-69
lines changed

10 files changed

+64
-69
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ jobs:
3535
- name: Rust Format
3636
run: cargo fmt --all -- --check
3737
- name: Clippy
38-
run: cargo clippy --all-targets -- -D warnings
38+
run: cargo clippy --workspace --all-targets -- -D warnings
3939
- name: Black Codestyle Format
4040
run: black --check --diff retworkx rustworkx retworkx tests
4141
- name: Python Lint
4242
run: ruff check rustworkx retworkx setup.py tests
4343
- name: Check stray release notes
4444
run: python tools/find_stray_release_notes.py
4545
- name: rustworkx-core Rust Tests
46-
run: pushd rustworkx-core && cargo test && popd
46+
run: cargo test --workspace
4747
- name: rustworkx-core Docs
48-
run: pushd rustworkx-core && cargo doc && popd
48+
run: cargo doc -p rustworkx-core
4949
env:
5050
RUSTDOCFLAGS: '-D warnings'
5151
- uses: actions/upload-artifact@v4

CONTRIBUTING.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,9 @@ https://doc.rust-lang.org/book/ch11-01-writing-tests.html
203203
204204
The rustworkx-core tests can be run with:
205205
```
206-
cargo test
206+
cargo test --workspace
207207
```
208208
209-
from the `rustworkx-core` directory.
210-
211209
### Fuzz Testing in rustworkx
212210
213211
We use cargo-fuzz to test rustworkx for unexpected crashes or undefined behavior. Follow these steps to run fuzzing locally.
@@ -271,12 +269,18 @@ what CI is checking.
271269
##### Lint
272270
273271
An additional step is to run [clippy](https://github.com/rust-lang/rust-clippy)
274-
on your changes. You can run it by running:
272+
on your changes. You can execute it by running:
275273
276274
```bash
277275
cargo clippy
278276
```
279277
278+
If you want a more detailed feedback identical to CI, run instead:
279+
280+
```bash
281+
cargo clippy --workspace --all-targets -- -D warnings
282+
```
283+
280284
#### Python
281285
282286
Python is used primarily for tests and some small pieces of packaging
@@ -310,18 +314,17 @@ you can view locally in a web browser.
310314
To build the rustworkx-core documentation you will use rust-doc. You can do this
311315
by running:
312316
```
313-
cargo doc
317+
cargo doc -p rustworkx-core
314318
```
315-
from the `rustworkx-core` directory (which is the root of the `rustworkx-core`
316-
crate. After it's built the compiled documentation will be located in
319+
After it's built the compiled documentation will be located in
317320
`target/doc/rustworkx_core` (which is off the repo root not the `rustworkx-core`
318321
dir)
319322
320323
You can build and open the documentation directly in your configured default
321324
web browser by running:
322325
323326
```
324-
cargo doc --open
327+
cargo doc -p rustworkx-core --open
325328
```
326329
327330
### Type Annotations

rustworkx-core/src/bipartite_coloring.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -969,9 +969,8 @@ mod test_bipartite_coloring {
969969
if n > 2 * k {
970970
let graph: petgraph::graph::UnGraph<(), ()> =
971971
petersen_graph(n, k, || (), || ()).unwrap();
972-
match bipartite_edge_color(&graph) {
973-
Ok(_) => panic!("This should error"),
974-
Err(_) => (),
972+
if bipartite_edge_color(&graph).is_ok() {
973+
panic!("This should error")
975974
}
976975
}
977976
}
@@ -980,9 +979,9 @@ mod test_bipartite_coloring {
980979

981980
#[test]
982981
fn test_bipartite_random_graphs_undirected() {
983-
for num_l_nodes in vec![5, 10, 15, 20] {
984-
for num_r_nodes in vec![5, 10, 15, 20] {
985-
for probability in vec![0.1, 0.3, 0.5, 0.7, 0.9] {
982+
for num_l_nodes in [5, 10, 15, 20] {
983+
for num_r_nodes in [5, 10, 15, 20] {
984+
for probability in [0.1, 0.3, 0.5, 0.7, 0.9] {
986985
let graph: petgraph::graph::UnGraph<(), ()> = random_bipartite_graph(
987986
num_l_nodes,
988987
num_r_nodes,
@@ -1014,9 +1013,9 @@ mod test_bipartite_coloring {
10141013

10151014
#[test]
10161015
fn test_bipartite_random_graphs_directed() {
1017-
for num_l_nodes in vec![5, 10, 15, 20] {
1018-
for num_r_nodes in vec![5, 10, 15, 20] {
1019-
for probability in vec![0.1, 0.3, 0.5, 0.7, 0.9] {
1016+
for num_l_nodes in [5, 10, 15, 20] {
1017+
for num_r_nodes in [5, 10, 15, 20] {
1018+
for probability in [0.1, 0.3, 0.5, 0.7, 0.9] {
10201019
let graph: petgraph::graph::DiGraph<(), ()> = random_bipartite_graph(
10211020
num_l_nodes,
10221021
num_r_nodes,

rustworkx-core/src/coloring.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ mod test_node_coloring {
10171017
let graph = Graph::<(), (), Undirected>::new_undirected();
10181018
let preset_color_fn = |_| Ok::<Option<usize>, Infallible>(None);
10191019

1020-
for strategy in vec![
1020+
for strategy in [
10211021
ColoringStrategy::Degree,
10221022
ColoringStrategy::Saturation,
10231023
ColoringStrategy::IndependentSet,
@@ -1308,7 +1308,7 @@ mod test_node_coloring {
13081308
path_graph(Some(7), None, || (), || (), false).unwrap();
13091309
let preset_color_fn = |_| Ok::<Option<usize>, Infallible>(None);
13101310

1311-
for strategy in vec![
1311+
for strategy in [
13121312
ColoringStrategy::Degree,
13131313
ColoringStrategy::Saturation,
13141314
ColoringStrategy::IndependentSet,
@@ -1326,7 +1326,7 @@ mod test_node_coloring {
13261326
cycle_graph(Some(15), None, || (), || (), false).unwrap();
13271327
let preset_color_fn = |_| Ok::<Option<usize>, Infallible>(None);
13281328

1329-
for strategy in vec![
1329+
for strategy in [
13301330
ColoringStrategy::Degree,
13311331
ColoringStrategy::Saturation,
13321332
ColoringStrategy::IndependentSet,
@@ -1344,7 +1344,7 @@ mod test_node_coloring {
13441344
heavy_hex_graph(7, || (), || (), false).unwrap();
13451345
let preset_color_fn = |_| Ok::<Option<usize>, Infallible>(None);
13461346

1347-
for strategy in vec![
1347+
for strategy in [
13481348
ColoringStrategy::Degree,
13491349
ColoringStrategy::Saturation,
13501350
ColoringStrategy::IndependentSet,
@@ -1362,7 +1362,7 @@ mod test_node_coloring {
13621362
complete_graph(Some(10), None, || (), || ()).unwrap();
13631363
let preset_color_fn = |_| Ok::<Option<usize>, Infallible>(None);
13641364

1365-
for strategy in vec![
1365+
for strategy in [
13661366
ColoringStrategy::Degree,
13671367
ColoringStrategy::Saturation,
13681368
ColoringStrategy::IndependentSet,

rustworkx-core/src/connectivity/johnson_simple_cycles.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ mod test_longest_path {
489489
);
490490
let mut cycles_iter = johnson_simple_cycles(&graph, None);
491491
let mut res = 0;
492-
while let Some(_) = cycles_iter.next(&graph) {
492+
while cycles_iter.next(&graph).is_some() {
493493
res += 1;
494494
}
495495
assert_eq!(res, 3 * k);
@@ -523,7 +523,7 @@ mod test_longest_path {
523523
);
524524
let mut cycles_iter = johnson_simple_cycles(&graph, None);
525525
let mut res = 0;
526-
while let Some(_) = cycles_iter.next(&graph) {
526+
while cycles_iter.next(&graph).is_some() {
527527
res += 1;
528528
}
529529
assert_eq!(res, 3 * k);

rustworkx-core/src/dag_algo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ mod test_collect_runs {
14181418
let mut runs = collect_runs(&graph, |_| -> Result<bool, ()> { Ok(true) }).expect("Some");
14191419

14201420
let run = runs.next();
1421-
assert!(run == None);
1421+
assert!(run.is_none());
14221422

14231423
let runs = collect_runs(&graph, |_| -> Result<bool, ()> { Ok(true) }).expect("Some");
14241424

rustworkx-core/src/generators/hexagonal_lattice_graph.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -380,21 +380,21 @@ mod tests {
380380

381381
fn check_expected_edges_directed<T>(
382382
graph: &petgraph::graph::DiGraph<T, ()>,
383-
expected_edges: &Vec<(usize, usize)>,
383+
expected_edges: &[(usize, usize)],
384384
) {
385385
assert_eq!(graph.edge_count(), expected_edges.len());
386386

387387
let edge_set: HashSet<(usize, usize)> = graph
388388
.edge_references()
389389
.map(|edge| (edge.source().index(), edge.target().index()))
390390
.collect();
391-
let expected_set: HashSet<(usize, usize)> = expected_edges.iter().map(|&e| e).collect();
391+
let expected_set: HashSet<(usize, usize)> = expected_edges.iter().copied().collect();
392392
assert_eq!(edge_set, expected_set);
393393
}
394394

395395
fn check_expected_edges_undirected(
396396
graph: &petgraph::graph::UnGraph<(), ()>,
397-
expected_edges: &Vec<(usize, usize)>,
397+
expected_edges: &[(usize, usize)],
398398
) {
399399
assert_eq!(graph.edge_count(), expected_edges.len());
400400

@@ -409,13 +409,10 @@ mod tests {
409409
let edge_set: HashSet<(usize, usize)> = graph
410410
.edge_references()
411411
.map(|edge| (edge.source().index(), edge.target().index()))
412-
.map(|e| sorted_pair(e))
413-
.collect();
414-
let expected_set: HashSet<(usize, usize)> = expected_edges
415-
.iter()
416-
.map(|&e| e)
417-
.map(|e| sorted_pair(e))
412+
.map(&sorted_pair)
418413
.collect();
414+
let expected_set: HashSet<(usize, usize)> =
415+
expected_edges.iter().copied().map(&sorted_pair).collect();
419416
assert_eq!(edge_set, expected_set);
420417
}
421418

rustworkx-core/src/generators/random_graph.rs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ where
334334
/// use rustworkx_core::generators::sbm_random_graph;
335335
///
336336
/// let g = sbm_random_graph::<petgraph::graph::DiGraph<(), ()>, (), _, _, ()>(
337-
/// &vec![1, 2],
337+
/// &[1, 2],
338338
/// &ndarray::arr2(&[[0., 1.], [0., 1.]]).view(),
339339
/// true,
340340
/// Some(10),
@@ -1018,7 +1018,7 @@ mod tests {
10181018
#[test]
10191019
fn test_sbm_directed_complete_blocks_loops() {
10201020
let g = sbm_random_graph::<petgraph::graph::DiGraph<(), ()>, (), _, _, ()>(
1021-
&vec![1, 2],
1021+
&[1, 2],
10221022
&ndarray::arr2(&[[0., 1.], [0., 1.]]).view(),
10231023
true,
10241024
Some(10),
@@ -1029,16 +1029,16 @@ mod tests {
10291029
assert_eq!(g.node_count(), 3);
10301030
assert_eq!(g.edge_count(), 6);
10311031
for (u, v) in [(1, 1), (1, 2), (2, 1), (2, 2), (0, 1), (0, 2)] {
1032-
assert_eq!(g.contains_edge(u.into(), v.into()), true);
1032+
assert!(g.contains_edge(u.into(), v.into()));
10331033
}
1034-
assert_eq!(g.contains_edge(1.into(), 0.into()), false);
1035-
assert_eq!(g.contains_edge(2.into(), 0.into()), false);
1034+
assert!(!g.contains_edge(1.into(), 0.into()));
1035+
assert!(!g.contains_edge(2.into(), 0.into()));
10361036
}
10371037

10381038
#[test]
10391039
fn test_sbm_undirected_complete_blocks_loops() {
10401040
let g = sbm_random_graph::<petgraph::graph::UnGraph<(), ()>, (), _, _, ()>(
1041-
&vec![1, 2],
1041+
&[1, 2],
10421042
&ndarray::arr2(&[[0., 1.], [1., 1.]]).view(),
10431043
true,
10441044
Some(10),
@@ -1049,15 +1049,15 @@ mod tests {
10491049
assert_eq!(g.node_count(), 3);
10501050
assert_eq!(g.edge_count(), 5);
10511051
for (u, v) in [(1, 1), (1, 2), (2, 2), (0, 1), (0, 2)] {
1052-
assert_eq!(g.contains_edge(u.into(), v.into()), true);
1052+
assert!(g.contains_edge(u.into(), v.into()));
10531053
}
1054-
assert_eq!(g.contains_edge(0.into(), 0.into()), false);
1054+
assert!(!g.contains_edge(0.into(), 0.into()));
10551055
}
10561056

10571057
#[test]
10581058
fn test_sbm_directed_complete_blocks_noloops() {
10591059
let g = sbm_random_graph::<petgraph::graph::DiGraph<(), ()>, (), _, _, ()>(
1060-
&vec![1, 2],
1060+
&[1, 2],
10611061
&ndarray::arr2(&[[0., 1.], [0., 1.]]).view(),
10621062
false,
10631063
Some(10),
@@ -1068,19 +1068,19 @@ mod tests {
10681068
assert_eq!(g.node_count(), 3);
10691069
assert_eq!(g.edge_count(), 4);
10701070
for (u, v) in [(1, 2), (2, 1), (0, 1), (0, 2)] {
1071-
assert_eq!(g.contains_edge(u.into(), v.into()), true);
1071+
assert!(g.contains_edge(u.into(), v.into()));
10721072
}
1073-
assert_eq!(g.contains_edge(1.into(), 0.into()), false);
1074-
assert_eq!(g.contains_edge(2.into(), 0.into()), false);
1073+
assert!(!g.contains_edge(1.into(), 0.into()));
1074+
assert!(!g.contains_edge(2.into(), 0.into()));
10751075
for u in 0..2 {
1076-
assert_eq!(g.contains_edge(u.into(), u.into()), false);
1076+
assert!(!g.contains_edge(u.into(), u.into()));
10771077
}
10781078
}
10791079

10801080
#[test]
10811081
fn test_sbm_undirected_complete_blocks_noloops() {
10821082
let g = sbm_random_graph::<petgraph::graph::UnGraph<(), ()>, (), _, _, ()>(
1083-
&vec![1, 2],
1083+
&[1, 2],
10841084
&ndarray::arr2(&[[0., 1.], [1., 1.]]).view(),
10851085
false,
10861086
Some(10),
@@ -1091,17 +1091,17 @@ mod tests {
10911091
assert_eq!(g.node_count(), 3);
10921092
assert_eq!(g.edge_count(), 3);
10931093
for (u, v) in [(1, 2), (0, 1), (0, 2)] {
1094-
assert_eq!(g.contains_edge(u.into(), v.into()), true);
1094+
assert!(g.contains_edge(u.into(), v.into()));
10951095
}
10961096
for u in 0..2 {
1097-
assert_eq!(g.contains_edge(u.into(), u.into()), false);
1097+
assert!(!g.contains_edge(u.into(), u.into()));
10981098
}
10991099
}
11001100

11011101
#[test]
11021102
fn test_sbm_bad_array_rows_error() {
11031103
match sbm_random_graph::<petgraph::graph::DiGraph<(), ()>, (), _, _, ()>(
1104-
&vec![1, 2],
1104+
&[1, 2],
11051105
&ndarray::arr2(&[[0., 1.], [1., 1.], [1., 1.]]).view(),
11061106
true,
11071107
Some(10),
@@ -1116,7 +1116,7 @@ mod tests {
11161116

11171117
fn test_sbm_bad_array_cols_error() {
11181118
match sbm_random_graph::<petgraph::graph::DiGraph<(), ()>, (), _, _, ()>(
1119-
&vec![1, 2],
1119+
&[1, 2],
11201120
&ndarray::arr2(&[[0., 1., 1.], [1., 1., 1.]]).view(),
11211121
true,
11221122
Some(10),
@@ -1131,7 +1131,7 @@ mod tests {
11311131
#[test]
11321132
fn test_sbm_asymmetric_array_error() {
11331133
match sbm_random_graph::<petgraph::graph::UnGraph<(), ()>, (), _, _, ()>(
1134-
&vec![1, 2],
1134+
&[1, 2],
11351135
&ndarray::arr2(&[[0., 1.], [0., 1.]]).view(),
11361136
true,
11371137
Some(10),
@@ -1146,7 +1146,7 @@ mod tests {
11461146
#[test]
11471147
fn test_sbm_invalid_probability_error() {
11481148
match sbm_random_graph::<petgraph::graph::UnGraph<(), ()>, (), _, _, ()>(
1149-
&vec![1, 2],
1149+
&[1, 2],
11501150
&ndarray::arr2(&[[0., 1.], [0., -1.]]).view(),
11511151
true,
11521152
Some(10),
@@ -1161,7 +1161,7 @@ mod tests {
11611161
#[test]
11621162
fn test_sbm_empty_error() {
11631163
match sbm_random_graph::<petgraph::graph::DiGraph<(), ()>, (), _, _, ()>(
1164-
&vec![],
1164+
&[],
11651165
&ndarray::arr2(&[[]]).view(),
11661166
true,
11671167
Some(10),
@@ -1355,10 +1355,7 @@ mod tests {
13551355
}
13561356
#[test]
13571357
fn test_hyperbolic_dist_inf() {
1358-
assert_eq!(
1359-
hyperbolic_distance(&[f64::INFINITY, 0.], &[0., 0.]).is_nan(),
1360-
true
1361-
);
1358+
assert!(hyperbolic_distance(&[f64::INFINITY, 0.], &[0., 0.]).is_nan());
13621359
}
13631360

13641361
#[test]

rustworkx-core/src/line_graph.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ where
104104
}
105105

106106
#[cfg(test)]
107-
108107
mod test_line_graph {
109108
use crate::line_graph::line_graph;
110109
use crate::petgraph::visit::EdgeRef;

0 commit comments

Comments
 (0)