1 use itertools::multizip;
2 use itertools::EitherOrBoth::{Both, Left, Right};
3 use itertools::Itertools;
4
5 #[test]
zip_longest_fused()6 fn zip_longest_fused() {
7 let a = [Some(1), None, Some(3), Some(4)];
8 let b = [1, 2, 3];
9
10 let unfused = a
11 .iter()
12 .batching(|it| *it.next().unwrap())
13 .zip_longest(b.iter().cloned());
14 itertools::assert_equal(unfused, vec![Both(1, 1), Right(2), Right(3)]);
15 }
16
17 #[test]
test_zip_longest_size_hint()18 fn test_zip_longest_size_hint() {
19 let c = (1..10).cycle();
20 let v: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
21 let v2 = &[10, 11, 12];
22
23 assert_eq!(c.zip_longest(v.iter()).size_hint(), (std::usize::MAX, None));
24
25 assert_eq!(v.iter().zip_longest(v2.iter()).size_hint(), (10, Some(10)));
26 }
27
28 #[test]
test_double_ended_zip_longest()29 fn test_double_ended_zip_longest() {
30 let xs = [1, 2, 3, 4, 5, 6];
31 let ys = [1, 2, 3, 7];
32 let a = xs.iter().copied();
33 let b = ys.iter().copied();
34 let mut it = a.zip_longest(b);
35 assert_eq!(it.next(), Some(Both(1, 1)));
36 assert_eq!(it.next(), Some(Both(2, 2)));
37 assert_eq!(it.next_back(), Some(Left(6)));
38 assert_eq!(it.next_back(), Some(Left(5)));
39 assert_eq!(it.next_back(), Some(Both(4, 7)));
40 assert_eq!(it.next(), Some(Both(3, 3)));
41 assert_eq!(it.next(), None);
42 }
43
44 #[test]
test_double_ended_zip()45 fn test_double_ended_zip() {
46 let xs = [1, 2, 3, 4, 5, 6];
47 let ys = [1, 2, 3, 7];
48 let a = xs.iter().copied();
49 let b = ys.iter().copied();
50 let mut it = multizip((a, b));
51 assert_eq!(it.next_back(), Some((4, 7)));
52 assert_eq!(it.next_back(), Some((3, 3)));
53 assert_eq!(it.next_back(), Some((2, 2)));
54 assert_eq!(it.next_back(), Some((1, 1)));
55 assert_eq!(it.next_back(), None);
56 }
57