diff --git a/Cargo.toml b/Cargo.toml index c709d51f..dcd8f0e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,8 +10,8 @@ version = "4.13.0" authors = ["Samuel Tardieu "] categories = ["algorithms"] readme = "README.md" -edition = "2021" -rust-version = "1.82.0" +edition = "2024" +rust-version = "1.85.0" [package.metadata.release] sign-commit = true diff --git a/benches/algos-fill.rs b/benches/algos-fill.rs index b02e5d23..cf7c7a75 100644 --- a/benches/algos-fill.rs +++ b/benches/algos-fill.rs @@ -1,7 +1,7 @@ // This version uses a filler in the Pt structure to increase // the cost of cloning a node. -use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion}; +use codspeed_criterion_compat::{Criterion, criterion_group, criterion_main}; use pathfinding::prelude::{astar, bfs, dfs, dijkstra, fringe, idastar, iddfs}; #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] diff --git a/benches/algos.rs b/benches/algos.rs index 6df282df..ed734b49 100644 --- a/benches/algos.rs +++ b/benches/algos.rs @@ -1,4 +1,4 @@ -use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion}; +use codspeed_criterion_compat::{Criterion, criterion_group, criterion_main}; use itertools::Itertools; use pathfinding::prelude::{ astar, bfs, dfs, dijkstra, fringe, idastar, iddfs, separate_components, diff --git a/benches/edmondskarp.rs b/benches/edmondskarp.rs index 943c03f0..be7dd03d 100644 --- a/benches/edmondskarp.rs +++ b/benches/edmondskarp.rs @@ -1,6 +1,6 @@ -use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion}; +use codspeed_criterion_compat::{Criterion, criterion_group, criterion_main}; use pathfinding::directed::edmonds_karp::{ - edmonds_karp, DenseCapacity, EKFlows, EdmondsKarp, SparseCapacity, + DenseCapacity, EKFlows, EdmondsKarp, SparseCapacity, edmonds_karp, }; use std::collections::HashMap; diff --git a/benches/kuhn_munkres.rs b/benches/kuhn_munkres.rs index 2a056977..775f3bea 100644 --- a/benches/kuhn_munkres.rs +++ b/benches/kuhn_munkres.rs @@ -1,5 +1,5 @@ -use codspeed_criterion_compat::{criterion_group, criterion_main, BenchmarkId, Criterion}; -use pathfinding::prelude::{kuhn_munkres, Matrix}; +use codspeed_criterion_compat::{BenchmarkId, Criterion, criterion_group, criterion_main}; +use pathfinding::prelude::{Matrix, kuhn_munkres}; use rand::{Rng, SeedableRng}; use rand_xorshift::XorShiftRng; diff --git a/benches/matrices.rs b/benches/matrices.rs index 0a94993a..a5057976 100644 --- a/benches/matrices.rs +++ b/benches/matrices.rs @@ -1,4 +1,4 @@ -use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion}; +use codspeed_criterion_compat::{Criterion, criterion_group, criterion_main}; use pathfinding::matrix::Matrix; #[expect(clippy::missing_panics_doc)] diff --git a/benches/movingai.rs b/benches/movingai.rs index 8429f89f..a7c51c0a 100644 --- a/benches/movingai.rs +++ b/benches/movingai.rs @@ -1,6 +1,6 @@ // Test with files from https://movingai.com/benchmarks/ -use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion}; +use codspeed_criterion_compat::{Criterion, criterion_group, criterion_main}; use movingai::parser::{parse_map_file, parse_scen_file}; use movingai::{Coords2D, Map2D}; use noisy_float::prelude::*; diff --git a/benches/separate_components.rs b/benches/separate_components.rs index 0127b60a..38a709cf 100644 --- a/benches/separate_components.rs +++ b/benches/separate_components.rs @@ -1,7 +1,7 @@ -use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion}; +use codspeed_criterion_compat::{Criterion, criterion_group, criterion_main}; use itertools::Itertools; use pathfinding::prelude::separate_components; -use rand::{prelude::SliceRandom, Rng, RngCore, SeedableRng}; +use rand::{Rng, RngCore, SeedableRng, prelude::SliceRandom}; use rand_xorshift::XorShiftRng; use std::collections::HashSet; diff --git a/src/directed/dijkstra.rs b/src/directed/dijkstra.rs index a1198106..fd3d9be1 100644 --- a/src/directed/dijkstra.rs +++ b/src/directed/dijkstra.rs @@ -99,7 +99,7 @@ where reached.map(|target| { ( reverse_path(&parents, |&(p, _)| p, target), - parents.get_index(target).unwrap().1 .1, + parents.get_index(target).unwrap().1.1, ) }) } diff --git a/src/directed/edmonds_karp.rs b/src/directed/edmonds_karp.rs index 2f809ded..981742d0 100644 --- a/src/directed/edmonds_karp.rs +++ b/src/directed/edmonds_karp.rs @@ -8,7 +8,7 @@ //! edges. use super::bfs::bfs; -use crate::{matrix::Matrix, FxIndexSet}; +use crate::{FxIndexSet, matrix::Matrix}; use num_traits::{Bounded, Signed, Zero}; use std::collections::{BTreeMap, BTreeSet, VecDeque}; use std::hash::Hash; diff --git a/src/grid.rs b/src/grid.rs index 25c28df3..c58e12f4 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -2,10 +2,10 @@ //! without diagonal links. use super::matrix::Matrix; +use crate::FxIndexSet; use crate::directed::bfs::bfs_reach; use crate::directed::dfs::dfs_reach; use crate::utils::constrain; -use crate::FxIndexSet; use num_traits::ToPrimitive; use std::collections::BTreeSet; use std::fmt; diff --git a/src/kuhn_munkres.rs b/src/kuhn_munkres.rs index e37ee339..ae9bf7b3 100644 --- a/src/kuhn_munkres.rs +++ b/src/kuhn_munkres.rs @@ -3,7 +3,7 @@ //! [Kuhn-Munkres algorithm](https://en.wikipedia.org/wiki/Hungarian_algorithm) //! (also known as Hungarian algorithm). -use crate::{matrix::Matrix, FxIndexSet}; +use crate::{FxIndexSet, matrix::Matrix}; use num_traits::{Bounded, Signed, Zero}; use std::iter::Sum; diff --git a/src/lib.rs b/src/lib.rs index f070a2b0..622d8433 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,7 +76,7 @@ //! in this context, you can wrap them into compliant types using the //! [ordered-float](https://crates.io/crates/ordered-float) crate. //! -//! The minimum supported Rust version (MSRV) is Rust 1.82.0. +//! The minimum supported Rust version (MSRV) is Rust 1.85.0. //! //! [A*]: https://en.wikipedia.org/wiki/A*_search_algorithm //! [BFS]: https://en.wikipedia.org/wiki/Breadth-first_search diff --git a/tests/astar_bag.rs b/tests/astar_bag.rs index bfad17ff..f4a12158 100644 --- a/tests/astar_bag.rs +++ b/tests/astar_bag.rs @@ -22,15 +22,12 @@ fn multiple_sinks() { ) .unwrap(); assert_eq!(cost, 4); - assert_eq!( - solutions.sorted().collect_vec(), - vec![ - vec![1, 2, 4], - vec![1, 2, 5, 6, 7], - vec![1, 3, 4], - vec![1, 3, 5, 6, 7], - ] - ); + assert_eq!(solutions.sorted().collect_vec(), vec![ + vec![1, 2, 4], + vec![1, 2, 5, 6, 7], + vec![1, 3, 4], + vec![1, 3, 5, 6, 7], + ]); } #[test] diff --git a/tests/cliques.rs b/tests/cliques.rs index 9faba56e..38445c95 100644 --- a/tests/cliques.rs +++ b/tests/cliques.rs @@ -24,13 +24,9 @@ fn test_same_node_appears_in_multiple_clique() { let cliques_as_vectors: Vec> = sort(&cliques); assert_eq!( - vec![ - vec![1, 5, 9], - vec![2, 6], - vec![3, 6, 9], - vec![3, 7], - vec![4, 8] - ], + vec![vec![1, 5, 9], vec![2, 6], vec![3, 6, 9], vec![3, 7], vec![ + 4, 8 + ]], cliques_as_vectors ); } diff --git a/tests/connected-components.rs b/tests/connected-components.rs index 15313ce8..0e3ba43a 100644 --- a/tests/connected-components.rs +++ b/tests/connected-components.rs @@ -36,10 +36,9 @@ fn basic_components() { let mut c = components(&[vec![1, 2], vec![3, 4], vec![5, 6], vec![1, 4, 7]]); c.sort_unstable_by_key(|v| *v.iter().min().unwrap()); assert_eq!(c.len(), 2); - assert_eq!( - c[0].clone().into_iter().sorted().collect_vec(), - vec![1, 2, 3, 4, 7] - ); + assert_eq!(c[0].clone().into_iter().sorted().collect_vec(), vec![ + 1, 2, 3, 4, 7 + ]); assert_eq!(c[1].clone().into_iter().sorted().collect_vec(), vec![5, 6]); } @@ -48,10 +47,9 @@ fn empty_components() { let mut c = components(&[vec![1, 2], vec![3, 4], vec![], vec![1, 4, 7]]); c.sort_unstable_by_key(|v| *v.iter().min().unwrap()); assert_eq!(c.len(), 1); - assert_eq!( - c[0].clone().into_iter().sorted().collect_vec(), - vec![1, 2, 3, 4, 7] - ); + assert_eq!(c[0].clone().into_iter().sorted().collect_vec(), vec![ + 1, 2, 3, 4, 7 + ]); } #[test] @@ -67,14 +65,12 @@ fn basic_connected_components() { }); c.sort_unstable_by_key(|v| *v.iter().min().unwrap()); assert_eq!(c.len(), 2); - assert_eq!( - c[0].clone().into_iter().sorted().collect_vec(), - vec![1, 3, 5, 7] - ); - assert_eq!( - c[1].clone().into_iter().sorted().collect_vec(), - vec![2, 4, 6, 8] - ); + assert_eq!(c[0].clone().into_iter().sorted().collect_vec(), vec![ + 1, 3, 5, 7 + ]); + assert_eq!(c[1].clone().into_iter().sorted().collect_vec(), vec![ + 2, 4, 6, 8 + ]); assert_eq!(counter, 2); } diff --git a/tests/dijkstra-all.rs b/tests/dijkstra-all.rs index 228bf6b9..27c59680 100644 --- a/tests/dijkstra-all.rs +++ b/tests/dijkstra-all.rs @@ -1,5 +1,5 @@ use pathfinding::prelude::*; -use rand::{rngs, Rng}; +use rand::{Rng, rngs}; fn build_network(size: usize) -> Matrix { let mut network = Matrix::new(size, size, 0); @@ -52,7 +52,10 @@ fn all_paths() { let other_path = build_path(&target, &paths); // There might be several paths, but we know that internally we use the // same algorithm so the comparison holds. - assert_eq!(path, other_path, "path {start} -> {target} differ in {network:?}: {path:?} vs {other_path:?}"); + assert_eq!( + path, other_path, + "path {start} -> {target} differ in {network:?}: {path:?} vs {other_path:?}" + ); } } else { assert!( diff --git a/tests/dijkstra-reach.rs b/tests/dijkstra-reach.rs index e3fdde88..51e543a3 100644 --- a/tests/dijkstra-reach.rs +++ b/tests/dijkstra-reach.rs @@ -1,5 +1,5 @@ use itertools::Itertools; -use pathfinding::prelude::{dijkstra_reach, DijkstraReachableItem}; +use pathfinding::prelude::{DijkstraReachableItem, dijkstra_reach}; use std::collections::HashMap; #[test] @@ -12,11 +12,13 @@ fn dijkstra_reach_numbers() { assert!((0..100).all(|x| reach.iter().any(|y| x == y.total_cost))); // dijkstra_reach should return reachable nodes in order of cost - assert!(reach - .iter() - .map(|x| x.total_cost) - .tuple_windows() - .all(|(a, b)| b >= a)); + assert!( + reach + .iter() + .map(|x| x.total_cost) + .tuple_windows() + .all(|(a, b)| b >= a) + ); } #[test] diff --git a/tests/grid.rs b/tests/grid.rs index 5dbe8565..16b7820e 100644 --- a/tests/grid.rs +++ b/tests/grid.rs @@ -77,19 +77,16 @@ fn diagonal_mode() { g.enable_diagonal_mode(); let mut ns = g.neighbours((1, 1)); ns.sort_unstable(); - assert_eq!( - ns, - vec![ - (0, 0), - (0, 1), - (0, 2), - (1, 0), - (1, 2), - (2, 0), - (2, 1), - (2, 2), - ] - ); + assert_eq!(ns, vec![ + (0, 0), + (0, 1), + (0, 2), + (1, 0), + (1, 2), + (2, 0), + (2, 1), + (2, 2), + ]); g.disable_diagonal_mode(); let mut ns = g.neighbours((1, 1)); ns.sort_unstable(); @@ -290,10 +287,13 @@ fn neighbours_of_border() { g.enable_diagonal_mode(); assert_eq!(g.neighbours((2, 1)), vec![]); g.fill(); - assert_eq!( - sort(g.neighbours((2, 1))), - vec![(1, 0), (1, 1), (1, 2), (2, 0), (2, 2)] - ); + assert_eq!(sort(g.neighbours((2, 1))), vec![ + (1, 0), + (1, 1), + (1, 2), + (2, 0), + (2, 2) + ]); g.disable_diagonal_mode(); assert_eq!(sort(g.neighbours((2, 1))), vec![(1, 1), (2, 0), (2, 2)]); @@ -302,10 +302,13 @@ fn neighbours_of_border() { g.enable_diagonal_mode(); assert_eq!(g.neighbours((1, 2)), vec![]); g.fill(); - assert_eq!( - sort(g.neighbours((1, 2))), - vec![(0, 1), (0, 2), (1, 1), (2, 1), (2, 2)] - ); + assert_eq!(sort(g.neighbours((1, 2))), vec![ + (0, 1), + (0, 2), + (1, 1), + (2, 1), + (2, 2) + ]); g.disable_diagonal_mode(); assert_eq!(sort(g.neighbours((1, 2))), vec![(0, 2), (1, 1), (2, 2)]); } @@ -467,47 +470,38 @@ fn edges() { g.fill(); let mut edges = g.edges().collect::>(); edges.sort_unstable(); - assert_eq!( - edges, - vec![ - ((0, 0), (0, 1)), - ((0, 0), (1, 0)), - ((0, 1), (1, 1)), - ((1, 0), (1, 1)) - ] - ); + assert_eq!(edges, vec![ + ((0, 0), (0, 1)), + ((0, 0), (1, 0)), + ((0, 1), (1, 1)), + ((1, 0), (1, 1)) + ]); g.enable_diagonal_mode(); let mut edges = g.edges().collect::>(); edges.sort_unstable(); - assert_eq!( - edges, - vec![ - ((0, 0), (0, 1)), - ((0, 0), (1, 0)), - ((0, 0), (1, 1)), - ((0, 1), (1, 1)), - ((1, 0), (0, 1)), - ((1, 0), (1, 1)) - ] - ); + assert_eq!(edges, vec![ + ((0, 0), (0, 1)), + ((0, 0), (1, 0)), + ((0, 0), (1, 1)), + ((0, 1), (1, 1)), + ((1, 0), (0, 1)), + ((1, 0), (1, 1)) + ]); let mut g = Grid::new(3, 3); g.fill(); g.remove_vertex((1, 1)); let mut edges = g.edges().collect::>(); edges.sort_unstable(); - assert_eq!( - edges, - vec![ - ((0, 0), (0, 1)), - ((0, 0), (1, 0)), - ((0, 1), (0, 2)), - ((0, 2), (1, 2)), - ((1, 0), (2, 0)), - ((1, 2), (2, 2)), - ((2, 0), (2, 1)), - ((2, 1), (2, 2)) - ] - ); + assert_eq!(edges, vec![ + ((0, 0), (0, 1)), + ((0, 0), (1, 0)), + ((0, 1), (0, 2)), + ((0, 2), (1, 2)), + ((1, 0), (2, 0)), + ((1, 2), (2, 2)), + ((2, 0), (2, 1)), + ((2, 1), (2, 2)) + ]); } #[test] diff --git a/tests/kruskal.rs b/tests/kruskal.rs index 024e77a5..0c470062 100644 --- a/tests/kruskal.rs +++ b/tests/kruskal.rs @@ -11,14 +11,11 @@ fn grid_lines() { .collect::>(); assert_eq!(weighted_edges.len(), 4); let mst = kruskal(&weighted_edges).sorted().collect_vec(); - assert_eq!( - mst, - vec![ - (&(0, 0), &(0, 1), 0), - (&(0, 0), &(1, 0), 0), - (&(1, 0), &(1, 1), 0) - ] - ); + assert_eq!(mst, vec![ + (&(0, 0), &(0, 1), 0), + (&(0, 0), &(1, 0), 0), + (&(1, 0), &(1, 1), 0) + ]); } #[test] @@ -33,13 +30,10 @@ fn wikipedia() { ('c', 'e', 6), ('d', 'e', 7), ]; - assert_eq!( - kruskal(&edges).collect::>(), - vec![ - (&'a', &'e', 1), - (&'c', &'d', 2), - (&'a', &'b', 3), - (&'b', &'c', 5) - ] - ); + assert_eq!(kruskal(&edges).collect::>(), vec![ + (&'a', &'e', 1), + (&'c', &'d', 2), + (&'a', &'b', 3), + (&'b', &'c', 5) + ]); } diff --git a/tests/kuhn_munkres.rs b/tests/kuhn_munkres.rs index e5ee273a..c92a017a 100644 --- a/tests/kuhn_munkres.rs +++ b/tests/kuhn_munkres.rs @@ -34,12 +34,9 @@ fn tryalgo_examples() { #[test] fn cranes() { // Test from https://s-mat-pcs.oulu.fi/~mpa/matreng/eem1_2-1.htm. - let distances = matrix![ - [90, 75, 75, 80], - [35, 85, 55, 65], - [125, 95, 90, 105], - [45, 110, 95, 115], - ]; + let distances = matrix![[90, 75, 75, 80], [35, 85, 55, 65], [125, 95, 90, 105], [ + 45, 110, 95, 115 + ],]; assert_eq!(kuhn_munkres_min(&distances).0, 275); } @@ -60,12 +57,9 @@ fn mattkrick() { #[test] fn hungarian() { // Test from http://www.hungarianalgorithm.com/examplehungarianalgorithm.php - let weights = matrix![ - [82, 83, 69, 92], - [77, 37, 49, 92], - [11, 69, 5, 86], - [8, 9, 98, 23], - ]; + let weights = matrix![[82, 83, 69, 92], [77, 37, 49, 92], [11, 69, 5, 86], [ + 8, 9, 98, 23 + ],]; assert_eq!(kuhn_munkres_min(&weights).0, 140); } diff --git a/tests/matrix.rs b/tests/matrix.rs index e7aa9eea..d60b2db4 100644 --- a/tests/matrix.rs +++ b/tests/matrix.rs @@ -271,29 +271,17 @@ fn flip_square() { #[test] fn flip_non_square() { - let m1 = Matrix::from_vec( - 4, - 5, - vec![ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - ], - ) + let m1 = Matrix::from_vec(4, 5, vec![ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + ]) .unwrap(); - let m2 = Matrix::from_vec( - 4, - 5, - vec![ - 15, 16, 17, 18, 19, 10, 11, 12, 13, 14, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, - ], - ) + let m2 = Matrix::from_vec(4, 5, vec![ + 15, 16, 17, 18, 19, 10, 11, 12, 13, 14, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, + ]) .unwrap(); - let m3 = Matrix::from_vec( - 4, - 5, - vec![ - 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 14, 13, 12, 11, 10, 19, 18, 17, 16, 15, - ], - ) + let m3 = Matrix::from_vec(4, 5, vec![ + 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 14, 13, 12, 11, 10, 19, 18, 17, 16, 15, + ]) .unwrap(); assert_eq!(m1.flipped_ud(), m2); assert_eq!(m1.flipped_lr(), m3); @@ -396,26 +384,18 @@ fn set_slice() { .unwrap(); let m2 = Matrix::from_vec(3, 2, vec![10, 20, 30, 40, 50, 60]).unwrap(); m1.set_slice((2, 3), &m2); - assert_eq!( - m1.to_vec(), - [ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 10, 20, 15, 16, 17, 30, 40, 20, 21, 22, 50, - 60, - ] - ); + assert_eq!(m1.to_vec(), [ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 10, 20, 15, 16, 17, 30, 40, 20, 21, 22, 50, 60, + ]); let mut m1 = Matrix::square_from_vec(vec![ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, ]) .unwrap(); let m2 = Matrix::from_vec(4, 3, vec![10, 20, 22, 30, 40, 44, 50, 60, 66, 70, 80, 88]).unwrap(); m1.set_slice((2, 3), &m2); - assert_eq!( - m1.to_vec(), - [ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 10, 20, 15, 16, 17, 30, 40, 20, 21, 22, 50, - 60, - ] - ); + assert_eq!(m1.to_vec(), [ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 10, 20, 15, 16, 17, 30, 40, 20, 21, 22, 50, 60, + ]); } #[test] @@ -534,16 +514,21 @@ fn bfs_reachable() { let m = matrix![[0, 1, 2], [3, 4, 5], [6, 7, 8]]; let indices = m.bfs_reachable((1, 0), false, |n| m[n] % 4 != 0); - assert_eq!( - indices.into_iter().collect::>(), - vec![(1, 0), (2, 0), (2, 1)] - ); + assert_eq!(indices.into_iter().collect::>(), vec![ + (1, 0), + (2, 0), + (2, 1) + ]); let indices = m.bfs_reachable((1, 0), true, |n| m[n] % 4 != 0); - assert_eq!( - indices.into_iter().collect::>(), - vec![(0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1)] - ); + assert_eq!(indices.into_iter().collect::>(), vec![ + (0, 1), + (0, 2), + (1, 0), + (1, 2), + (2, 0), + (2, 1) + ]); } #[test] @@ -555,10 +540,11 @@ fn bfs_reachable_mut() { counter += 1; m[n] % 4 != 0 }); - assert_eq!( - indices.into_iter().collect::>(), - vec![(1, 0), (2, 0), (2, 1)] - ); + assert_eq!(indices.into_iter().collect::>(), vec![ + (1, 0), + (2, 0), + (2, 1) + ]); assert_eq!(counter, 8); let mut counter = 0; @@ -566,10 +552,14 @@ fn bfs_reachable_mut() { counter += 1; m[n] % 4 != 0 }); - assert_eq!( - indices.into_iter().collect::>(), - vec![(0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1)] - ); + assert_eq!(indices.into_iter().collect::>(), vec![ + (0, 1), + (0, 2), + (1, 0), + (1, 2), + (2, 0), + (2, 1) + ]); assert_eq!(counter, 26); } @@ -578,16 +568,21 @@ fn dfs_reachable() { let m = matrix![[0, 1, 2], [3, 4, 5], [6, 7, 8]]; let indices = m.dfs_reachable((1, 0), false, |n| m[n] % 4 != 0); - assert_eq!( - indices.into_iter().collect::>(), - vec![(1, 0), (2, 0), (2, 1)] - ); + assert_eq!(indices.into_iter().collect::>(), vec![ + (1, 0), + (2, 0), + (2, 1) + ]); let indices = m.dfs_reachable((1, 0), true, |n| m[n] % 4 != 0); - assert_eq!( - indices.into_iter().collect::>(), - vec![(0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1)] - ); + assert_eq!(indices.into_iter().collect::>(), vec![ + (0, 1), + (0, 2), + (1, 0), + (1, 2), + (2, 0), + (2, 1) + ]); } #[test] @@ -599,10 +594,11 @@ fn dfs_reachable_mut() { counter += 1; m[n] % 4 != 0 }); - assert_eq!( - indices.into_iter().collect::>(), - vec![(1, 0), (2, 0), (2, 1)] - ); + assert_eq!(indices.into_iter().collect::>(), vec![ + (1, 0), + (2, 0), + (2, 1) + ]); assert_eq!(counter, 8); let mut counter = 0; @@ -610,10 +606,14 @@ fn dfs_reachable_mut() { counter += 1; m[n] % 4 != 0 }); - assert_eq!( - indices.into_iter().collect::>(), - vec![(0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1)] - ); + assert_eq!(indices.into_iter().collect::>(), vec![ + (0, 1), + (0, 2), + (1, 0), + (1, 2), + (2, 0), + (2, 1) + ]); assert_eq!(counter, 26); } @@ -721,28 +721,35 @@ fn into_iter_is_fused() { #[expect(deprecated)] fn indices() { let m = matrix![[0, 1, 2], [2, 1, 0]]; - assert_eq!( - m.indices().collect::>(), - vec![(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2)] - ); + assert_eq!(m.indices().collect::>(), vec![ + (0, 0), + (0, 1), + (0, 2), + (1, 0), + (1, 1), + (1, 2) + ]); } #[test] fn keys() { let m = matrix![[0, 1, 2], [2, 1, 0]]; - assert_eq!( - m.keys().collect::>(), - vec![(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2)] - ); + assert_eq!(m.keys().collect::>(), vec![ + (0, 0), + (0, 1), + (0, 2), + (1, 0), + (1, 1), + (1, 2) + ]); } #[test] fn values() { let m = matrix![[0, 1, 2], [2, 1, 0]]; - assert_eq!( - m.values().copied().collect::>(), - vec![0, 1, 2, 2, 1, 0] - ); + assert_eq!(m.values().copied().collect::>(), vec![ + 0, 1, 2, 2, 1, 0 + ]); } #[test] @@ -764,38 +771,32 @@ fn in_direction() { m.in_direction((10, 10), (-1, -1)).collect::>(), vec![] ); - assert_eq!( - m.in_direction((4, 4), (-2, 0)).collect::>(), - vec![(2, 4), (0, 4)] - ); - assert_eq!( - m.in_direction((4, 4), (-3, 0)).collect::>(), - vec![(1, 4)] - ); - assert_eq!( - m.in_direction((4, 4), (2, 0)).collect::>(), - vec![(6, 4)] - ); - assert_eq!( - m.in_direction((4, 4), (3, 0)).collect::>(), - vec![(7, 4)] - ); - assert_eq!( - m.in_direction((4, 4), (0, -2)).collect::>(), - vec![(4, 2), (4, 0)] - ); - assert_eq!( - m.in_direction((4, 4), (0, -3)).collect::>(), - vec![(4, 1)] - ); - assert_eq!( - m.in_direction((4, 4), (0, 2)).collect::>(), - vec![(4, 6)] - ); - assert_eq!( - m.in_direction((4, 4), (0, 3)).collect::>(), - vec![(4, 7)] - ); + assert_eq!(m.in_direction((4, 4), (-2, 0)).collect::>(), vec![ + (2, 4), + (0, 4) + ]); + assert_eq!(m.in_direction((4, 4), (-3, 0)).collect::>(), vec![( + 1, 4 + )]); + assert_eq!(m.in_direction((4, 4), (2, 0)).collect::>(), vec![( + 6, 4 + )]); + assert_eq!(m.in_direction((4, 4), (3, 0)).collect::>(), vec![( + 7, 4 + )]); + assert_eq!(m.in_direction((4, 4), (0, -2)).collect::>(), vec![ + (4, 2), + (4, 0) + ]); + assert_eq!(m.in_direction((4, 4), (0, -3)).collect::>(), vec![( + 4, 1 + )]); + assert_eq!(m.in_direction((4, 4), (0, 2)).collect::>(), vec![( + 4, 6 + )]); + assert_eq!(m.in_direction((4, 4), (0, 3)).collect::>(), vec![( + 4, 7 + )]); } #[test] diff --git a/tests/pathfinding.rs b/tests/pathfinding.rs index 17dc4293..5f381665 100644 --- a/tests/pathfinding.rs +++ b/tests/pathfinding.rs @@ -225,9 +225,11 @@ mod ex2 { .unwrap(); assert_eq!(cost, 8); assert_eq!(paths.len(), 1); - assert!(paths - .iter() - .all(|path| path.iter().all(|&(nx, ny)| OPEN[ny][nx]))); + assert!( + paths + .iter() + .all(|path| path.iter().all(|&(nx, ny)| OPEN[ny][nx])) + ); assert_eq!(counter, 15); } @@ -247,9 +249,11 @@ mod ex2 { .unwrap(); assert_eq!(cost, 9); assert_eq!(paths.len(), 3); - assert!(paths - .iter() - .all(|path| path.iter().all(|&(nx, ny)| OPEN[ny][nx]))); + assert!( + paths + .iter() + .all(|path| path.iter().all(|&(nx, ny)| OPEN[ny][nx])) + ); assert_eq!(counter, 18); } diff --git a/tests/prim.rs b/tests/prim.rs index f4b1275c..21b244e6 100644 --- a/tests/prim.rs +++ b/tests/prim.rs @@ -12,15 +12,12 @@ fn base_test() { ('c', 'e', 6), ('d', 'e', 7), ]; - assert_eq!( - prim(&edges), - vec![ - (&'a', &'e', 1), - (&'a', &'b', 3), - (&'b', &'c', 5), - (&'c', &'d', 2), - ] - ); + assert_eq!(prim(&edges), vec![ + (&'a', &'e', 1), + (&'a', &'b', 3), + (&'b', &'c', 5), + (&'c', &'d', 2), + ]); } #[test] @@ -42,19 +39,16 @@ fn geeksforgeeks() { (6, 8, 6), (7, 8, 7), ]; - assert_eq!( - prim(&edges), - vec![ - (&0, &1, 4), - (&0, &7, 8), - (&7, &6, 1), - (&6, &5, 2), - (&5, &2, 4), - (&2, &8, 2), - (&2, &3, 7), - (&3, &4, 9), - ] - ); + assert_eq!(prim(&edges), vec![ + (&0, &1, 4), + (&0, &7, 8), + (&7, &6, 1), + (&6, &5, 2), + (&5, &2, 4), + (&2, &8, 2), + (&2, &3, 7), + (&3, &4, 9), + ]); } // Order of edges is not important in the result, except for starting edge, because always @@ -71,13 +65,10 @@ fn another_test() { ('C', 'E', 6), ('D', 'E', 1), ]; - assert_eq!( - prim(&edges), - vec![ - (&'B', &'D', 4), - (&'D', &'E', 1), - (&'D', &'C', 2), - (&'C', &'A', 3), - ] - ); + assert_eq!(prim(&edges), vec![ + (&'B', &'D', 4), + (&'D', &'E', 1), + (&'D', &'C', 2), + (&'C', &'A', 3), + ]); } diff --git a/tests/topological_sort.rs b/tests/topological_sort.rs index 3bbe8d64..32a3dcce 100644 --- a/tests/topological_sort.rs +++ b/tests/topological_sort.rs @@ -38,11 +38,7 @@ fn complexity() { let mut requested = 0; let result = tsort(&ints, |&n| { requested += 1; - if n < 999 { - vec![n + 1] - } else { - vec![] - } + if n < 999 { vec![n + 1] } else { vec![] } }); assert_eq!(result, Ok((1..1000).collect_vec())); assert_eq!(requested, 999); diff --git a/tests/version.rs b/tests/version.rs index cfbd94d0..62c759b6 100644 --- a/tests/version.rs +++ b/tests/version.rs @@ -11,7 +11,10 @@ fn check_version() { assert!( trim(VERSION).starts_with(&trim(version)), "Version in README.md ({} - seen as {}) is not compatible with Cargo.toml ({} - seen as {})", - version, trim(version), VERSION, trim(VERSION), + version, + trim(version), + VERSION, + trim(VERSION), ); } diff --git a/tests/yen.rs b/tests/yen.rs index 74010330..4b4f6fe3 100644 --- a/tests/yen.rs +++ b/tests/yen.rs @@ -45,10 +45,9 @@ fn ask_more_than_exist() { ); // we asked for 10 but the graph can only produce 7 - assert_eq!( - result.iter().map(|&(_, c)| c).collect::>(), - vec![5, 7, 8, 8, 8, 11, 11] - ); + assert_eq!(result.iter().map(|&(_, c)| c).collect::>(), vec![ + 5, 7, 8, 8, 8, 11, 11 + ]); } /// Test that we return None in case there is no solution @@ -129,16 +128,13 @@ fn all_paths() { usize::MAX, ); result.sort_unstable(); - assert_eq!( - result, - vec![ - (vec!['a', 'b', 'c', 'd'], 3), - (vec!['a', 'b', 'd'], 2), - (vec!['a', 'c', 'b', 'd'], 3), - (vec!['a', 'c', 'd'], 2), - (vec!['a', 'd'], 1), - ] - ); + assert_eq!(result, vec![ + (vec!['a', 'b', 'c', 'd'], 3), + (vec!['a', 'b', 'd'], 2), + (vec!['a', 'c', 'b', 'd'], 3), + (vec!['a', 'c', 'd'], 2), + (vec!['a', 'd'], 1), + ]); } #[test]