File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change 1
1
use permutohedron;
2
2
use quickcheck:: quickcheck;
3
+ use rand:: { seq:: SliceRandom , thread_rng} ;
3
4
use std:: cmp:: min;
4
5
use itertools as it;
5
6
use crate :: it:: Itertools ;
@@ -358,9 +359,14 @@ fn sorted_by() {
358
359
359
360
quickcheck ! {
360
361
fn k_smallest_range( n: u64 , m: u64 , k: u64 ) -> ( ) {
361
- // Check that taking the k smallest elements in n..n+m
362
- // yields n..n+min(k, m)
363
- let i = ( n..n. saturating_add( m) ) . into_iter( ) ;
362
+ // Generate a random permutation of n..n+m
363
+ let i = {
364
+ let mut v: Vec <u64 > = ( n..n. saturating_add( m) ) . collect( ) ;
365
+ v. shuffle( & mut thread_rng( ) ) ;
366
+ v. into_iter( )
367
+ } ;
368
+
369
+ // Check that taking the k smallest elements yields n..n+min(k, m)
364
370
it:: assert_equal(
365
371
i. k_smallest( k as usize ) ,
366
372
n..n. saturating_add( min( k, m) )
You can’t perform that action at this time.
0 commit comments