Skip to content

Commit

Permalink
style: fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
unrenamed committed Nov 1, 2023
1 parent a984b82 commit 6e839f9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 26 deletions.
9 changes: 4 additions & 5 deletions src/maze/formatters/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::maze::grid::cell::Cell;
use crate::maze::{formatters::Formatter, grid::Grid};
use std::fmt::Write;


use super::StringWrapper;

/// A formatter to emit the maze as ASCII with narrow passages
Expand Down Expand Up @@ -129,8 +128,8 @@ mod tests {
expected.push_str("|_______|\n");

let formatter = AsciiNarrow;
let mut grid = generate_maze();
let actual = formatter.format(&mut grid).0;
let grid = generate_maze();
let actual = formatter.format(&grid).0;

assert_eq!(actual, expected);
}
Expand All @@ -149,8 +148,8 @@ mod tests {
expected.push_str("+---+---+---+---+\n");

let formatter = AsciiBroad;
let mut grid = generate_maze();
let actual = formatter.format(&mut grid).0;
let grid = generate_maze();
let actual = formatter.format(&grid).0;

assert_eq!(actual, expected);
}
Expand Down
16 changes: 8 additions & 8 deletions src/maze/formatters/game_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl GameMap<WithStartGoal> {
rows: usize,
) -> (usize, usize) {
let mut positions: Vec<Coords> = self
.iter_possible_start_and_goal_positions(&map, cols, rows)
.iter_possible_start_and_goal_positions(map, cols, rows)
.collect();

// shuffle possible positions
Expand Down Expand Up @@ -344,10 +344,10 @@ fn bottom_right_neighbour_exists(cx: usize, cy: usize, grid: &Grid) -> bool {
grid.is_carved((cx + 1, cy + 1), Cell::WEST) && grid.is_carved((cx + 1, cy + 1), Cell::NORTH)
}

fn write_map(map: &Vec<char>, cols: usize) -> String {
fn write_map(map: &[char], cols: usize) -> String {
let mut ascii_map: String = String::new();
for i in 0..map.len() {
write!(ascii_map, "{}", map[i]).unwrap();
for (i, ch) in map.iter().enumerate() {
write!(ascii_map, "{}", ch).unwrap();
if (i + 1) % cols == 0 {
writeln!(ascii_map).unwrap();
}
Expand Down Expand Up @@ -472,8 +472,8 @@ mod tests {
expected.push_str("#########\n");

let formatter = GameMap::new().span(1);
let mut grid = generate_maze();
let actual = formatter.format(&mut grid).0;
let grid = generate_maze();
let actual = formatter.format(&grid).0;

assert_eq!(actual, expected);
}
Expand All @@ -492,8 +492,8 @@ mod tests {
expected.push_str("#########\n");

let formatter = GameMap::new().span(1).with_start_goal();
let mut grid = generate_maze();
let actual = formatter.format(&mut grid).0;
let grid = generate_maze();
let actual = formatter.format(&grid).0;

assert_eq!(actual, expected);
}
Expand Down
4 changes: 2 additions & 2 deletions src/maze/formatters/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ mod tests {
#[test]
fn format() {
let formatter = Image::new();
let mut grid = generate_maze();
let grid = generate_maze();

let actual = formatter.format(&mut grid).0;
let actual = formatter.format(&grid).0;
let expected = image::open("tests/fixtures/maze.png").unwrap();

assert_eq!(actual.as_bytes(), expected.as_bytes());
Expand Down
4 changes: 2 additions & 2 deletions src/maze/maze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ mod tests {
fn valid_maze() {
let grid = generate_valid_maze();
let maze = OrthogonalMaze { grid };
assert_eq!(maze.is_valid(), true);
assert!(maze.is_valid());
}

#[test]
fn invalid_maze() {
let grid = generate_invalid_maze();
let maze = OrthogonalMaze { grid };
assert_eq!(maze.is_valid(), false);
assert!(!maze.is_valid());
}

fn generate_valid_maze() -> Grid {
Expand Down
14 changes: 7 additions & 7 deletions src/utils/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ mod tests {
let node2 = arena.new_node();
let node3 = arena.new_node();

assert_eq!(arena.connected(node1, node2), false);
assert_eq!(arena.connected(node1, node3), false);
assert!(!arena.connected(node1, node2));
assert!(!arena.connected(node1, node3));
}

#[test]
Expand All @@ -89,8 +89,8 @@ mod tests {
let node3 = arena.new_node();

arena.connect(node1, node2);
assert_eq!(arena.connected(node1, node2), true);
assert_eq!(arena.connected(node1, node3), false);
assert!(arena.connected(node1, node2));
assert!(!arena.connected(node1, node3));
}

#[test]
Expand All @@ -104,9 +104,9 @@ mod tests {
arena.connect(node1, node2);
arena.connect(node3, node2);

assert_eq!(arena.connected(node1, node2), true);
assert_eq!(arena.connected(node1, node3), true);
assert_eq!(arena.connected(node3, node2), true);
assert!(arena.connected(node1, node2));
assert!(arena.connected(node1, node3));
assert!(arena.connected(node3, node2));
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/utils/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub struct RandPositions;
impl RandPositions {
#[cfg(not(test))]
#[cfg(not(tarpaulin_include))]
pub fn rand<'a>(positions: &'a mut Vec<Coords>) -> &'a mut Vec<Coords> {
pub fn rand(positions: &mut Vec<Coords>) -> &mut Vec<Coords> {
use rand::seq::SliceRandom;
let mut rng = rand::thread_rng();
positions.shuffle(&mut rng);
Expand All @@ -14,7 +14,7 @@ impl RandPositions {

#[cfg(test)]
#[cfg(not(tarpaulin_include))]
pub fn rand<'a>(positions: &'a mut Vec<Coords>) -> &'a mut Vec<Coords> {
pub fn rand(positions: &mut Vec<Coords>) -> &mut Vec<Coords> {
positions
}
}

0 comments on commit 6e839f9

Please sign in to comment.