Skip to content

Commit 36e1713

Browse files
committed
Review feedback.
1 parent 8d4d5ed commit 36e1713

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ binggan = "0.14.0"
7878
rand = "0.8.5"
7979
maplit = "1.0.2"
8080
matches = "0.1.9"
81+
ordered-float = "5.0.0"
8182
pretty_assertions = "1.2.1"
8283
proptest = "1.0.0"
8384
test-log = "0.2.10"

src/collector/top_collector.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,23 +195,36 @@ impl<T: PartialOrd + Clone> TopSegmentCollector<T> {
195195

196196
#[cfg(test)]
197197
mod tests {
198+
use std::collections::HashSet;
199+
200+
use ordered_float::OrderedFloat;
201+
198202
use super::{TopCollector, TopSegmentCollector};
199203
use crate::DocAddress;
200204

205+
/// Individual segments are not sorted, and we convert their results to a set to emphasize that.
206+
fn segment_results_set(
207+
results: Vec<(f32, DocAddress)>,
208+
) -> HashSet<(OrderedFloat<f32>, DocAddress)> {
209+
results
210+
.into_iter()
211+
.map(|(score, doc)| (OrderedFloat(score), doc))
212+
.collect()
213+
}
214+
201215
#[test]
202216
fn test_top_collector_not_at_capacity() {
203217
let mut top_collector = TopSegmentCollector::new(0, 4);
204218
top_collector.collect(1, 0.8);
205219
top_collector.collect(3, 0.2);
206220
top_collector.collect(5, 0.3);
207221
assert_eq!(
208-
top_collector.harvest(),
209-
// Note: Individual segments are not sorted.
210-
vec![
211-
(0.8, DocAddress::new(0, 1)),
222+
segment_results_set(top_collector.harvest()),
223+
segment_results_set(vec![
212224
(0.2, DocAddress::new(0, 3)),
213225
(0.3, DocAddress::new(0, 5)),
214-
]
226+
(0.8, DocAddress::new(0, 1)),
227+
]),
215228
);
216229
}
217230

@@ -224,14 +237,13 @@ mod tests {
224237
top_collector.collect(7, 0.9);
225238
top_collector.collect(9, -0.2);
226239
assert_eq!(
227-
top_collector.harvest(),
228-
// Note: Individual segments are not sorted.
229-
vec![
230-
(0.8, DocAddress::new(0, 1)),
240+
segment_results_set(top_collector.harvest()),
241+
segment_results_set(vec![
231242
(0.2, DocAddress::new(0, 3)),
232243
(0.3, DocAddress::new(0, 5)),
244+
(0.8, DocAddress::new(0, 1)),
233245
(0.9, DocAddress::new(0, 7)),
234-
]
246+
]),
235247
);
236248
}
237249

0 commit comments

Comments
 (0)