unified-queues 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/test ADDED
@@ -0,0 +1,297 @@
1
+ #!/usr/bin/ruby
2
+ # encoding: utf-8
3
+ # (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
4
+
5
+ $:.push("./lib")
6
+ $:.unshift("./lib")
7
+
8
+ require "unified-queues"
9
+ require "riot"
10
+
11
+ context "Single: Array (from Ruby STL)" do
12
+ setup do
13
+ UnifiedQueues::Single::new(Array)
14
+ end
15
+
16
+ asserts("#clear!") do
17
+ initial = topic.empty?
18
+ topic.push(:foo)
19
+ topic.clear!
20
+ after = topic.empty?
21
+ initial and after
22
+ end
23
+ asserts("#empty?") do
24
+ initial = topic.empty?
25
+ topic.push(:foo)
26
+ after = topic.empty?
27
+ topic.pop
28
+ initial and not after
29
+ end
30
+ asserts("#length") do
31
+ initial = topic.length
32
+ topic.push(:foo)
33
+ after = topic.length
34
+ topic.pop
35
+ initial == 0 and after == 1
36
+ end
37
+ asserts("#pop") do
38
+ topic.push(:foo)
39
+ topic.push(:bar)
40
+ topic.pop == :foo and topic.pop == :bar
41
+ end
42
+ asserts("#push") do
43
+ topic.push(:foo)
44
+ topic.pop == :foo
45
+ end
46
+ end
47
+
48
+ context "Single: Queue (from Ruby STL)" do
49
+ setup do
50
+ require "thread"
51
+ UnifiedQueues::Single::new(Queue)
52
+ end
53
+
54
+ asserts("#clear!") do
55
+ initial = topic.empty?
56
+ topic.push(:foo)
57
+ topic.clear!
58
+ after = topic.empty?
59
+ initial and after
60
+ end
61
+ asserts("#empty?") do
62
+ initial = topic.empty?
63
+ topic.push(:foo)
64
+ after = topic.empty?
65
+ topic.pop
66
+ initial and not after
67
+ end
68
+ asserts("#length") do
69
+ initial = topic.length
70
+ topic.push(:foo)
71
+ after = topic.length
72
+ topic.pop
73
+ initial == 0 and after == 1
74
+ end
75
+ asserts("#pop") do
76
+ topic.push(:foo)
77
+ topic.push(:bar)
78
+ topic.pop == :foo and topic.pop == :bar
79
+ end
80
+ asserts("#push") do
81
+ topic.push(:foo)
82
+ topic.pop == :foo
83
+ end
84
+ end
85
+
86
+ context "Single: Containers::Heap (from 'algorithms')" do
87
+ setup do
88
+ require "algorithms"
89
+ UnifiedQueues::Single::new(Containers::Heap)
90
+ end
91
+
92
+ asserts("#clear!") do
93
+ initial = topic.empty?
94
+ topic.push(:foo)
95
+ topic.clear!
96
+ after = topic.empty?
97
+ initial and after
98
+ end
99
+ asserts("#empty?") do
100
+ initial = topic.empty?
101
+ topic.push(:foo)
102
+ after = topic.empty?
103
+ topic.pop
104
+ initial and not after
105
+ end
106
+ asserts("#length") do
107
+ initial = topic.length
108
+ topic.push(:foo)
109
+ after = topic.length
110
+ topic.pop
111
+ initial == 0 and after == 1
112
+ end
113
+ asserts("#pop") do
114
+ topic.push(:foo, 2)
115
+ topic.push(:bar, 1)
116
+ topic.pop == :bar and topic.pop == :foo
117
+ end
118
+ asserts("#push") do
119
+ topic.push(:foo)
120
+ topic.pop == :foo
121
+ end
122
+ end
123
+
124
+ context "Single: Depq (from 'depq')" do
125
+ setup do
126
+ require "depq"
127
+ UnifiedQueues::Single::new(Depq)
128
+ end
129
+
130
+ asserts("#clear!") do
131
+ initial = topic.empty?
132
+ topic.push(:foo)
133
+ topic.clear!
134
+ after = topic.empty?
135
+ initial and after
136
+ end
137
+ asserts("#empty?") do
138
+ initial = topic.empty?
139
+ topic.push(:foo)
140
+ after = topic.empty?
141
+ topic.pop
142
+ initial and not after
143
+ end
144
+ asserts("#length") do
145
+ initial = topic.length
146
+ topic.push(:foo)
147
+ after = topic.length
148
+ topic.pop
149
+ initial == 0 and after == 1
150
+ end
151
+ asserts("#pop") do
152
+ topic.push(:foo, 2)
153
+ topic.push(:bar, 1)
154
+ topic.pop == :bar and topic.pop == :foo
155
+ end
156
+ asserts("#push") do
157
+ topic.push(:foo)
158
+ topic.pop == :foo
159
+ end
160
+ end
161
+
162
+ context "Single: EventedQueue (from 'evented-queue')" do
163
+ setup do
164
+ require "evented-queue"
165
+ UnifiedQueues::Single::new(EventedQueue)
166
+ end
167
+
168
+ asserts("#clear!") do
169
+ initial = topic.empty?
170
+ topic.push(:foo)
171
+ topic.clear!
172
+ after = topic.empty?
173
+ initial and after
174
+ end
175
+ asserts("#empty?") do
176
+ initial = topic.empty?
177
+ topic.push(:foo)
178
+ after = topic.empty?
179
+ topic.pop
180
+ initial and not after
181
+ end
182
+ asserts("#length") do
183
+ initial = topic.length
184
+ topic.push(:foo)
185
+ after = topic.length
186
+ topic.pop
187
+ initial == 0 and after == 1
188
+ end
189
+ asserts("#pop") do
190
+ topic.push(:foo)
191
+ topic.push(:bar)
192
+ topic.pop == :foo and topic.pop == :bar
193
+ end
194
+ asserts("#push") do
195
+ topic.push(:foo)
196
+ topic.pop == :foo
197
+ end
198
+ end
199
+
200
+ context "Single: CPriorityQueue (from 'priority_queue')" do
201
+ setup do
202
+ require "priority_queue/c_priority_queue"
203
+ UnifiedQueues::Single::new(CPriorityQueue)
204
+ end
205
+
206
+ asserts("#clear!") do
207
+ initial = topic.empty?
208
+ topic.push(:foo)
209
+ topic.clear!
210
+ after = topic.empty?
211
+ initial and after
212
+ end
213
+ asserts("#empty?") do
214
+ initial = topic.empty?
215
+ topic.push(:foo)
216
+ after = topic.empty?
217
+ topic.pop
218
+ initial and not after
219
+ end
220
+ asserts("#length") do
221
+ initial = topic.length
222
+ topic.push(:foo)
223
+ after = topic.length
224
+ topic.pop
225
+ initial == 0 and after == 1
226
+ end
227
+ asserts("#pop") do
228
+ topic.push(:foo, 2)
229
+ topic.push(:bar, 1)
230
+ topic.pop == :bar and topic.pop == :foo
231
+ end
232
+ asserts("#push") do
233
+ topic.push(:foo)
234
+ topic.pop == :foo
235
+ end
236
+ end
237
+
238
+ context "Single: PoorPriorityQueue (from 'priority_queue')" do
239
+ setup do
240
+ require "priority_queue/poor_priority_queue"
241
+ UnifiedQueues::Single::new(PoorPriorityQueue)
242
+ end
243
+
244
+ asserts("#clear!") do
245
+ topic.push(:foo)
246
+ topic.clear!
247
+ topic.pop.nil?
248
+ end
249
+ asserts("#pop") do
250
+ topic.push(:foo, 2)
251
+ topic.push(:bar, 1)
252
+ topic.pop == :bar and topic.pop == :foo
253
+ end
254
+ asserts("#push") do
255
+ topic.push(:foo)
256
+ topic.pop == :foo
257
+ end
258
+ end
259
+
260
+ context "Single: RubyPriorityQueue (from 'priority_queue')" do
261
+ setup do
262
+ require "priority_queue/ruby_priority_queue"
263
+ UnifiedQueues::Single::new(RubyPriorityQueue)
264
+ end
265
+
266
+ asserts("#clear!") do
267
+ initial = topic.empty?
268
+ topic.push(:foo)
269
+ topic.clear!
270
+ after = topic.empty?
271
+ initial and after
272
+ end
273
+ asserts("#empty?") do
274
+ initial = topic.empty?
275
+ topic.push(:foo)
276
+ after = topic.empty?
277
+ topic.pop
278
+ initial and not after
279
+ end
280
+ asserts("#length") do
281
+ initial = topic.length
282
+ topic.push(:foo)
283
+ after = topic.length
284
+ topic.pop
285
+ initial == 0 and after == 1
286
+ end
287
+ asserts("#pop") do
288
+ topic.push(:foo, 2)
289
+ topic.push(:bar, 1)
290
+ topic.pop == :bar and topic.pop == :foo
291
+ end
292
+ asserts("#push") do
293
+ topic.push(:foo)
294
+ topic.pop == :foo
295
+ end
296
+ end
297
+
metadata ADDED
@@ -0,0 +1,218 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unified-queues
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Martin Kozák
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: abstract
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: hash-utils
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.18.1
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.18.1
46
+ - !ruby/object:Gem::Dependency
47
+ name: lookup-hash
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 1.0.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.0.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: jeweler2
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 2.0.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 2.0.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: riot
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: 0.12.3
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 0.12.3
110
+ - !ruby/object:Gem::Dependency
111
+ name: PriorityQueue
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: algorithms
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: depq
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ description:
159
+ email: martinkozak@martinkozak.net
160
+ executables: []
161
+ extensions: []
162
+ extra_rdoc_files:
163
+ - LICENSE.txt
164
+ - README.md
165
+ files:
166
+ - .document
167
+ - CHANGES.txt
168
+ - Gemfile
169
+ - Gemfile.lock
170
+ - LICENSE.txt
171
+ - README.md
172
+ - Rakefile
173
+ - VERSION
174
+ - debug
175
+ - lib/unified-queues.rb
176
+ - lib/unified-queues/multi.rb
177
+ - lib/unified-queues/multi/driver.rb
178
+ - lib/unified-queues/multi/driver/em-jack.rb
179
+ - lib/unified-queues/multi/driver/unified-queues.rb
180
+ - lib/unified-queues/single.rb
181
+ - lib/unified-queues/single/driver.rb
182
+ - lib/unified-queues/single/driver/algorithms.rb
183
+ - lib/unified-queues/single/driver/array.rb
184
+ - lib/unified-queues/single/driver/depq.rb
185
+ - lib/unified-queues/single/driver/evented-queue.rb
186
+ - lib/unified-queues/single/driver/priority_queue.rb
187
+ - lib/unified-queues/single/driver/queue.rb
188
+ - test
189
+ homepage: http://github.com/martinkozak/unified-queue
190
+ licenses:
191
+ - MIT
192
+ post_install_message:
193
+ rdoc_options: []
194
+ require_paths:
195
+ - lib
196
+ required_ruby_version: !ruby/object:Gem::Requirement
197
+ none: false
198
+ requirements:
199
+ - - ! '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ segments:
203
+ - 0
204
+ hash: -1165763858604757789
205
+ required_rubygems_version: !ruby/object:Gem::Requirement
206
+ none: false
207
+ requirements:
208
+ - - ! '>='
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ requirements: []
212
+ rubyforge_project:
213
+ rubygems_version: 1.8.24
214
+ signing_key:
215
+ specification_version: 3
216
+ summary: Unifies many queue implementations under the single interface. Includes both
217
+ single queue libraries and multiple queue libraries.
218
+ test_files: []