1 extern crate rayon;
2
3 use rayon::prelude::*;
4
check<I>(iter: I) where I: ParallelIterator + Clone, I::Item: std::fmt::Debug + PartialEq,5 fn check<I>(iter: I)
6 where
7 I: ParallelIterator + Clone,
8 I::Item: std::fmt::Debug + PartialEq,
9 {
10 let a: Vec<_> = iter.clone().collect();
11 let b: Vec<_> = iter.collect();
12 assert_eq!(a, b);
13 }
14
15 #[test]
clone_binary_heap()16 fn clone_binary_heap() {
17 use std::collections::BinaryHeap;
18 let heap: BinaryHeap<_> = (0..1000).collect();
19 check(heap.par_iter());
20 check(heap.into_par_iter());
21 }
22
23 #[test]
clone_btree_map()24 fn clone_btree_map() {
25 use std::collections::BTreeMap;
26 let map: BTreeMap<_, _> = (0..1000).enumerate().collect();
27 check(map.par_iter());
28 }
29
30 #[test]
clone_btree_set()31 fn clone_btree_set() {
32 use std::collections::BTreeSet;
33 let set: BTreeSet<_> = (0..1000).collect();
34 check(set.par_iter());
35 }
36
37 #[test]
clone_hash_map()38 fn clone_hash_map() {
39 use std::collections::HashMap;
40 let map: HashMap<_, _> = (0..1000).enumerate().collect();
41 check(map.par_iter());
42 }
43
44 #[test]
clone_hash_set()45 fn clone_hash_set() {
46 use std::collections::HashSet;
47 let set: HashSet<_> = (0..1000).collect();
48 check(set.par_iter());
49 }
50
51 #[test]
clone_linked_list()52 fn clone_linked_list() {
53 use std::collections::LinkedList;
54 let list: LinkedList<_> = (0..1000).collect();
55 check(list.par_iter());
56 check(list.into_par_iter());
57 }
58
59 #[test]
clone_vec_deque()60 fn clone_vec_deque() {
61 use std::collections::VecDeque;
62 let deque: VecDeque<_> = (0..1000).collect();
63 check(deque.par_iter());
64 check(deque.into_par_iter());
65 }
66
67 #[test]
clone_option()68 fn clone_option() {
69 let option = Some(0);
70 check(option.par_iter());
71 check(option.into_par_iter());
72 }
73
74 #[test]
clone_result()75 fn clone_result() {
76 let result = Ok::<_, ()>(0);
77 check(result.par_iter());
78 check(result.into_par_iter());
79 }
80
81 #[test]
clone_range()82 fn clone_range() {
83 check((0..1000).into_par_iter());
84 }
85
86 #[test]
clone_range_inclusive()87 fn clone_range_inclusive() {
88 check((0..=1000).into_par_iter());
89 }
90
91 #[test]
clone_str()92 fn clone_str() {
93 let s = include_str!("clones.rs");
94 check(s.par_chars());
95 check(s.par_lines());
96 check(s.par_split('\n'));
97 check(s.par_split_terminator('\n'));
98 check(s.par_split_whitespace());
99 }
100
101 #[test]
clone_vec()102 fn clone_vec() {
103 let v: Vec<_> = (0..1000).collect();
104 check(v.par_iter());
105 check(v.par_chunks(42));
106 check(v.par_windows(42));
107 check(v.par_split(|x| x % 3 == 0));
108 check(v.into_par_iter());
109 }
110
111 #[test]
clone_adaptors()112 fn clone_adaptors() {
113 let v: Vec<_> = (0..1000).map(Some).collect();
114 check(v.par_iter().chain(&v));
115 check(v.par_iter().cloned());
116 check(v.par_iter().enumerate());
117 check(v.par_iter().filter(|_| true));
118 check(v.par_iter().filter_map(|x| *x));
119 check(v.par_iter().flat_map(|x| *x));
120 check(v.par_iter().flatten());
121 check(v.par_iter().with_max_len(1).fold(|| 0, |x, _| x));
122 check(v.par_iter().with_max_len(1).fold_with(0, |x, _| x));
123 check(v.par_iter().with_max_len(1).try_fold(|| 0, |_, &x| x));
124 check(v.par_iter().with_max_len(1).try_fold_with(0, |_, &x| x));
125 check(v.par_iter().inspect(|_| ()));
126 check(v.par_iter().update(|_| ()));
127 check(v.par_iter().interleave(&v));
128 check(v.par_iter().interleave_shortest(&v));
129 check(v.par_iter().intersperse(&None));
130 check(v.par_iter().chunks(3));
131 check(v.par_iter().map(|x| x));
132 check(v.par_iter().map_with(0, |_, x| x));
133 check(v.par_iter().map_init(|| 0, |_, x| x));
134 check(v.par_iter().panic_fuse());
135 check(v.par_iter().rev());
136 check(v.par_iter().skip(1));
137 check(v.par_iter().take(1));
138 check(v.par_iter().cloned().while_some());
139 check(v.par_iter().with_max_len(1));
140 check(v.par_iter().with_min_len(1));
141 check(v.par_iter().zip(&v));
142 check(v.par_iter().zip_eq(&v));
143 }
144
145 #[test]
clone_empty()146 fn clone_empty() {
147 check(rayon::iter::empty::<i32>());
148 }
149
150 #[test]
clone_once()151 fn clone_once() {
152 check(rayon::iter::once(10));
153 }
154
155 #[test]
clone_repeat()156 fn clone_repeat() {
157 let x: Option<i32> = None;
158 check(rayon::iter::repeat(x).while_some());
159 check(rayon::iter::repeatn(x, 1000));
160 }
161
162 #[test]
clone_splitter()163 fn clone_splitter() {
164 check(rayon::iter::split(0..1000, |x| (x, None)));
165 }
166