diff --git a/src/lib.rs b/src/lib.rs index 6b5841f..2ca2bcf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -654,34 +654,3 @@ impl Index for [ZeroNode] { /// /// This should become a generic argument to `Hnsw` when possible. const M: usize = 6; - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn basic() { - let (hnsw, pids) = Hnsw::::builder().build(&[ - Point(0.1, 0.4), - Point(-0.324, 0.543), - Point(0.87, -0.33), - Point(0.452, 0.932), - ]); - - let mut search = Search::default(); - let mut results = vec![PointId::invalid()]; - let p = Point(0.1, 0.35); - let found = hnsw.search(&p, &mut results, &mut search); - assert_eq!(found, 1); - assert_eq!(&results, &[pids[0]]); - } - - #[derive(Clone, Copy, Debug)] - struct Point(f32, f32); - - impl super::Point for Point { - fn distance(&self, other: &Self) -> f32 { - ((self.0 - other.0).powi(2) + (self.1 - other.1).powi(2)).sqrt() - } - } -} diff --git a/tests/all.rs b/tests/all.rs new file mode 100644 index 0000000..754e4db --- /dev/null +++ b/tests/all.rs @@ -0,0 +1,28 @@ +use instant_distance::{Hnsw, PointId, Search}; + +#[test] +fn basic() { + let (hnsw, pids) = Hnsw::::builder().build(&[ + Point(0.1, 0.4), + Point(-0.324, 0.543), + Point(0.87, -0.33), + Point(0.452, 0.932), + ]); + + let mut search = Search::default(); + let mut results = vec![PointId::default()]; + let p = Point(0.1, 0.35); + let found = hnsw.search(&p, &mut results, &mut search); + assert_eq!(found, 1); + assert_eq!(&results, &[pids[0]]); +} + +#[derive(Clone, Copy, Debug)] +struct Point(f32, f32); + +impl instant_distance::Point for Point { + fn distance(&self, other: &Self) -> f32 { + // Euclidean distance metric + ((self.0 - other.0).powi(2) + (self.1 - other.1).powi(2)).sqrt() + } +}