Skip to content

Commit cfb2774

Browse files
Quicktest Positions
`Positions` is tested to be fused, for specialized methods and has two doctests. No other test. While I was adding `Enumerate` in `Positions` internals, running `cargo test positions` told me `rfold` was wrong. The silly mistake was on `next_back` instead and this test would have helped me. Plus, I noticed that the documentation was just a bit wrong.
1 parent 715b556 commit cfb2774

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,7 @@ pub trait Itertools: Iterator {
18061806
/// Return an iterator adaptor that yields the indices of all elements
18071807
/// satisfying a predicate, counted from the start of the iterator.
18081808
///
1809-
/// Equivalent to `iter.enumerate().filter(|(_, v)| predicate(v)).map(|(i, _)| i)`.
1809+
/// Equivalent to `iter.enumerate().filter(|(_, v)| predicate(*v)).map(|(i, _)| i)`.
18101810
///
18111811
/// ```
18121812
/// use itertools::Itertools;

tests/quick.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,12 @@ quickcheck! {
604604
let b = &b[..len];
605605
itertools::equal(zip_eq(a, b), zip(a, b))
606606
}
607+
fn equal_positions(a: Vec<i32>) -> bool {
608+
let with_pos = a.iter().positions(|v| v % 2 == 0);
609+
let without = a.iter().enumerate().filter(|(_, v)| *v % 2 == 0).map(|(i, _)| i);
610+
itertools::equal(with_pos.clone(), without.clone())
611+
&& itertools::equal(with_pos.rev(), without.rev())
612+
}
607613
fn size_zip_longest(a: Iter<i16, Exact>, b: Iter<i16, Exact>) -> bool {
608614
let filt = a.clone().dedup();
609615
let filt2 = b.clone().dedup();

0 commit comments

Comments
 (0)