]> git.proxmox.com Git - rustc.git/blame - vendor/itertools/tests/zip.rs
New upstream version 1.49.0+dfsg1
[rustc.git] / vendor / itertools / tests / zip.rs
CommitLineData
532ac7d7
XL
1use itertools::Itertools;
2use itertools::EitherOrBoth::{Both, Left, Right};
3use itertools::free::zip_eq;
4
5#[test]
6fn zip_longest_fused() {
7 let a = [Some(1), None, Some(3), Some(4)];
8 let b = [1, 2, 3];
9
10 let unfused = a.iter().batching(|it| *it.next().unwrap())
11 .zip_longest(b.iter().cloned());
12 itertools::assert_equal(unfused,
13 vec![Both(1, 1), Right(2), Right(3)]);
14}
15
16#[test]
17fn test_zip_longest_size_hint() {
18 let c = (1..10).cycle();
19 let v: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
20 let v2 = &[10, 11, 12];
21
22 assert_eq!(c.zip_longest(v.iter()).size_hint(), (std::usize::MAX, None));
23
24 assert_eq!(v.iter().zip_longest(v2.iter()).size_hint(), (10, Some(10)));
25}
26
27#[test]
28fn test_double_ended_zip_longest() {
29 let xs = [1, 2, 3, 4, 5, 6];
30 let ys = [1, 2, 3, 7];
31 let a = xs.iter().map(|&x| x);
32 let b = ys.iter().map(|&x| x);
33 let mut it = a.zip_longest(b);
34 assert_eq!(it.next(), Some(Both(1, 1)));
35 assert_eq!(it.next(), Some(Both(2, 2)));
36 assert_eq!(it.next_back(), Some(Left(6)));
37 assert_eq!(it.next_back(), Some(Left(5)));
38 assert_eq!(it.next_back(), Some(Both(4, 7)));
39 assert_eq!(it.next(), Some(Both(3, 3)));
40 assert_eq!(it.next(), None);
41}
42
43
44#[should_panic]
45#[test]
46fn zip_eq_panic1()
47{
48 let a = [1, 2];
49 let b = [1, 2, 3];
50
51 zip_eq(&a, &b).count();
52}
53
54#[should_panic]
55#[test]
56fn zip_eq_panic2()
57{
58 let a: [i32; 0] = [];
59 let b = [1, 2, 3];
60
61 zip_eq(&a, &b).count();
62}
63