Move integration test into tests dir
This commit is contained in:
parent
d02deec46b
commit
a3f07f790f
31
src/lib.rs
31
src/lib.rs
|
@ -654,34 +654,3 @@ impl Index<PointId> 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::<Point>::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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
use instant_distance::{Hnsw, PointId, Search};
|
||||
|
||||
#[test]
|
||||
fn basic() {
|
||||
let (hnsw, pids) = Hnsw::<Point>::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()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue