Skip to content

Commit

Permalink
Quicktest Positions
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
Philippe-Cholet committed Dec 8, 2023
1 parent 51a6cc5 commit fdeb91c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1806,7 +1806,7 @@ pub trait Itertools: Iterator {
/// Return an iterator adaptor that yields the indices of all elements
/// satisfying a predicate, counted from the start of the iterator.
///
/// Equivalent to `iter.enumerate().filter(|(_, v)| predicate(v)).map(|(i, _)| i)`.
/// Equivalent to `iter.enumerate().filter(|(_, v)| predicate(*v)).map(|(i, _)| i)`.
///
/// ```
/// use itertools::Itertools;
Expand Down
6 changes: 6 additions & 0 deletions tests/quick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,12 @@ quickcheck! {
let b = &b[..len];
itertools::equal(zip_eq(a, b), zip(a, b))
}
fn equal_positions(a: Vec<i32>) -> bool {
let with_pos = a.iter().positions(|v| v % 2 == 0);
let without = a.iter().enumerate().filter(|(_, v)| *v % 2 == 0).map(|(i, _)| i);
itertools::equal(with_pos.clone(), without.clone())
&& itertools::equal(with_pos.rev(), without.rev())
}
fn size_zip_longest(a: Iter<i16, Exact>, b: Iter<i16, Exact>) -> bool {
let filt = a.clone().dedup();
let filt2 = b.clone().dedup();
Expand Down

0 comments on commit fdeb91c

Please sign in to comment.