summaryrefslogtreecommitdiffstats
path: root/third_party/rust/rayon/tests/clones.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/rayon/tests/clones.rs
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/rayon/tests/clones.rs')
-rw-r--r--third_party/rust/rayon/tests/clones.rs200
1 files changed, 200 insertions, 0 deletions
diff --git a/third_party/rust/rayon/tests/clones.rs b/third_party/rust/rayon/tests/clones.rs
new file mode 100644
index 0000000000..2b78f09876
--- /dev/null
+++ b/third_party/rust/rayon/tests/clones.rs
@@ -0,0 +1,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());
+}