1use rayon::prelude::*;
2
3#[test]
4fn check_intersperse() {
5 let v: Vec<_> = (0..1000).into_par_iter().intersperse(-1).collect();
6 assert_eq!(v.len(), 1999);
7 for (i, x) in v.into_iter().enumerate() {
8 assert_eq!(x, if i % 2 == 0 { i as i32 / 2 } else { -1 });
9 }
10}
11
12#[test]
13fn check_intersperse_again() {
14 let v: Vec<_> = (0..1000)
15 .into_par_iter()
16 .intersperse(-1)
17 .intersperse(-2)
18 .collect();
19 assert_eq!(v.len(), 3997);
20 for (i, x) in v.into_iter().enumerate() {
21 let y = match i % 4 {
22 0 => i as i32 / 4,
23 2 => -1,
24 _ => -2,
25 };
26 assert_eq!(x, y);
27 }
28}
29
30#[test]
31fn check_intersperse_unindexed() {
32 let v: Vec<_> = (0..1000).map(|i| i.to_string()).collect();
33 let s = v.join(",");
34 let s2 = v.join(";");
35 let par: String = s.par_split(',').intersperse(";").collect();
36 assert_eq!(par, s2);
37}
38
39#[test]
40fn check_intersperse_producer() {
41 (0..1000)
42 .into_par_iter()
43 .intersperse(-1)
44 .zip_eq(0..1999)
45 .for_each(|(x, i)| {
46 assert_eq!(x, if i % 2 == 0 { i / 2 } else { -1 });
47 });
48}
49
50#[test]
51fn check_intersperse_rev() {
52 (0..1000)
53 .into_par_iter()
54 .intersperse(-1)
55 .zip_eq(0..1999)
56 .rev()
57 .for_each(|(x, i)| {
58 assert_eq!(x, if i % 2 == 0 { i / 2 } else { -1 });
59 });
60}
61