summaryrefslogtreecommitdiffstats
path: root/third_party/rust/rayon/tests/clones.rs
blob: 2b78f0987633c11e13cb3f5a36283fea0e995f64 (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
use rayon::prelude::*;

fn check<I>(iter: I)
where
    I: ParallelIterator + Clone,
    I::Item: std::fmt::Debug + PartialEq,
{
    let a: Vec<_> = iter.clone().collect();
    let b: Vec<_> = iter.collect();
    assert_eq!(a, b);
}

#[test]
fn clone_binary_heap() {
    use std::collections::BinaryHeap;
    let heap: BinaryHeap<_> = (0..1000).collect();
    check(heap.par_iter());
    check(heap.into_par_iter());
}

#[test]
fn clone_btree_map() {
    use std::collections::BTreeMap;
    let map: BTreeMap<_, _> = (0..1000).enumerate().collect();
    check(map.par_iter());
}

#[test]
fn clone_btree_set() {
    use std::collections::BTreeSet;
    let set: BTreeSet<_> = (0..1000).collect();
    check(set.par_iter());
}

#[test]
fn clone_hash_map() {
    use std::collections::HashMap;
    let map: HashMap<_, _> = (0..1000).enumerate().collect();
    check(map.par_iter());
}

#[test]
fn clone_hash_set() {
    use std::collections::HashSet;
    let set: HashSet<_> = (0..1000).collect();
    check(set.par_iter());
}

#[test]
fn clone_linked_list() {
    use std::collections::LinkedList;
    let list: LinkedList<_> = (0..1000).collect();
    check(list.par_iter());
    check(list.into_par_iter());
}

#[test]
fn clone_vec_deque() {
    use std::collections::VecDeque;
    let deque: VecDeque<_> = (0..1000).collect();
    check(deque.par_iter());
    check(deque.into_par_iter());
}

#[test]
fn clone_option() {
    let option = Some(0);
    check(option.par_iter());
    check(option.into_par_iter());
}

#[test]
fn clone_result() {
    let result = Ok::<_, ()>(0);
    check(result.par_iter());
    check(result.into_par_iter());
}

#[test]
fn clone_range() {
    check((0..1000).into_par_iter());
}

#[test]
fn clone_range_inclusive() {
    check((0..=1000).into_par_iter());
}

#[test]
fn clone_str() {
    let s = include_str!("clones.rs");
    check(s.par_chars());
    check(s.par_lines());
    check(s.par_split('\n'));
    check(s.par_split_terminator('\n'));
    check(s.par_split_whitespace());
}

#[test]
fn clone_vec() {
    let v: Vec<_> = (0..1000).collect();
    check(v.par_iter());
    check(v.par_chunks(42));
    check(v.par_chunks_exact(42));
    check(v.par_rchunks(42));
    check(v.par_rchunks_exact(42));
    check(v.par_windows(42));
    check(v.par_split(|x| x % 3 == 0));
    check(v.into_par_iter());
}

#[test]
fn clone_array() {
    let a = [0i32; 100];
    check(a.into_par_iter());
}

#[test]
fn clone_adaptors() {
    let v: Vec<_> = (0..1000).map(Some).collect();
    check(v.par_iter().chain(&v));
    check(v.par_iter().cloned());
    check(v.par_iter().copied());
    check(v.par_iter().enumerate());
    check(v.par_iter().filter(|_| true));
    check(v.par_iter().filter_map(|x| *x));
    check(v.par_iter().flat_map(|x| *x));
    check(v.par_iter().flat_map_iter(|x| *x));
    check(v.par_iter().flatten());
    check(v.par_iter().flatten_iter());
    check(v.par_iter().with_max_len(1).fold(|| 0, |x, _| x));
    check(v.par_iter().with_max_len(1).fold_with(0, |x, _| x));
    check(v.par_iter().with_max_len(1).fold_chunks(1, || 0, |x, _| x));
    check(
        v.par_iter()
            .with_max_len(1)
            .fold_chunks_with(1, 0, |x, _| x),
    );
    check(v.par_iter().with_max_len(1).try_fold(|| 0, |_, &x| x));
    check(v.par_iter().with_max_len(1).try_fold_with(0, |_, &x| x));
    check(v.par_iter().inspect(|_| ()));
    check(v.par_iter().update(|_| ()));
    check(v.par_iter().interleave(&v));
    check(v.par_iter().interleave_shortest(&v));
    check(v.par_iter().intersperse(&None));
    check(v.par_iter().chunks(3));
    check(v.par_iter().map(|x| x));
    check(v.par_iter().map_with(0, |_, x| x));
    check(v.par_iter().map_init(|| 0, |_, x| x));
    check(v.par_iter().panic_fuse());
    check(v.par_iter().positions(|_| true));
    check(v.par_iter().rev());
    check(v.par_iter().skip(1));
    check(v.par_iter().take(1));
    check(v.par_iter().cloned().while_some());
    check(v.par_iter().with_max_len(1));
    check(v.par_iter().with_min_len(1));
    check(v.par_iter().zip(&v));
    check(v.par_iter().zip_eq(&v));
    check(v.par_iter().step_by(2));
}

#[test]
fn clone_empty() {
    check(rayon::iter::empty::<i32>());
}

#[test]
fn clone_once() {
    check(rayon::iter::once(10));
}

#[test]
fn clone_repeat() {
    let x: Option<i32> = None;
    check(rayon::iter::repeat(x).while_some());
    check(rayon::iter::repeatn(x, 1000));
}

#[test]
fn clone_splitter() {
    check(rayon::iter::split(0..1000, |x| (x, None)));
}

#[test]
fn clone_multizip() {
    let v: &Vec<_> = &(0..1000).collect();
    check((v,).into_par_iter());
    check((v, v).into_par_iter());
    check((v, v, v).into_par_iter());
    check((v, v, v, v).into_par_iter());
    check((v, v, v, v, v).into_par_iter());
    check((v, v, v, v, v, v).into_par_iter());
    check((v, v, v, v, v, v, v).into_par_iter());
    check((v, v, v, v, v, v, v, v).into_par_iter());
    check((v, v, v, v, v, v, v, v, v).into_par_iter());
    check((v, v, v, v, v, v, v, v, v, v).into_par_iter());
    check((v, v, v, v, v, v, v, v, v, v, v).into_par_iter());
    check((v, v, v, v, v, v, v, v, v, v, v, v).into_par_iter());
}