restruct 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,257 @@
1
+ require 'minitest_helper'
2
+
3
+ [Restruct::Set, Restruct::MarshalSet].each do |klass|
4
+
5
+ describe klass do
6
+
7
+ let(:set) { klass.new }
8
+
9
+ def fill(elements)
10
+ redis.call 'SADD', set.id, *(elements.map { |e| set.send(:serialize, e) })
11
+ end
12
+
13
+ describe 'Setters' do
14
+
15
+ %w(add <<).each do |method|
16
+ it method do
17
+ fill %w(a b)
18
+
19
+ set.send(method, 'b').must_equal set
20
+ set.to_set.must_equal Set.new %w(a b)
21
+
22
+ set.send(method, 'c').must_equal set
23
+ set.to_set.must_equal Set.new %w(a b c)
24
+ end
25
+ end
26
+
27
+ it 'add?' do
28
+ fill %w(a b)
29
+
30
+ set.add?('b').must_be_nil
31
+ set.to_set.must_equal Set.new %w(a b)
32
+
33
+ set.add?('c').must_equal set
34
+ set.to_set.must_equal Set.new %w(a b c)
35
+ end
36
+
37
+ it 'merge' do
38
+ fill %w(a b)
39
+
40
+ set.merge(%w(b c d)).must_equal set
41
+ set.to_set.must_equal Set.new %w(a b c d)
42
+ end
43
+
44
+ it 'delete' do
45
+ fill %w(a b c d)
46
+
47
+ set.delete('x').must_equal set
48
+ set.to_set.must_equal Set.new %w(a b c d)
49
+
50
+ set.delete('b').must_equal set
51
+ set.to_set.must_equal Set.new %w(a c d)
52
+ end
53
+
54
+ it 'delete?' do
55
+ fill %w(a b c d)
56
+
57
+ set.delete?('x').must_be_nil
58
+ set.to_set.must_equal Set.new %w(a b c d)
59
+
60
+ set.delete?('b').must_equal set
61
+ set.to_set.must_equal Set.new %w(a c d)
62
+ end
63
+
64
+ it 'subtract' do
65
+ fill %w(a b c d)
66
+
67
+ set.subtract(%w(b c x)).must_equal set
68
+ set.to_set.must_equal Set.new %w(a d)
69
+ end
70
+
71
+ it 'delete_if' do
72
+ fill %w(a b c)
73
+
74
+ set.delete_if { |e| e == 'a' }.must_equal set
75
+ set.to_set.must_equal Set.new(%w(b c))
76
+ end
77
+
78
+ %w(keep_if select!).each do |method|
79
+ it method do
80
+ fill %w(a b c)
81
+
82
+ set.send(method) { |e| e == 'a' }.must_equal set
83
+ set.to_set.must_equal Set.new(%w(a))
84
+ end
85
+ end
86
+
87
+ it 'clear' do
88
+ fill %w(a b c d)
89
+
90
+ set.clear.must_equal set
91
+ set.must_be_empty
92
+ end
93
+
94
+ end
95
+
96
+ describe 'Info' do
97
+
98
+ %w(size count length).each do |method|
99
+ it method do
100
+ fill %w(a b c)
101
+ set.send(method).must_equal 3
102
+ end
103
+ end
104
+
105
+ it 'empty?' do
106
+ set.must_be :empty?
107
+ fill %w(a b c)
108
+ set.wont_be :empty?
109
+ end
110
+
111
+ it 'include?' do
112
+ fill %w(a b c)
113
+
114
+ assert set.include? 'a'
115
+ refute set.include? 'z'
116
+ end
117
+
118
+ end
119
+
120
+ describe 'Transformations' do
121
+
122
+ it 'to_a' do
123
+ fill %w(a b c)
124
+ set.to_a.sort.must_equal %w(a b c)
125
+ end
126
+
127
+ %w(to_set to_primitive).each do |method|
128
+ it method do
129
+ fill %w(a b c)
130
+ set.send(method).must_equal Set.new(%w(a b c))
131
+ end
132
+ end
133
+
134
+ end
135
+
136
+ describe 'Enumerable' do
137
+
138
+ it 'included module' do
139
+ assert klass.included_modules.include? Enumerable
140
+ end
141
+
142
+ it 'each' do
143
+ fill %w(a b c)
144
+
145
+ members = Set.new
146
+ set.each { |e| members << e }
147
+
148
+ members.must_equal set.to_set
149
+ end
150
+
151
+ end
152
+
153
+ describe 'Sets' do
154
+
155
+ %w(union | +).each do |method|
156
+ it method do
157
+ fill %w(a b c)
158
+ set.send(method, %w(a x y)).must_equal Set.new(%w(a b c x y))
159
+ end
160
+ end
161
+
162
+ %w(intersection &).each do |method|
163
+ it method do
164
+ fill %w(a b c)
165
+ set.send(method, %w(b a z)).must_equal Set.new(%w(a b))
166
+ end
167
+ end
168
+
169
+ %w(difference -).each do |method|
170
+ it method do
171
+ fill %w(a b c)
172
+ set.send(method, %w(a z)).must_equal Set.new(%w(b c))
173
+ end
174
+ end
175
+
176
+ %w(proper_subset? <).each do |method|
177
+ it method do
178
+ fill %w(a b)
179
+
180
+ assert set.send(method, Set.new(%w(a b c)))
181
+ refute set.send(method, Set.new(%w(a b)))
182
+ refute set.send(method, Set.new(%w(a x)))
183
+ end
184
+ end
185
+
186
+ %w(subset? <=).each do |method|
187
+ it method do
188
+ fill %w(a b)
189
+
190
+ assert set.send(method, Set.new(%w(a b c)))
191
+ assert set.send(method, Set.new(%w(a b)))
192
+ refute set.send(method, Set.new(%w(a x)))
193
+ end
194
+ end
195
+
196
+ %w(proper_superset? >).each do |method|
197
+ it method do
198
+ fill %w(a b c)
199
+
200
+ assert set.send(method, Set.new(%w(a b)))
201
+ refute set.send(method, Set.new(%w(a b c)))
202
+ refute set.send(method, Set.new(%w(a x)))
203
+ end
204
+ end
205
+
206
+ %w(superset? >=).each do |method|
207
+ it method do
208
+ fill %w(a b c)
209
+
210
+ assert set.send(method, Set.new(%w(a b)))
211
+ assert set.send(method, Set.new(%w(a b c)))
212
+ refute set.send(method, Set.new(%w(a x)))
213
+ end
214
+ end
215
+
216
+ it 'intersect?' do
217
+ fill %w(a b c)
218
+
219
+ assert set.intersect? Set.new(%w(a x y))
220
+ refute set.intersect? Set.new(%w(x y z))
221
+ end
222
+
223
+ it 'disjoint?' do
224
+ fill %w(a b c)
225
+
226
+ refute set.disjoint? Set.new(%w(a x y))
227
+ assert set.disjoint? Set.new(%w(x y z))
228
+ end
229
+
230
+ it '^' do
231
+ fill %w(a b c)
232
+ (set ^ %w(a x y)).must_equal Set.new(%w(b c x y))
233
+ end
234
+
235
+ end
236
+
237
+ it 'Equality' do
238
+ copy = klass.new id: set.id
239
+ assert set == copy
240
+ assert set.eql? copy
241
+ refute set.equal? copy
242
+ end
243
+
244
+ it 'Dump/Restore' do
245
+ fill %w(a b c)
246
+
247
+ dump = set.dump
248
+ other = klass.new
249
+ other.restore dump
250
+
251
+ other.id.wont_equal set.id
252
+ other.to_primitive.must_equal set.to_primitive
253
+ end
254
+
255
+ end
256
+
257
+ end
metadata ADDED
@@ -0,0 +1,192 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: restruct
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Naiman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redic
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: class_config
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: turn
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.9'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.9'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-nav
113
+ requirement: !ruby/object:Gem::Requirement
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
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Redis structures
126
+ email:
127
+ - gabynaiman@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".coveralls.yml"
133
+ - ".gitignore"
134
+ - ".ruby-gemset"
135
+ - ".ruby-version"
136
+ - ".travis.yml"
137
+ - Gemfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - lib/restruct.rb
142
+ - lib/restruct/array.rb
143
+ - lib/restruct/hash.rb
144
+ - lib/restruct/id.rb
145
+ - lib/restruct/marshal_array.rb
146
+ - lib/restruct/marshal_hash.rb
147
+ - lib/restruct/marshal_set.rb
148
+ - lib/restruct/marshalizable.rb
149
+ - lib/restruct/nested_hash.rb
150
+ - lib/restruct/set.rb
151
+ - lib/restruct/structure.rb
152
+ - lib/restruct/version.rb
153
+ - restruct.gemspec
154
+ - spec/array_spec.rb
155
+ - spec/coverage_helper.rb
156
+ - spec/hash_spec.rb
157
+ - spec/id_spec.rb
158
+ - spec/minitest_helper.rb
159
+ - spec/nested_hash_spec.rb
160
+ - spec/set_spec.rb
161
+ homepage: https://github.com/gabynaiman/restruct
162
+ licenses:
163
+ - MIT
164
+ metadata: {}
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ requirements: []
180
+ rubyforge_project:
181
+ rubygems_version: 2.2.2
182
+ signing_key:
183
+ specification_version: 4
184
+ summary: Redis structures
185
+ test_files:
186
+ - spec/array_spec.rb
187
+ - spec/coverage_helper.rb
188
+ - spec/hash_spec.rb
189
+ - spec/id_spec.rb
190
+ - spec/minitest_helper.rb
191
+ - spec/nested_hash_spec.rb
192
+ - spec/set_spec.rb