]>
git.proxmox.com Git - rustc.git/blob - vendor/itertools/tests/zip.rs
1 extern crate itertools
;
3 use itertools
::Itertools
;
4 use itertools
::EitherOrBoth
::{Both, Left, Right}
;
5 use itertools
::free
::zip_eq
;
8 fn zip_longest_fused() {
9 let a
= [Some(1), None
, Some(3), Some(4)];
12 let unfused
= a
.iter().batching(|it
| *it
.next().unwrap())
13 .zip_longest(b
.iter().cloned());
14 itertools
::assert_equal(unfused
,
15 vec
![Both(1, 1), Right(2), Right(3)]);
19 fn test_zip_longest_size_hint() {
20 let c
= (1..10).cycle();
21 let v
: &[_
] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
22 let v2
= &[10, 11, 12];
24 assert_eq
!(c
.zip_longest(v
.iter()).size_hint(), (std
::usize::MAX
, None
));
26 assert_eq
!(v
.iter().zip_longest(v2
.iter()).size_hint(), (10, Some(10)));
30 fn test_double_ended_zip_longest() {
31 let xs
= [1, 2, 3, 4, 5, 6];
32 let ys
= [1, 2, 3, 7];
33 let a
= xs
.iter().map(|&x
| x
);
34 let b
= ys
.iter().map(|&x
| x
);
35 let mut it
= a
.zip_longest(b
);
36 assert_eq
!(it
.next(), Some(Both(1, 1)));
37 assert_eq
!(it
.next(), Some(Both(2, 2)));
38 assert_eq
!(it
.next_back(), Some(Left(6)));
39 assert_eq
!(it
.next_back(), Some(Left(5)));
40 assert_eq
!(it
.next_back(), Some(Both(4, 7)));
41 assert_eq
!(it
.next(), Some(Both(3, 3)));
42 assert_eq
!(it
.next(), None
);
53 zip_eq(&a
, &b
).count();
63 zip_eq(&a
, &b
).count();