-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4cfae9
commit 07bbad4
Showing
3 changed files
with
146 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use rindex::Rindex; | ||
|
||
#[allow(unused_variables)] | ||
#[test] | ||
fn test_main_usage() { | ||
let fanout = 10; | ||
let k = 3; // maintain 3 nearest neighbors for each point | ||
let mut rindex = Rindex::new(fanout, k).expect("Failed to create Rindex"); | ||
|
||
// Insert some points | ||
let a = rindex.insert([1.0, 1.0]); | ||
let b = rindex.insert([2.0, 2.0]); | ||
let c = rindex.insert([3.0, 3.0]); | ||
let d = rindex.insert([20.0, 20.0]); | ||
|
||
// Check k nearest neighbors of point a | ||
let (neighbors, distances) = rindex.neighbors_of(a); | ||
assert_eq!(neighbors, vec![a, b, c]); | ||
|
||
// Remove point b | ||
rindex.delete(b); | ||
|
||
// Check k nearest neighbors of point a again | ||
let (neighbors, distances) = rindex.neighbors_of(a); | ||
assert_eq!(neighbors, vec![a, c, d]); // b is not in the result | ||
} | ||
|
||
#[allow(unused_variables)] | ||
#[test] | ||
fn test_update_operations() { | ||
let mut rindex = Rindex::default(); | ||
let a = rindex.insert([1.0, 1.0]); | ||
assert_eq!(rindex.num_points(), 1); | ||
rindex.delete(a); | ||
assert_eq!(rindex.num_points(), 0); | ||
} | ||
|
||
#[allow(unused_variables)] | ||
#[test] | ||
fn test_query_operations() { | ||
let fanout = 10; | ||
let k = 3; | ||
let mut rindex = Rindex::new(fanout, k).expect("Failed to create Rindex"); | ||
let a = rindex.insert([1.0, 1.0]); | ||
let b = rindex.insert([2.0, 2.0]); | ||
let c = rindex.insert([3.0, 3.0]); | ||
let d = rindex.insert([20.0, 20.0]); | ||
|
||
let query_point = [0.0, 0.0]; | ||
|
||
// Range queries: find all points within query_radius distance | ||
let query_radius = 10.0; | ||
let (neighbors, distances) = rindex.query(&query_point, query_radius); | ||
assert_eq!(neighbors, vec![a, b, c]); | ||
|
||
// Nearest neighbors: find 3 nearest neighbors of the query point | ||
let (neighbors, distances) = rindex.query_neighbors(&query_point, 3); | ||
assert_eq!(neighbors, vec![a, b, c]); | ||
|
||
// Reverse nearest neighbors: find such points that sees the query point | ||
// as one of their 3 nearest neighbors | ||
let (neighbors, distances) = rindex.query_reverse(&[0.0, 0.0]); | ||
assert_eq!(neighbors, vec![a]); | ||
} |