1use crossbeam_deque::Steal::Success;
2use crossbeam_deque::{Injector, Worker};
3
4#[test]
5fn steal_fifo() {
6 let w = Worker::new_fifo();
7 for i in 1..=3 {
8 w.push(i);
9 }
10
11 let s = w.stealer();
12 assert_eq!(s.steal(), Success(1));
13 assert_eq!(s.steal(), Success(2));
14 assert_eq!(s.steal(), Success(3));
15}
16
17#[test]
18fn steal_lifo() {
19 let w = Worker::new_lifo();
20 for i in 1..=3 {
21 w.push(i);
22 }
23
24 let s = w.stealer();
25 assert_eq!(s.steal(), Success(1));
26 assert_eq!(s.steal(), Success(2));
27 assert_eq!(s.steal(), Success(3));
28}
29
30#[test]
31fn steal_injector() {
32 let q = Injector::new();
33 for i in 1..=3 {
34 q.push(i);
35 }
36
37 assert_eq!(q.steal(), Success(1));
38 assert_eq!(q.steal(), Success(2));
39 assert_eq!(q.steal(), Success(3));
40}
41
42#[test]
43fn steal_batch_fifo_fifo() {
44 let w = Worker::new_fifo();
45 for i in 1..=4 {
46 w.push(i);
47 }
48
49 let s = w.stealer();
50 let w2 = Worker::new_fifo();
51
52 assert_eq!(s.steal_batch(&w2), Success(()));
53 assert_eq!(w2.pop(), Some(1));
54 assert_eq!(w2.pop(), Some(2));
55}
56
57#[test]
58fn steal_batch_lifo_lifo() {
59 let w = Worker::new_lifo();
60 for i in 1..=4 {
61 w.push(i);
62 }
63
64 let s = w.stealer();
65 let w2 = Worker::new_lifo();
66
67 assert_eq!(s.steal_batch(&w2), Success(()));
68 assert_eq!(w2.pop(), Some(2));
69 assert_eq!(w2.pop(), Some(1));
70}
71
72#[test]
73fn steal_batch_fifo_lifo() {
74 let w = Worker::new_fifo();
75 for i in 1..=4 {
76 w.push(i);
77 }
78
79 let s = w.stealer();
80 let w2 = Worker::new_lifo();
81
82 assert_eq!(s.steal_batch(&w2), Success(()));
83 assert_eq!(w2.pop(), Some(1));
84 assert_eq!(w2.pop(), Some(2));
85}
86
87#[test]
88fn steal_batch_lifo_fifo() {
89 let w = Worker::new_lifo();
90 for i in 1..=4 {
91 w.push(i);
92 }
93
94 let s = w.stealer();
95 let w2 = Worker::new_fifo();
96
97 assert_eq!(s.steal_batch(&w2), Success(()));
98 assert_eq!(w2.pop(), Some(2));
99 assert_eq!(w2.pop(), Some(1));
100}
101
102#[test]
103fn steal_batch_injector_fifo() {
104 let q = Injector::new();
105 for i in 1..=4 {
106 q.push(i);
107 }
108
109 let w2 = Worker::new_fifo();
110 assert_eq!(q.steal_batch(&w2), Success(()));
111 assert_eq!(w2.pop(), Some(1));
112 assert_eq!(w2.pop(), Some(2));
113}
114
115#[test]
116fn steal_batch_injector_lifo() {
117 let q = Injector::new();
118 for i in 1..=4 {
119 q.push(i);
120 }
121
122 let w2 = Worker::new_lifo();
123 assert_eq!(q.steal_batch(&w2), Success(()));
124 assert_eq!(w2.pop(), Some(1));
125 assert_eq!(w2.pop(), Some(2));
126}
127
128#[test]
129fn steal_batch_and_pop_fifo_fifo() {
130 let w = Worker::new_fifo();
131 for i in 1..=6 {
132 w.push(i);
133 }
134
135 let s = w.stealer();
136 let w2 = Worker::new_fifo();
137
138 assert_eq!(s.steal_batch_and_pop(&w2), Success(1));
139 assert_eq!(w2.pop(), Some(2));
140 assert_eq!(w2.pop(), Some(3));
141}
142
143#[test]
144fn steal_batch_and_pop_lifo_lifo() {
145 let w = Worker::new_lifo();
146 for i in 1..=6 {
147 w.push(i);
148 }
149
150 let s = w.stealer();
151 let w2 = Worker::new_lifo();
152
153 assert_eq!(s.steal_batch_and_pop(&w2), Success(3));
154 assert_eq!(w2.pop(), Some(2));
155 assert_eq!(w2.pop(), Some(1));
156}
157
158#[test]
159fn steal_batch_and_pop_fifo_lifo() {
160 let w = Worker::new_fifo();
161 for i in 1..=6 {
162 w.push(i);
163 }
164
165 let s = w.stealer();
166 let w2 = Worker::new_lifo();
167
168 assert_eq!(s.steal_batch_and_pop(&w2), Success(1));
169 assert_eq!(w2.pop(), Some(2));
170 assert_eq!(w2.pop(), Some(3));
171}
172
173#[test]
174fn steal_batch_and_pop_lifo_fifo() {
175 let w = Worker::new_lifo();
176 for i in 1..=6 {
177 w.push(i);
178 }
179
180 let s = w.stealer();
181 let w2 = Worker::new_fifo();
182
183 assert_eq!(s.steal_batch_and_pop(&w2), Success(3));
184 assert_eq!(w2.pop(), Some(2));
185 assert_eq!(w2.pop(), Some(1));
186}
187
188#[test]
189fn steal_batch_and_pop_injector_fifo() {
190 let q = Injector::new();
191 for i in 1..=6 {
192 q.push(i);
193 }
194
195 let w2 = Worker::new_fifo();
196 assert_eq!(q.steal_batch_and_pop(&w2), Success(1));
197 assert_eq!(w2.pop(), Some(2));
198 assert_eq!(w2.pop(), Some(3));
199}
200
201#[test]
202fn steal_batch_and_pop_injector_lifo() {
203 let q = Injector::new();
204 for i in 1..=6 {
205 q.push(i);
206 }
207
208 let w2 = Worker::new_lifo();
209 assert_eq!(q.steal_batch_and_pop(&w2), Success(1));
210 assert_eq!(w2.pop(), Some(2));
211 assert_eq!(w2.pop(), Some(3));
212}
213