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