1 use std::time::Duration;
2
3 use crossbeam_channel::{after, bounded, never, tick, unbounded};
4
ms(ms: u64) -> Duration5 fn ms(ms: u64) -> Duration {
6 Duration::from_millis(ms)
7 }
8
9 #[test]
after_same_channel()10 fn after_same_channel() {
11 let r = after(ms(50));
12
13 let r2 = r.clone();
14 assert!(r.same_channel(&r2));
15
16 let r3 = after(ms(50));
17 assert!(!r.same_channel(&r3));
18 assert!(!r2.same_channel(&r3));
19
20 let r4 = after(ms(100));
21 assert!(!r.same_channel(&r4));
22 assert!(!r2.same_channel(&r4));
23 }
24
25 #[test]
array_same_channel()26 fn array_same_channel() {
27 let (s, r) = bounded::<usize>(1);
28
29 let s2 = s.clone();
30 assert!(s.same_channel(&s2));
31
32 let r2 = r.clone();
33 assert!(r.same_channel(&r2));
34
35 let (s3, r3) = bounded::<usize>(1);
36 assert!(!s.same_channel(&s3));
37 assert!(!s2.same_channel(&s3));
38 assert!(!r.same_channel(&r3));
39 assert!(!r2.same_channel(&r3));
40 }
41
42 #[test]
list_same_channel()43 fn list_same_channel() {
44 let (s, r) = unbounded::<usize>();
45
46 let s2 = s.clone();
47 assert!(s.same_channel(&s2));
48
49 let r2 = r.clone();
50 assert!(r.same_channel(&r2));
51
52 let (s3, r3) = unbounded::<usize>();
53 assert!(!s.same_channel(&s3));
54 assert!(!s2.same_channel(&s3));
55 assert!(!r.same_channel(&r3));
56 assert!(!r2.same_channel(&r3));
57 }
58
59 #[test]
never_same_channel()60 fn never_same_channel() {
61 let r = never::<usize>();
62
63 let r2 = r.clone();
64 assert!(r.same_channel(&r2));
65
66 // Never channel are always equal to one another.
67 let r3 = never::<usize>();
68 assert!(r.same_channel(&r3));
69 assert!(r2.same_channel(&r3));
70 }
71
72 #[test]
tick_same_channel()73 fn tick_same_channel() {
74 let r = tick(ms(50));
75
76 let r2 = r.clone();
77 assert!(r.same_channel(&r2));
78
79 let r3 = tick(ms(50));
80 assert!(!r.same_channel(&r3));
81 assert!(!r2.same_channel(&r3));
82
83 let r4 = tick(ms(100));
84 assert!(!r.same_channel(&r4));
85 assert!(!r2.same_channel(&r4));
86 }
87
88 #[test]
zero_same_channel()89 fn zero_same_channel() {
90 let (s, r) = bounded::<usize>(0);
91
92 let s2 = s.clone();
93 assert!(s.same_channel(&s2));
94
95 let r2 = r.clone();
96 assert!(r.same_channel(&r2));
97
98 let (s3, r3) = bounded::<usize>(0);
99 assert!(!s.same_channel(&s3));
100 assert!(!s2.same_channel(&s3));
101 assert!(!r.same_channel(&r3));
102 assert!(!r2.same_channel(&r3));
103 }
104
105 #[test]
different_flavors_same_channel()106 fn different_flavors_same_channel() {
107 let (s1, r1) = bounded::<usize>(0);
108 let (s2, r2) = unbounded::<usize>();
109
110 assert!(!s1.same_channel(&s2));
111 assert!(!r1.same_channel(&r2));
112 }
113