Skip to content

Commit e71977e

Browse files
committed
Add property-based test for k_smallest when applied to ranges
1 parent 51670c9 commit e71977e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/test_std.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use permutohedron;
2+
use quickcheck::quickcheck;
3+
use std::cmp::min;
24
use itertools as it;
35
use crate::it::Itertools;
46
use crate::it::ExactlyOneError;
@@ -354,6 +356,18 @@ fn sorted_by() {
354356
it::assert_equal(v, vec![4, 3, 2, 1, 0]);
355357
}
356358

359+
quickcheck! {
360+
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();
364+
it::assert_equal(
365+
i.k_smallest(k as usize),
366+
n..n.saturating_add(min(k, m))
367+
);
368+
}
369+
}
370+
357371
#[test]
358372
fn sorted_by_key() {
359373
let sc = [3, 4, 1, 2].iter().cloned().sorted_by_key(|&x| x);

0 commit comments

Comments
 (0)