From 7288c9230a619cab88ee22eb0c6634d97269a670 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 20 May 2021 15:35:56 +0200 Subject: [PATCH] Actually test HnswMap results --- instant-distance/tests/all.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/instant-distance/tests/all.rs b/instant-distance/tests/all.rs index 3c25964..061c562 100644 --- a/instant-distance/tests/all.rs +++ b/instant-distance/tests/all.rs @@ -8,21 +8,34 @@ use instant_distance::{Builder, Point as _, Search}; #[test] fn map() { - let points = (0..16) + let points = (0..5) .into_iter() .map(|i| Point(i as f32, i as f32)) .collect::>(); - let values = vec![ - "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", - "eleven", "twelve", "thirteen", "fourteen", "fifteen", - ]; + let values = vec!["zero", "one", "two", "three", "four"]; let seed = ThreadRng::default().gen::(); println!("map (seed = {})", seed); let map = Builder::default().seed(seed).build(points, values); let mut search = Search::default(); - let _ = map.search(&Point(2.0, 2.0), &mut search); + for (i, item) in map.search(&Point(2.0, 2.0), &mut search).enumerate() { + match i { + 0 => { + assert_eq!(item.distance, 0.0); + assert_eq!(item.value, &"two"); + } + 1 | 2 => { + assert_eq!(item.distance, 1.4142135); + assert!(item.value == &"one" || item.value == &"three"); + } + 3 | 4 => { + assert_eq!(item.distance, 2.828427); + assert!(item.value == &"zero" || item.value == &"four"); + } + _ => unreachable!(), + } + } } #[test]