Skip to content

Commit

Permalink
iter: Add tests for .chain() and .flat_map()'s fold
Browse files Browse the repository at this point in the history
  • Loading branch information
bluss committed Oct 20, 2016
1 parent e33e28e commit f095f0d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/libcoretest/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,29 @@ fn test_empty() {
assert_eq!(it.next(), None);
}

#[test]
fn test_chain_fold() {
let xs = [1, 2, 3];
let ys = [1, 2, 0];

let mut iter = xs.iter().chain(&ys);
iter.next();
let mut result = Vec::new();
iter.fold((), |(), &elt| result.push(elt));
assert_eq!(&[2, 3, 1, 2, 0], &result[..]);
}

#[test]
fn test_flat_map_fold() {
let xs = [1, 2, 3, 4, 5, 6];

let mut iter = xs.chunks(2).flat_map(|x| x);
iter.next();
let mut result = Vec::new();
iter.fold((), |(), &elt| result.push(elt));
assert_eq!(&xs[1..], &result[..]);
}

#[bench]
fn bench_rposition(b: &mut Bencher) {
let it: Vec<usize> = (0..300).collect();
Expand Down

0 comments on commit f095f0d

Please sign in to comment.