Skip to content

Commit

Permalink
fix clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilhenry committed Nov 13, 2023
1 parent ac9df45 commit 050d9b1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
25 changes: 2 additions & 23 deletions src/position.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::cmp::Ordering;
use std::hash::Hash;
use std::ops::Add;

#[derive(Hash, Debug, Clone)]
#[derive(Hash, Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub struct Position {
pub x: i32,
pub y: i32,
}

pub fn euclid_distance(from: &Position, to: &Position) -> usize {
let x_dist = (from.x - to.x).abs();
let y_dist = (from.y - to.y).abs();
Expand Down Expand Up @@ -40,23 +39,3 @@ impl Add<&Position> for Position {
}
}
}

impl Eq for Position {}

impl PartialEq<Self> for Position {
fn eq(&self, other: &Self) -> bool {
self.x == other.x && self.y == other.y
}
}

impl PartialOrd<Self> for Position {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

impl Ord for Position {
fn cmp(&self, other: &Self) -> Ordering {
self.x.cmp(&other.y).then_with(|| self.y.cmp(&other.y))
}
}
12 changes: 6 additions & 6 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ fn correct_index_rectangle() {
#[test]
fn valid_positions() {
let grid = Grid::new(5, 5);
assert_eq!(true, grid.is_valid_pos(&Position::new(1, 0)));
assert_eq!(true, grid.is_valid_pos(&Position::new(4, 4)));
assert_eq!(false, grid.is_valid_pos(&Position::new(-1, 0)));
assert_eq!(false, grid.is_valid_pos(&Position::new(5, 4)));
assert_eq!(false, grid.is_valid_pos(&Position::new(4, 5)));
assert_eq!(false, grid.is_valid_pos(&Position::new(5, 5)));
assert!(grid.is_valid_pos(&Position::new(1, 0)));
assert!(grid.is_valid_pos(&Position::new(4, 4)));
assert!(!grid.is_valid_pos(&Position::new(-1, 0)));
assert!(!grid.is_valid_pos(&Position::new(5, 4)));
assert!(!grid.is_valid_pos(&Position::new(4, 5)));
assert!(!grid.is_valid_pos(&Position::new(5, 5)));
}

#[test]
Expand Down

0 comments on commit 050d9b1

Please sign in to comment.