Move integration test into tests dir

This commit is contained in:
Dirkjan Ochtman 2021-01-07 11:20:23 +01:00
parent d02deec46b
commit a3f07f790f
2 changed files with 28 additions and 31 deletions

View File

@ -654,34 +654,3 @@ impl Index<PointId> for [ZeroNode] {
/// ///
/// This should become a generic argument to `Hnsw` when possible. /// This should become a generic argument to `Hnsw` when possible.
const M: usize = 6; 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()
}
}
}

28
tests/all.rs Normal file
View File

@ -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()
}
}