diff --git a/benches/movingai.rs b/benches/movingai.rs index c285c8ac..69284b88 100644 --- a/benches/movingai.rs +++ b/benches/movingai.rs @@ -1,5 +1,7 @@ // Test with files from https://movingai.com/benchmarks/ +#![allow(clippy::cast_precision_loss)] + use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion}; use movingai::parser::{parse_map_file, parse_scen_file}; use movingai::{Coords2D, Map2D}; @@ -11,6 +13,7 @@ fn distance(a: &Coords2D, b: &Coords2D) -> R64 { r64((a.0 as f64 - b.0 as f64).hypot(a.1 as f64 - b.1 as f64)) } +#[allow(clippy::missing_panics_doc)] pub fn arena(c: &mut Criterion) { c.bench_function("arena", |b| { b.iter(|| { diff --git a/examples/sliding-puzzle.rs b/examples/sliding-puzzle.rs index 1b354a23..3193a559 100644 --- a/examples/sliding-puzzle.rs +++ b/examples/sliding-puzzle.rs @@ -1,3 +1,5 @@ +#![allow(clippy::cast_possible_truncation)] + use itertools::Itertools; use lazy_static::lazy_static; use pathfinding::prelude::{astar, idastar}; diff --git a/src/directed/edmonds_karp.rs b/src/directed/edmonds_karp.rs index 7338fa1c..0aa1e828 100644 --- a/src/directed/edmonds_karp.rs +++ b/src/directed/edmonds_karp.rs @@ -63,8 +63,14 @@ where let reverse = vertices.iter().collect::>(); let mut capacities = EK::new( vertices.len(), - reverse.get_index_of(source).unwrap(), - reverse.get_index_of(sink).unwrap(), + match reverse.get_index_of(source) { + Some(s) => s, + None => panic!("source not found in vertices"), + }, + match reverse.get_index_of(sink) { + Some(s) => s, + None => panic!("sink not found in vertices"), + }, ); for ((from, to), capacity) in caps { capacities.set_capacity( diff --git a/src/matrix.rs b/src/matrix.rs index 8ce29fa3..acea3f12 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -698,7 +698,10 @@ where IC: IntoIterator, { fn from_iter>(iter: T) -> Self { - Matrix::from_rows(iter).unwrap() + match Matrix::from_rows(iter) { + Ok(matrix) => matrix, + Err(e) => panic!("{e}"), + } } } @@ -735,7 +738,10 @@ macro_rules! matrix { let mut m = pathfinding::matrix::Matrix::new_empty($a.len()); m.extend(&$a).unwrap(); $( - m.extend(&$b).expect("all rows must have the same width"); + match m.extend(&$b) { + Ok(row) => row, + Err(_) => panic!("all rows must have the same width"), + } )* m }}; diff --git a/tests/codejam-2017-a.rs b/tests/codejam-2017-a.rs index adeb4eae..ca9e7a1b 100644 --- a/tests/codejam-2017-a.rs +++ b/tests/codejam-2017-a.rs @@ -1,6 +1,8 @@ // Problem A from the Google Code Jam finals 2017. // https://code.google.com/codejam/contest/dashboard?c=6314486#s=p0&a=0 +#![allow(clippy::cast_sign_loss)] + use pathfinding::prelude::*; use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; use std::io::prelude::*; @@ -35,10 +37,10 @@ fn read_ints(file: &mut dyn BufRead) -> Result, Error> { } fn test>(n: usize, file: &mut dyn BufRead) -> Result { - let ndices = read_ints(file)?[0]; + let n_dices = read_ints(file)?[0]; let mut dices = Vec::new(); let mut values = HashMap::new(); - for d in 0..ndices { + for d in 0..n_dices { let mut dice = read_ints(file)?; for v in dice.clone() { values.entry(v).or_insert_with(HashSet::new).insert(d); diff --git a/tests/dijkstra-all.rs b/tests/dijkstra-all.rs index 01f3aeb7..1c1ccecb 100644 --- a/tests/dijkstra-all.rs +++ b/tests/dijkstra-all.rs @@ -80,10 +80,10 @@ fn partial_paths() { // We cannot compare other paths since there is no guarantee that the // paths variable is up-to-date as the algorithm stopped prematurely. let cost = paths[&target].1; - let (path, dcost) = + let (path, dijkstra_cost) = dijkstra(&start, neighbours(network.clone()), |&n| n == target).unwrap(); assert_eq!( - cost, dcost, + cost, dijkstra_cost, "costs {start} -> {target} differ in {network:?}" ); let other_path = build_path(&target, &paths); diff --git a/tests/edmondskarp.rs b/tests/edmondskarp.rs index 72b42ba0..91082181 100644 --- a/tests/edmondskarp.rs +++ b/tests/edmondskarp.rs @@ -60,6 +60,7 @@ fn wikipedia_example_sparse() { wikipedia_example::>(); } +#[allow(clippy::cast_possible_truncation)] fn wikipedia_progressive_example>() { let successors = successors_wikipedia(); let size = successors.len(); @@ -154,20 +155,20 @@ fn modified_sparse() { } #[test] -#[should_panic] +#[should_panic(expected = "source is greater or equal than size")] fn empty() { let mut ek = DenseCapacity::::new(0, 0, 0); ek.augment(); } #[test] -#[should_panic] +#[should_panic(expected = "source not found in vertices")] fn unknown_source() { edmonds_karp_dense(&[1, 2, 3], &0, &3, Vec::<((i32, i32), i32)>::new()); } #[test] -#[should_panic] +#[should_panic(expected = "sink not found in vertices")] fn unknown_sink() { edmonds_karp_dense(&[1, 2, 3], &1, &4, Vec::<((i32, i32), i32)>::new()); } diff --git a/tests/gps.rs b/tests/gps.rs index 09629698..51a80459 100644 --- a/tests/gps.rs +++ b/tests/gps.rs @@ -1,4 +1,5 @@ #![cfg(test)] +#![allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] use pathfinding::prelude::*; use std::collections::HashMap; diff --git a/tests/kuhn_munkres.rs b/tests/kuhn_munkres.rs index 1d483447..e5ee273a 100644 --- a/tests/kuhn_munkres.rs +++ b/tests/kuhn_munkres.rs @@ -91,7 +91,7 @@ fn empty() { } #[test] -#[should_panic] +#[should_panic(expected = "number of rows must not be larger than number of columns")] fn unbalanced() { kuhn_munkres(&Matrix::new(3, 2, 0)); } diff --git a/tests/matrix.rs b/tests/matrix.rs index d8b9133f..b77fcbb2 100644 --- a/tests/matrix.rs +++ b/tests/matrix.rs @@ -1,6 +1,9 @@ #![cfg(test)] -use pathfinding::{matrix, matrix::Matrix}; +use pathfinding::{ + matrix, + matrix::{Matrix, MatrixFormatError}, +}; #[test] fn sm() { @@ -55,7 +58,7 @@ fn from_vec_error() { } #[test] -#[should_panic] +#[should_panic(expected = "unable to create a matrix with empty rows")] fn new_empty_row_panic() { let _ = Matrix::new(1, 0, 42); } @@ -83,15 +86,19 @@ fn square_from_vec() { } #[test] -#[should_panic] fn from_vec_panic() { - Matrix::from_vec(2, 3, vec![1, 2, 3]).unwrap(); + assert!(matches!( + Matrix::from_vec(2, 3, vec![1, 2, 3]), + Err(MatrixFormatError::WrongLength) + )); } #[test] -#[should_panic] fn square_from_vec_panic() { - Matrix::square_from_vec(vec![1, 2, 3]).unwrap(); + assert!(matches!( + Matrix::square_from_vec(vec![1, 2, 3]), + Err(MatrixFormatError::WrongLength) + )); } #[test] @@ -175,13 +182,13 @@ fn non_square_rotate() { } #[test] -#[should_panic] +#[should_panic(expected = "this operation would create a matrix with empty rows")] fn no_rows_rotated_cw_panic() { let _ = Matrix::::new_empty(10).rotated_cw(1); } #[test] -#[should_panic] +#[should_panic(expected = "this operation would create a matrix with empty rows")] fn no_rows_rotated_ccw_panic() { let _ = Matrix::::new_empty(10).rotated_ccw(1); } @@ -215,7 +222,7 @@ fn transpose() { } #[test] -#[should_panic] +#[should_panic(expected = "this operation would create a matrix with empty rows")] fn no_rows_transposed_panic() { let _ = Matrix::::new_empty(10).transposed(); } @@ -334,13 +341,13 @@ fn matrix_macro() { } #[test] -#[should_panic] +#[should_panic(expected = "all rows must have the same width")] fn matrix_macro_inconsistent_panic() { matrix![[0, 1, 2], [3, 4]]; } #[test] -#[should_panic] +#[should_panic(expected = "all rows must have the same width")] fn matrix_macro_inconsistent_panic_2() { matrix![0, 1, 2; 3, 4]; } @@ -516,7 +523,7 @@ fn from_iter() { } #[test] -#[should_panic] +#[should_panic(expected = "provided data does not correspond to the expected length")] fn from_iter_error() { let _ = (1..3) .map(|n| (1..n).map(move |x| x * n))