2021-01-09 16:55:41 -06:00
|
|
|
use core::iter::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_fuse_nth() {
|
|
|
|
let xs = [0, 1, 2];
|
|
|
|
let mut it = xs.iter();
|
|
|
|
|
|
|
|
assert_eq!(it.len(), 3);
|
|
|
|
assert_eq!(it.nth(2), Some(&2));
|
|
|
|
assert_eq!(it.len(), 0);
|
|
|
|
assert_eq!(it.nth(2), None);
|
|
|
|
assert_eq!(it.len(), 0);
|
|
|
|
}
|
2021-01-22 15:58:21 -06:00
|
|
|
|
2021-01-09 16:55:41 -06:00
|
|
|
#[test]
|
|
|
|
fn test_fuse_last() {
|
|
|
|
let xs = [0, 1, 2];
|
|
|
|
let it = xs.iter();
|
|
|
|
|
|
|
|
assert_eq!(it.len(), 3);
|
|
|
|
assert_eq!(it.last(), Some(&2));
|
|
|
|
}
|
2021-01-22 15:58:21 -06:00
|
|
|
|
2021-01-09 16:55:41 -06:00
|
|
|
#[test]
|
|
|
|
fn test_fuse_count() {
|
|
|
|
let xs = [0, 1, 2];
|
|
|
|
let it = xs.iter();
|
|
|
|
|
|
|
|
assert_eq!(it.len(), 3);
|
|
|
|
assert_eq!(it.count(), 3);
|
|
|
|
// Can't check len now because count consumes.
|
|
|
|
}
|
2021-01-22 15:58:21 -06:00
|
|
|
|
2021-01-09 16:55:41 -06:00
|
|
|
#[test]
|
|
|
|
fn test_fuse_fold() {
|
|
|
|
let xs = [0, 1, 2];
|
|
|
|
let it = xs.iter(); // `FusedIterator`
|
|
|
|
let i = it.fuse().fold(0, |i, &x| {
|
|
|
|
assert_eq!(x, xs[i]);
|
|
|
|
i + 1
|
|
|
|
});
|
|
|
|
assert_eq!(i, xs.len());
|
|
|
|
|
|
|
|
let it = xs.iter(); // `FusedIterator`
|
|
|
|
let i = it.fuse().rfold(xs.len(), |i, &x| {
|
|
|
|
assert_eq!(x, xs[i - 1]);
|
|
|
|
i - 1
|
|
|
|
});
|
|
|
|
assert_eq!(i, 0);
|
|
|
|
|
|
|
|
let it = xs.iter().scan((), |_, &x| Some(x)); // `!FusedIterator`
|
|
|
|
let i = it.fuse().fold(0, |i, x| {
|
|
|
|
assert_eq!(x, xs[i]);
|
|
|
|
i + 1
|
|
|
|
});
|
|
|
|
assert_eq!(i, xs.len());
|
|
|
|
}
|
2021-01-22 16:20:42 -06:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_fuse() {
|
|
|
|
let mut it = 0..3;
|
|
|
|
assert_eq!(it.len(), 3);
|
|
|
|
assert_eq!(it.next(), Some(0));
|
|
|
|
assert_eq!(it.len(), 2);
|
|
|
|
assert_eq!(it.next(), Some(1));
|
|
|
|
assert_eq!(it.len(), 1);
|
|
|
|
assert_eq!(it.next(), Some(2));
|
|
|
|
assert_eq!(it.len(), 0);
|
|
|
|
assert_eq!(it.next(), None);
|
|
|
|
assert_eq!(it.len(), 0);
|
|
|
|
assert_eq!(it.next(), None);
|
|
|
|
assert_eq!(it.len(), 0);
|
|
|
|
assert_eq!(it.next(), None);
|
|
|
|
assert_eq!(it.len(), 0);
|
|
|
|
}
|