Skip to content

Commit

Permalink
clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mrhooray committed Nov 30, 2024
1 parent 4f3755e commit 00f17c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
16 changes: 10 additions & 6 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ where
mod tests {
use super::distance_to_space;
use crate::distance::squared_euclidean;
use std::f64::{INFINITY, NEG_INFINITY};

#[test]
fn test_normal_distance_to_space() {
Expand All @@ -32,16 +31,21 @@ mod tests {

#[test]
fn test_distance_outside_inf() {
let dis = distance_to_space(&[0.0, 0.0], &[1.0, 1.0], &[INFINITY, INFINITY], &squared_euclidean);
let dis = distance_to_space(
&[0.0, 0.0],
&[1.0, 1.0],
&[f64::INFINITY, f64::INFINITY],
&squared_euclidean,
);
assert_eq!(dis, 2.0);
}

#[test]
fn test_distance_inside_inf() {
let dis = distance_to_space(
&[2.0, 2.0],
&[NEG_INFINITY, NEG_INFINITY],
&[INFINITY, INFINITY],
&[f64::NEG_INFINITY, f64::NEG_INFINITY],
&[f64::INFINITY, f64::INFINITY],
&squared_euclidean,
);
assert_eq!(dis, 0.0);
Expand All @@ -57,8 +61,8 @@ mod tests {
fn distance_to_half_space() {
let dis = distance_to_space(
&[-2.0, 0.0],
&[0.0, NEG_INFINITY],
&[INFINITY, INFINITY],
&[0.0, f64::NEG_INFINITY],
&[f64::INFINITY, f64::INFINITY],
&squared_euclidean,
);
assert_eq!(dis, 4.0);
Expand Down
10 changes: 5 additions & 5 deletions tests/kdtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn it_works() {
);

let unsorted1 = kdtree.within_unsorted(&POINT_A.0, 0.0, &squared_euclidean).unwrap();
let ans1 = vec![(0.0, &0)];
let ans1 = [(0.0, &0)];
assert_eq!(unsorted1.len(), ans1.len());
assert_eq!(
kdtree.within_count(&POINT_A.0, 0.0, &squared_euclidean).unwrap(),
Expand All @@ -72,7 +72,7 @@ fn it_works() {
}

let unsorted2 = kdtree.within_unsorted(&POINT_B.0, 1.0, &squared_euclidean).unwrap();
let ans2 = vec![(0.0, &1)];
let ans2 = [(0.0, &1)];
assert_eq!(unsorted2.len(), ans2.len());
assert_eq!(
kdtree.within_count(&POINT_B.0, 1.0, &squared_euclidean).unwrap(),
Expand All @@ -83,7 +83,7 @@ fn it_works() {
}

let unsorted3 = kdtree.within_unsorted(&POINT_B.0, 2.0, &squared_euclidean).unwrap();
let ans3 = vec![(0.0, &1), (2.0, &2), (2.0, &0)];
let ans3 = [(0.0, &1), (2.0, &2), (2.0, &0)];
assert_eq!(unsorted3.len(), ans3.len());
assert_eq!(
kdtree.within_count(&POINT_B.0, 2.0, &squared_euclidean).unwrap(),
Expand Down Expand Up @@ -178,8 +178,8 @@ fn handles_wrong_dimension() {

#[test]
fn handles_non_finite_coordinate() {
let point_a = ([std::f64::NAN, std::f64::NAN], 0f64);
let point_b = ([std::f64::INFINITY, std::f64::INFINITY], 0f64);
let point_a = ([f64::NAN, f64::NAN], 0f64);
let point_b = ([f64::INFINITY, f64::INFINITY], 0f64);
let mut kdtree = KdTree::with_capacity(2, 1);

assert_eq!(kdtree.add(&point_a.0, point_a.1), Err(ErrorKind::NonFiniteCoordinate));
Expand Down

0 comments on commit 00f17c5

Please sign in to comment.