]> git.proxmox.com Git - rustc.git/blob - vendor/itertools-0.8.0/tests/zip.rs
New upstream version 1.44.1+dfsg1
[rustc.git] / vendor / itertools-0.8.0 / tests / zip.rs
1 extern crate itertools;
2
3 use itertools::Itertools;
4 use itertools::EitherOrBoth::{Both, Left, Right};
5 use itertools::free::zip_eq;
6
7 #[test]
8 fn zip_longest_fused() {
9 let a = [Some(1), None, Some(3), Some(4)];
10 let b = [1, 2, 3];
11
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)]);
16 }
17
18 #[test]
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];
23
24 assert_eq!(c.zip_longest(v.iter()).size_hint(), (std::usize::MAX, None));
25
26 assert_eq!(v.iter().zip_longest(v2.iter()).size_hint(), (10, Some(10)));
27 }
28
29 #[test]
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);
43 }
44
45
46 #[should_panic]
47 #[test]
48 fn zip_eq_panic1()
49 {
50 let a = [1, 2];
51 let b = [1, 2, 3];
52
53 zip_eq(&a, &b).count();
54 }
55
56 #[should_panic]
57 #[test]
58 fn zip_eq_panic2()
59 {
60 let a: [i32; 0] = [];
61 let b = [1, 2, 3];
62
63 zip_eq(&a, &b).count();
64 }
65