Skip to content

Commit 11b54cc

Browse files
committed
tests::k_smallest_range: Shuffle the input before taking the k smallest
1 parent e71977e commit 11b54cc

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

tests/test_std.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use permutohedron;
22
use quickcheck::quickcheck;
3+
use rand::{seq::SliceRandom, thread_rng};
34
use std::cmp::min;
45
use itertools as it;
56
use crate::it::Itertools;
@@ -358,9 +359,14 @@ fn sorted_by() {
358359

359360
quickcheck! {
360361
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)
364370
it::assert_equal(
365371
i.k_smallest(k as usize),
366372
n..n.saturating_add(min(k, m))

0 commit comments

Comments
 (0)