Skip to content

Commit

Permalink
Add a Zip::nth test for side effects
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmcm committed Mar 1, 2018
1 parent 70d5a46 commit 11fefeb
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/libcore/tests/iter.rs
Expand Up @@ -161,6 +161,26 @@ fn test_zip_nth() {
assert_eq!(it.nth(3), None);
}

#[test]
fn test_zip_nth_side_effects() {
let mut a = Vec::new();
let mut b = Vec::new();
let value = [1, 2, 3, 4, 5, 6].iter().cloned()
.map(|n| {
a.push(n);
n * 10
})
.zip([2, 3, 4, 5, 6, 7, 8].iter().cloned().map(|n| {
b.push(n * 100);
n * 1000
}))
.skip(1)
.nth(3);
assert_eq!(value, Some((50, 6000)));
assert_eq!(a, vec![1, 2, 3, 4, 5]);
assert_eq!(b, vec![200, 300, 400, 500, 600]);
}

#[test]
fn test_iterator_step_by() {
// Identity
Expand Down

0 comments on commit 11fefeb

Please sign in to comment.