Skip to content

Commit

Permalink
test: fix test_topk_computer
Browse files Browse the repository at this point in the history
Signed-off-by: Mingzhuo Yin <[email protected]>
  • Loading branch information
silver-ymz committed Nov 18, 2024
1 parent 587ba3c commit 29d54d7
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/utils/topk_computer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ impl TopKComputer {
mod tests {
use std::collections::BinaryHeap;

use rand::seq::SliceRandom as _;

use super::*;

#[derive(PartialEq)]
Expand All @@ -83,8 +85,14 @@ mod tests {
let mut topk = TopKComputer::new(20);
let mut reference = BinaryHeap::new();

for _ in 0..100000 {
let score = rand::random::<f32>();
let mut scores = (0..100000)
.map(|_| rand::random::<f32>())
.collect::<Vec<_>>();
scores.sort_unstable_by(|a, b| a.partial_cmp(b).unwrap());
scores.dedup();
scores.shuffle(&mut rand::thread_rng());

for score in scores {
let id = rand::random::<u32>();
topk.push(score, id);
reference.push(Cmp(score, id));
Expand All @@ -93,7 +101,7 @@ mod tests {
}
}

let topk = topk.to_sorted_slice();
let topk = topk.to_sorted_slice().to_vec();
let mut reference = reference.into_sorted_vec();
reference.reverse();
println!(
Expand Down

0 comments on commit 29d54d7

Please sign in to comment.