orx_v/impl_nvec/
vec.rs

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use crate::{impl_v1, impl_vn, D2, D3, D4};
use alloc::vec::Vec;

impl_v1!([T], Vec<T>, [T: Copy]);
impl_vn!(D2, [T, C], Vec<C>, [C: NVec<<D2 as Dim>::PrevDim, T>]);
impl_vn!(D3, [T, C], Vec<C>, [C: NVec<<D3 as Dim>::PrevDim, T>]);
impl_vn!(D4, [T, C], Vec<C>, [C: NVec<<D4 as Dim>::PrevDim, T>]);

#[cfg(test)]
mod tests {
    use crate::*;
    use alloc::vec;
    use alloc::vec::Vec;

    #[test]
    fn vec_d1() {
        let mut v1: Vec<i32> = vec![1, 2, 3, 4];
        assert_eq!(v1.card([]), 4);
        assert_eq!(v1.equality(&[1, 2, 3, 4]), Equality::Equal);
        assert_eq!(v1.all().collect::<Vec<_>>(), vec![1, 2, 3, 4]);

        v1.push(5);
        v1.push(6);
        assert_eq!(v1.core_card([]), 6);
        assert_eq!(v1.equality(&[1, 2, 3, 4, 5, 6]), Equality::Equal);
    }

    #[test]
    fn vec_recurse_d2() {
        let mut v2: Vec<Vec<i32>> = vec![vec![1, 10], vec![2, 20], vec![3, 30], vec![4, 40]];
        assert_eq!(v2.card([]), 4);
        assert_eq!(
            v2.equality(&[[1, 10], [2, 20], [3, 30], [4, 40]]),
            Equality::Equal
        );
        assert_eq!(
            v2.all().collect::<Vec<_>>(),
            vec![1, 10, 2, 20, 3, 30, 4, 40]
        );

        v2.push(vec![5]);
        v2.push(vec![6, 60, 600]);
        assert_eq!(v2.card([]), 6);
        assert_eq!(
            v2.equality(&[
                vec![1, 10],
                vec![2, 20],
                vec![3, 30],
                vec![4, 40],
                vec![5],
                vec![6, 60, 600]
            ]),
            Equality::Equal
        );
        assert_eq!(
            v2.all().collect::<Vec<_>>(),
            vec![1, 10, 2, 20, 3, 30, 4, 40, 5, 6, 60, 600]
        );
    }

    #[test]
    fn vec_recurse_d3() {
        let mut v3: Vec<Vec<Vec<i32>>> = vec![
            vec![vec![1], vec![10]],
            vec![vec![2], vec![20]],
            vec![vec![3], vec![30]],
            vec![vec![4], vec![40]],
        ];
        assert_eq!(v3.card([]), 4);
        assert_eq!(
            v3.equality(&[[[1], [10]], [[2], [20]], [[3], [30]], [[4], [40]]]),
            Equality::Equal
        );
        assert_eq!(
            v3.all().collect::<Vec<_>>(),
            vec![1, 10, 2, 20, 3, 30, 4, 40]
        );

        v3.push(vec![vec![5]]);
        v3.push(vec![vec![6], vec![60], vec![600]]);
        assert_eq!(v3.card([]), 6);
        assert_eq!(
            v3.equality(&[
                vec![[1], [10]],
                vec![[2], [20]],
                vec![[3], [30]],
                vec![[4], [40]],
                vec![[5]],
                vec![[6], [60], [600]]
            ]),
            Equality::Equal
        );
        assert_eq!(
            v3.all().collect::<Vec<_>>(),
            vec![1, 10, 2, 20, 3, 30, 4, 40, 5, 6, 60, 600]
        );
    }
}