1 | **use** itertools::Itertools; |

2 | **use** itertools::EitherOrBoth::{Both, Left, Right}; |

3 | **use** itertools::free::zip_eq; |

4 | **use** itertools::multizip; |

5 | |

6 | #[test] |

7 | **fn** zip_longest_fused() { |

8 | **let** a = [Some(`1`), None, Some(`3`), Some(`4`)]; |

9 | **let** b = [`1`, `2`, `3`]; |

10 | |

11 | **let** unfused = a.iter().batching(|it| *it.next().unwrap()) |

12 | .zip_longest(b.iter().cloned()); |

13 | itertools::assert_equal(unfused, |

14 | vec![Both(`1`, `1`), Right(`2`), Right(`3`)]); |

15 | } |

16 | |

17 | #[test] |

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] |

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] |

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 | |

58 | |

59 | #[should_panic ] |

60 | #[test] |

61 | **fn** zip_eq_panic1() |

62 | { |

63 | **let** a = [`1`, `2`]; |

64 | **let** b = [`1`, `2`, `3`]; |

65 | |

66 | zip_eq(&a, &b).count(); |

67 | } |

68 | |

69 | #[should_panic ] |

70 | #[test] |

71 | **fn** zip_eq_panic2() |

72 | { |

73 | **let** a: [**i32**; `0`] = []; |

74 | **let** b = [`1`, `2`, `3`]; |

75 | |

76 | zip_eq(&a, &b).count(); |

77 | } |

78 | |