Skip to content

Commit f095f0d

Browse files
committed
iter: Add tests for .chain() and .flat_map()'s fold
1 parent e33e28e commit f095f0d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/libcoretest/iter.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,29 @@ fn test_empty() {
985985
assert_eq!(it.next(), None);
986986
}
987987

988+
#[test]
989+
fn test_chain_fold() {
990+
let xs = [1, 2, 3];
991+
let ys = [1, 2, 0];
992+
993+
let mut iter = xs.iter().chain(&ys);
994+
iter.next();
995+
let mut result = Vec::new();
996+
iter.fold((), |(), &elt| result.push(elt));
997+
assert_eq!(&[2, 3, 1, 2, 0], &result[..]);
998+
}
999+
1000+
#[test]
1001+
fn test_flat_map_fold() {
1002+
let xs = [1, 2, 3, 4, 5, 6];
1003+
1004+
let mut iter = xs.chunks(2).flat_map(|x| x);
1005+
iter.next();
1006+
let mut result = Vec::new();
1007+
iter.fold((), |(), &elt| result.push(elt));
1008+
assert_eq!(&xs[1..], &result[..]);
1009+
}
1010+
9881011
#[bench]
9891012
fn bench_rposition(b: &mut Bencher) {
9901013
let it: Vec<usize> = (0..300).collect();

0 commit comments

Comments
 (0)