1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
mod generated;
pub use self::generated::*;

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn r0_is_empty_o0_is_empty() {
        let r0 = std::iter::empty::<u32>();
        let o0 = (0..).map(|n| n.to_string());

        let expected: Vec<(u32, String)> = vec![];
        let got = clamped_zip_1x1(r0, o0, String::new).collect::<Vec<_>>();

        similar_asserts::assert_eq!(expected, got);
    }

    #[test]
    fn r0_and_o0_are_matched() {
        let r0 = 0..20u32;
        let o0 = (0..20).map(|n| n.to_string());

        let expected: Vec<(u32, String)> = (0..20u32).map(|n| (n, n.to_string())).collect();
        let got = clamped_zip_1x1(r0, o0, String::new).collect::<Vec<_>>();

        similar_asserts::assert_eq!(expected, got);
    }

    #[test]
    fn r0_is_shorter() {
        let r0 = 0..10u32;
        let o0 = (0..20).map(|n| n.to_string());

        let expected: Vec<(u32, String)> = (0..10u32).map(|n| (n, n.to_string())).collect();
        let got = clamped_zip_1x1(r0, o0, String::new).collect::<Vec<_>>();

        similar_asserts::assert_eq!(expected, got);
    }

    #[test]
    fn r0_is_longer() {
        let r0 = 0..30u32;
        let o0 = (0..20).map(|n| n.to_string());

        let expected: Vec<(u32, String)> = (0..30u32)
            .map(|n| (n, u32::min(n, 19).to_string()))
            .collect();
        let got = clamped_zip_1x1(r0, o0, String::new).collect::<Vec<_>>();

        similar_asserts::assert_eq!(expected, got);
    }

    #[test]
    fn r0_is_longer_and_o0_is_empty() {
        let r0 = 0..10u32;
        let o0 = std::iter::empty();

        let expected: Vec<(u32, String)> = (0..10u32).map(|n| (n, "hey".to_owned())).collect();
        let got = clamped_zip_1x1(r0, o0, || "hey".to_owned()).collect::<Vec<_>>();

        similar_asserts::assert_eq!(expected, got);
    }
}