@@ -195,23 +195,36 @@ impl<T: PartialOrd + Clone> TopSegmentCollector<T> {
195
195
196
196
#[ cfg( test) ]
197
197
mod tests {
198
+ use std:: collections:: HashSet ;
199
+
200
+ use ordered_float:: OrderedFloat ;
201
+
198
202
use super :: { TopCollector , TopSegmentCollector } ;
199
203
use crate :: DocAddress ;
200
204
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
+
201
215
#[ test]
202
216
fn test_top_collector_not_at_capacity ( ) {
203
217
let mut top_collector = TopSegmentCollector :: new ( 0 , 4 ) ;
204
218
top_collector. collect ( 1 , 0.8 ) ;
205
219
top_collector. collect ( 3 , 0.2 ) ;
206
220
top_collector. collect ( 5 , 0.3 ) ;
207
221
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![
212
224
( 0.2 , DocAddress :: new( 0 , 3 ) ) ,
213
225
( 0.3 , DocAddress :: new( 0 , 5 ) ) ,
214
- ]
226
+ ( 0.8 , DocAddress :: new( 0 , 1 ) ) ,
227
+ ] ) ,
215
228
) ;
216
229
}
217
230
@@ -224,14 +237,13 @@ mod tests {
224
237
top_collector. collect ( 7 , 0.9 ) ;
225
238
top_collector. collect ( 9 , -0.2 ) ;
226
239
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![
231
242
( 0.2 , DocAddress :: new( 0 , 3 ) ) ,
232
243
( 0.3 , DocAddress :: new( 0 , 5 ) ) ,
244
+ ( 0.8 , DocAddress :: new( 0 , 1 ) ) ,
233
245
( 0.9 , DocAddress :: new( 0 , 7 ) ) ,
234
- ]
246
+ ] ) ,
235
247
) ;
236
248
}
237
249
0 commit comments