Skip to content

Commit

Permalink
Merge #686
Browse files Browse the repository at this point in the history
686: Impl Clone for CircularTupleWindows r=jswrenn a=zachs18

Fixes #685

Co-authored-by: Zachary S <zasample18+github@gmail.com>
  • Loading branch information
bors[bot] and zachs18 committed Jun 14, 2023
2 parents 0b18d26 + 447370d commit ca31484
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/tuple_impl.rs
Expand Up @@ -201,7 +201,7 @@ impl<I, T> FusedIterator for TupleWindows<I, T>
/// See [`.circular_tuple_windows()`](crate::Itertools::circular_tuple_windows) for more
/// information.
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CircularTupleWindows<I, T: Clone>
where I: Iterator<Item = T::Item> + Clone,
T: TupleCollect + Clone
Expand Down
64 changes: 64 additions & 0 deletions tests/quick.rs
Expand Up @@ -1021,7 +1021,71 @@ quickcheck! {
}
}

// tuple iterators
quickcheck! {
fn equal_circular_tuple_windows_1(a: Vec<u8>) -> bool {
let x = a.iter().map(|e| (e,) );
let y = a.iter().circular_tuple_windows::<(_,)>();
itertools::assert_equal(x,y);
true
}

fn equal_circular_tuple_windows_2(a: Vec<u8>) -> bool {
let x = (0..a.len()).map(|start_idx| (
&a[start_idx],
&a[(start_idx + 1) % a.len()],
));
let y = a.iter().circular_tuple_windows::<(_, _)>();
itertools::assert_equal(x,y);
true
}

fn equal_circular_tuple_windows_3(a: Vec<u8>) -> bool {
let x = (0..a.len()).map(|start_idx| (
&a[start_idx],
&a[(start_idx + 1) % a.len()],
&a[(start_idx + 2) % a.len()],
));
let y = a.iter().circular_tuple_windows::<(_, _, _)>();
itertools::assert_equal(x,y);
true
}

fn equal_circular_tuple_windows_4(a: Vec<u8>) -> bool {
let x = (0..a.len()).map(|start_idx| (
&a[start_idx],
&a[(start_idx + 1) % a.len()],
&a[(start_idx + 2) % a.len()],
&a[(start_idx + 3) % a.len()],
));
let y = a.iter().circular_tuple_windows::<(_, _, _, _)>();
itertools::assert_equal(x,y);
true
}

fn equal_cloned_circular_tuple_windows(a: Vec<u8>) -> bool {
let x = a.iter().circular_tuple_windows::<(_, _, _, _)>();
let y = x.clone();
itertools::assert_equal(x,y);
true
}

fn equal_cloned_circular_tuple_windows_noninitial(a: Vec<u8>) -> bool {
let mut x = a.iter().circular_tuple_windows::<(_, _, _, _)>();
let _ = x.next();
let y = x.clone();
itertools::assert_equal(x,y);
true
}

fn equal_cloned_circular_tuple_windows_complete(a: Vec<u8>) -> bool {
let mut x = a.iter().circular_tuple_windows::<(_, _, _, _)>();
for _ in x.by_ref() {}
let y = x.clone();
itertools::assert_equal(x,y);
true
}

fn equal_tuple_windows_1(a: Vec<u8>) -> bool {
let x = a.windows(1).map(|s| (&s[0], ));
let y = a.iter().tuple_windows::<(_,)>();
Expand Down

0 comments on commit ca31484

Please sign in to comment.