Skip to content

Commit

Permalink
rust/worker
Browse files Browse the repository at this point in the history
  • Loading branch information
HammadB committed Mar 24, 2024
1 parent 0cfef97 commit 5d6e862
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions rust/worker/src/execution/operators/brute_force_knn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,19 @@ mod tests {
1.0f32 - ((data_1[0] * 0.0) + (data_1[1] * 1.0) + (data_1[2] * 0.0));
assert_eq!(output.distances, vec![0.0, expected_distance_1]);
}

#[tokio::test]
async fn test_data_less_than_k() {
// If we have less data than k, we should return all the data, sorted by distance.
let operator = BruteForceKnnOperator {};
let input = BruteForceKnnOperatorInput {
data: vec![vec![0.0, 0.0, 0.0]],
query: vec![0.0, 0.0, 0.0],
k: 2,
distance_metric: DistanceFunction::Euclidean,
};
let output = operator.run(&input).await.unwrap();
assert_eq!(output.indices, vec![0]);
assert_eq!(output.distances, vec![0.0]);
}
}

0 comments on commit 5d6e862

Please sign in to comment.