Add property-based test for k_smallest when applied to ranges
use permutohedron;
+use quickcheck::quickcheck;
+use std::cmp::min;
use itertools as it;
use crate::it::Itertools;
use crate::it::ExactlyOneError;
@@ -354,6 +356,18 @@ fn sorted_by() {
it::assert_equal(v, vec![4, 3, 2, 1, 0]);
}
+quickcheck! {
+ fn k_smallest_range(n: u64, m: u64, k: u64) -> () {
+ // Check that taking the k smallest elements in n..n+m
+ // yields n..n+min(k, m)
+ let i = (n..n.saturating_add(m)).into_iter();
+ it::assert_equal(
+ i.k_smallest(k as usize),
+ n..n.saturating_add(min(k, m))
+ );
+ }
+}
+
#[test]
fn sorted_by_key() {
let sc = [3, 4, 1, 2].iter().cloned().sorted_by_key(|&x| x);
