hashery 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.ruby +57 -92
  2. data/.yardopts +8 -0
  3. data/COPYING.rdoc +45 -0
  4. data/HISTORY.rdoc +18 -0
  5. data/QED.rdoc +1 -0
  6. data/README.rdoc +42 -16
  7. data/lib/hashery.rb +16 -9
  8. data/lib/hashery.yml +57 -92
  9. data/lib/hashery/association.rb +3 -1
  10. data/lib/hashery/basic_object.rb +74 -0
  11. data/lib/hashery/basic_struct.rb +288 -1
  12. data/lib/hashery/basicobject.rb +1 -74
  13. data/lib/hashery/basicstruct.rb +1 -280
  14. data/lib/hashery/casting_hash.rb +171 -1
  15. data/lib/hashery/castinghash.rb +1 -171
  16. data/lib/hashery/core_ext.rb +82 -0
  17. data/lib/hashery/dictionary.rb +3 -0
  18. data/lib/hashery/fuzzy_hash.rb +154 -1
  19. data/lib/hashery/fuzzyhash.rb +1 -154
  20. data/lib/hashery/ini.rb +3 -2
  21. data/lib/hashery/key_hash.rb +186 -0
  22. data/lib/hashery/keyhash.rb +1 -0
  23. data/lib/hashery/linked_list.rb +195 -1
  24. data/lib/hashery/linkedlist.rb +1 -195
  25. data/lib/hashery/lru_hash.rb +273 -1
  26. data/lib/hashery/lruhash.rb +1 -273
  27. data/lib/hashery/open_cascade.rb +99 -1
  28. data/lib/hashery/open_hash.rb +77 -1
  29. data/lib/hashery/opencascade.rb +1 -99
  30. data/lib/hashery/openhash.rb +1 -77
  31. data/lib/hashery/ordered_hash.rb +168 -1
  32. data/lib/hashery/orderedhash.rb +1 -167
  33. data/lib/hashery/property_hash.rb +97 -1
  34. data/lib/hashery/propertyhash.rb +1 -97
  35. data/lib/hashery/query_hash.rb +35 -1
  36. data/lib/hashery/queryhash.rb +1 -35
  37. data/lib/hashery/stash.rb +3 -174
  38. data/lib/hashery/static_hash.rb +48 -1
  39. data/lib/hashery/statichash.rb +1 -48
  40. data/qed/06_opencascade.rdoc +12 -12
  41. data/test/case_association.rb +29 -15
  42. data/test/case_basicstruct.rb +192 -0
  43. data/test/case_dictionary.rb +149 -109
  44. data/test/case_keyhash.rb +175 -0
  45. data/test/case_opencascade.rb +89 -43
  46. data/test/case_openhash.rb +15 -11
  47. metadata +85 -78
  48. data/LICENSE +0 -206
  49. data/NOTICE +0 -11
  50. data/lib/hashery/sparse_array.rb +0 -1
  51. data/lib/hashery/sparsearray.rb +0 -577
  52. data/test/case_openobject.rb +0 -130
  53. data/test/case_sparsearray.rb +0 -316
  54. data/test/case_stash.rb +0 -131
@@ -1,130 +0,0 @@
1
- require 'hashery/openobject'
2
-
3
- TestCase OpenObject do
4
-
5
- Unit :respond_to? do
6
- o = OpenObject.new
7
- assert{ o.respond_to?(:key?) }
8
- end
9
-
10
- Unit :is_a? do
11
- assert OpenObject[{}].is_a?(Hash)
12
- assert OpenObject[{}].is_a?(OpenObject)
13
- end
14
-
15
- Unit :[] => "subhash access" do
16
- o = OpenObject[:a=>1,:b=>{:x=>9}]
17
- assert{ o[:b][:x] == 9 }
18
- assert{ o.b[:x] == 9 }
19
- end
20
-
21
- Unit :[] => "indifferent key access" do
22
- o = OpenObject["a"=>1,"b"=>{:x=>9}]
23
- assert{ o["a"] == 1 }
24
- assert{ o[:a] == 1 }
25
- assert{ o["b"] == {:x=>9} }
26
- assert{ o[:b] == {:x=>9} }
27
- assert{ o["b"][:x] == 9 }
28
- assert{ o[:b]["x"] == nil }
29
- end
30
-
31
- Unit :[]= => "setting first entry" do
32
- f0 = OpenObject.new
33
- f0[:a] = 1
34
- assert{ f0.to_h == {:a=>1} }
35
- end
36
-
37
- Unit :[]= => "setting an additional entry" do
38
- f0 = OpenObject[:a=>1]
39
- f0[:b] = 2
40
- assert{ f0.to_h == {:a=>1,:b=>2} }
41
- end
42
-
43
- Unit :method_missing => "reading entries" do
44
- f0 = OpenObject[:class=>1]
45
- assert{ f0.class == 1 }
46
- end
47
-
48
- Unit :method_missing => "setting entries" do
49
- fo = OpenObject.new
50
- 9.times{ |i| fo.__send__("n#{i}=", 1) }
51
- 9.times{ |i|
52
- assert( fo.__send__("n#{i}") == 1 )
53
- }
54
- end
55
-
56
- Unit :method_missing => "using bang" do
57
- o = OpenObject.new
58
- o.a = 10
59
- o.b = 20
60
- h = {}
61
- o.each!{ |k,v| h[k] = v + 10 }
62
- assert( h == {:a=>20, :b=>30} )
63
- end
64
-
65
- #Unit :as_hash do
66
- # f0 = OpenObject[:f0=>"f0"]
67
- # h0 = { :h0=>"h0" }
68
- # assert{ OpenObject[:f0=>"f0", :h0=>"h0"] == f0.as_hash.merge(h0) }
69
- # assert{ {:f0=>"f0", :h0=>"h0"} == h0.merge(f0) }
70
- #end
71
-
72
- Unit :as_hash do
73
- f1 = OpenObject[:f1=>"f1"]
74
- h1 = { :h1=>"h1" }
75
- f1.as_hash.update(h1)
76
- h1.update(f1)
77
- assert{ f1 == OpenObject[:f1=>"f1", :h1=>"h1"] }
78
- assert{ h1 == {:f1=>"f1", :h1=>"h1"} }
79
- end
80
-
81
- Unit :<< => "passing a hash" do
82
- fo = OpenObject.new
83
- fo << {:a=>1,:b=>2}
84
- assert{ fo.to_h == {:a=>1, :b=>2} }
85
- end
86
-
87
- Unit :<< => "passing a pair" do
88
- fo = OpenObject.new
89
- fo << [:a, 1]
90
- fo << [:b, 2]
91
- assert( fo.to_h == {:a=>1, :b=>2} )
92
- end
93
-
94
- Unit :to_h do
95
- ho = {}
96
- fo = OpenObject.new
97
- 5.times{ |i| ho["n#{i}".to_sym] = 1 }
98
- 5.times{ |i| fo.__send__("n#{i}=", 1) }
99
- assert{ fo.to_h == ho }
100
- end
101
-
102
- Unit :to_h => "OpenObject within OpenObject" do
103
- o = OpenObject.new
104
- o.a = 10
105
- o.b = 20
106
- o.x = OpenObject.new
107
- o.x.a = 100
108
- o.x.b = 200
109
- o.x.c = 300
110
- assert{ o.to_h == {:a=>10, :b=>20, :x=>{:a=>100, :b=>200, :c=>300}} }
111
- end
112
-
113
- Unit :to_proc do
114
- p = lambda { |x| x.word = "Hello" }
115
- o = OpenObject[:a=>1,:b=>2]
116
- assert{ Proc === o.to_proc }
117
- end
118
-
119
- end
120
-
121
- TestCase Proc do
122
-
123
- Unit :to_openobject do
124
- p = lambda { |x| x.word = "Hello" }
125
- o = p.to_openobject
126
- assert{ o.word == "Hello" }
127
- end
128
-
129
- end
130
-
@@ -1,316 +0,0 @@
1
- require 'hashery/sparsearray'
2
- require 'ae/legacy'
3
-
4
- # This is a mostly complete testcase for SparseArray.
5
- # SparseArray is tested by comparison to standard Array.
6
-
7
- Case SparseArray do
8
-
9
- def aha(a)
10
- return a, SparseArray[*a]
11
- end
12
-
13
- Unit :to_ary do
14
- a, ha = aha [1,3,'a',8,nil,[1]]
15
- assert_equal(ha, ha.to_ary) # these need to be opposite
16
- end
17
-
18
- Unit :to_a do
19
- a, ha = aha [1,3,'a',8,nil,[1]]
20
- assert_equal(a, ha.to_a) #
21
- assert_equal(a.to_s, ha.to_s)
22
- end
23
-
24
- Unit :to_s do
25
- a, ha = aha [1,3,'a',8,nil,[1]]
26
- assert_equal(a.to_s, ha.to_s)
27
- end
28
-
29
- Unit :|, :&, :+, :- do
30
- a, ha = aha [1,3,5,8,9]
31
- b, hb = aha [2,3,6,8,9]
32
- assert_equal(a | b, (ha | hb).to_a)
33
- assert_equal(a & b, (ha & hb).to_a)
34
- assert_equal(a + b, (ha + hb).to_a)
35
- assert_equal(a - b, (ha - hb).to_a)
36
- end
37
-
38
- Unit :* do
39
- a, ha = aha [1,3]
40
- assert_equal(a*3,(ha*3).to_a)
41
- end
42
-
43
- Unit :[]= do
44
- a, ha = aha [1,2,3,4]
45
- a[1..2] = [8,9]
46
- ha[1..2] = [8,9]
47
- assert_equal(a, ha.to_a)
48
- end
49
-
50
- Unit :assoc do
51
- a, ha = aha [[1,2],[3,4],[3,6]]
52
- assert_equal(a.assoc(3), ha.assoc(3).to_a)
53
- end
54
-
55
- Unit :at do
56
- a, ha = aha [4,5,6,6]
57
- assert_equal(a.at(0), ha.at(0))
58
- assert_equal(a.at(2), ha.at(2))
59
- assert_equal(a.at(4), ha.at(4))
60
- assert_equal(a.at(9), ha.at(9))
61
- assert_equal(a.at(-1), ha.at(-1))
62
- assert_equal(a.at(-3), ha.at(-3))
63
- assert_equal(a.at(-4), ha.at(-4))
64
- assert_equal(a.at(-5), ha.at(-5))
65
- end
66
-
67
- Unit :collect do
68
- a, ha = aha [4,5,6,6]
69
- assert_equal(a.collect{|e|e}, ha.collect{|e|e}.to_a)
70
- assert_equal(a.collect!{|e|e}, ha.collect!{|e|e}.to_a)
71
- assert_equal(a,ha.to_a)
72
- end
73
-
74
- Unit :compact do
75
- a, ha = aha [4,nil,5,nil,6]
76
- assert_equal(a.compact, ha.compact.to_a)
77
- end
78
-
79
- Unit :concat do
80
- a, ha = aha [1,3,5,8,9]
81
- b, hb = aha [2,3,6,8,9]
82
- assert_equal(a.concat(b),ha.concat(hb).to_a)
83
- end
84
-
85
- Unit :count do
86
- ha = SparseArray[9,3,9,5,nil,nil,9,3]
87
- assert_equal(2,ha.count)
88
- assert_equal(2,ha.count(3))
89
- assert_equal(3,ha.count{|e|e==9})
90
- end
91
-
92
- Unit :delete do
93
- a, ha = aha [1,3,5,8,9,'a','b','c','c','d']
94
- # test delete
95
- assert_equal(a.delete(1),ha.delete(1))
96
- assert_equal(a,ha.to_a)
97
- assert_equal(a.delete('a'),ha.delete('a'))
98
- assert_equal(a,ha.to_a)
99
- # test delete_at
100
- assert_equal(a.delete_at(0),ha.delete_at(0))
101
- assert_equal(a,ha.to_a)
102
- # test delete_if
103
- assert_equal(a.delete_if{|v|v=='c'},ha.delete_if{|v|v=='c'}.to_a)
104
- assert_equal(a,ha.to_a)
105
- end
106
-
107
- Unit :each do
108
- a, ha = aha [4,'a',nil,'b']
109
- # test each
110
- ca, cha = '', ''
111
- a.each{|e| ca += e.to_s}
112
- ha.each{|e| cha += e.to_s}
113
- assert_equal(ca,cha)
114
- assert_equal(a,ha.to_a)
115
- # test each_index
116
- ca, cha = '', ''
117
- a.each_index{|i| ca += i.to_s}
118
- ha.each_index{|i| cha += i.to_s}
119
- assert_equal(ca,cha)
120
- assert_equal(a,ha.to_a)
121
- end
122
-
123
- Unit :eql? do
124
- a, ha = aha [4,'a',nil,'b']
125
- b, hb = aha [4,'a',nil,'b']
126
- assert_equal(a,b)
127
- assert_equal(ha,hb)
128
- assert_equal(a.eql?(b),ha.eql?(hb))
129
- assert_equal(b.eql?(a),hb.eql?(ha))
130
- assert(ha.eql?(hb))
131
- assert(hb.eql?(ha))
132
- end
133
-
134
- Unit :empty? do
135
- a, ha = aha []
136
- assert_equal(a.empty?,ha.empty?)
137
- a, ha = aha [1,2,3]
138
- assert_equal(a.empty?,ha.empty?)
139
- end
140
-
141
- Unit :fill do
142
- a, ha = aha ['a','b','c','d']
143
- assert_equal(a.fill('x'),ha.fill('x').to_a)
144
- assert_equal(a,ha.to_a)
145
- assert_equal(a.fill('y',2,2),ha.fill('y',2,2).to_a)
146
- assert_equal(a,ha.to_a)
147
- assert_equal(a.fill('z',0..1),ha.fill('z',0..1).to_a)
148
- assert_equal(a,ha.to_a)
149
- end
150
-
151
- Unit :first do
152
- a, ha = aha [2,3,4]
153
- assert_equal(a.first,ha.first)
154
- end
155
-
156
- Unit :flatten do
157
- a, ha = aha [2,[3],'a',[[1,2],4],nil,5]
158
- assert_equal(a.flatten,ha.flatten.to_a)
159
- a, ha = aha [2,[3],'a',[[1,2],4],nil,5]
160
- assert_equal(a.flatten!,ha.flatten!.to_a)
161
- assert_equal(a,ha.to_a)
162
- a, ha = aha [2,3,'a',nil,5]
163
- assert_equal(a.flatten!,ha.flatten!)
164
- end
165
-
166
- Unit :include? do
167
- a, ha = aha ['a','b','c','d']
168
- assert_equal(a.include?('b'),ha.include?('b'))
169
- assert_equal(a.include?('x'),ha.include?('x'))
170
- end
171
-
172
- Unit :index do
173
- a, ha = aha ['a','b','b','c','d']
174
- assert_equal(a.index('b'),ha.index('b'))
175
- assert_equal(a.index('x'),ha.index('x'))
176
- end
177
-
178
- Unit :join do
179
- a, ha = aha [2,3,4]
180
- assert_equal(a.join,ha.join)
181
- assert_equal(a.join(','),ha.join(','))
182
- end
183
-
184
- Unit :last do
185
- a, ha = aha [2,3,4]
186
- assert_equal(a.last,ha.last)
187
- end
188
-
189
- Unit :length do
190
- a, ha = aha [2,3,4]
191
- assert_equal(a.length,ha.length)
192
- end
193
-
194
- Unit :map! do
195
- a, ha = aha [4,5,6,6]
196
- assert_equal(a.map!{|e|e}, ha.map!{|e|e}.to_a)
197
- assert_equal(a,ha.to_a)
198
- end
199
-
200
- Unit :nitems do
201
- a, ha = aha [4,5,nil,6,nil]
202
- assert_equal(a.nitems, ha.nitems)
203
- end
204
-
205
- Unit :pop do
206
- a, ha = aha [4,5,nil,6,nil]
207
- assert_equal(a.pop, ha.pop)
208
- assert_equal(a, ha.to_a)
209
- assert_equal(a.pop, ha.pop)
210
- assert_equal(a, ha.to_a)
211
- end
212
-
213
- Unit :push do
214
- a, ha = aha [4,5,nil,6,nil]
215
- args = [1,2,3]
216
- assert_equal(a.push(*args), ha.push(*args).to_a)
217
- assert_equal(a, ha.to_a)
218
- end
219
-
220
- Unit :rassoc do
221
- a, ha = aha [[1,2],[1,3],[1,3]]
222
- assert_equal(a.rassoc(3), ha.rassoc(3).to_a)
223
- end
224
-
225
- Unit :reject! do
226
- a, ha = aha ['a','b','c','c','d']
227
- assert_equal(a.reject!{|v|v=='c'},ha.reject!{|v|v=='c'}.to_a)
228
- assert_equal(a,ha.to_a)
229
- assert_equal(a.reject!{|v|v=='x'},ha.reject!{|v|v=='x'})
230
- assert_equal(a,ha.to_a)
231
- end
232
-
233
- Unit :reverse do
234
- a, ha = aha ['a','b','c','c','d']
235
- assert_equal(a.reverse,ha.reverse.to_a)
236
- assert_equal(a.reverse!,ha.reverse!.to_a)
237
- assert_equal(a,ha.to_a)
238
- a, ha = aha [1,2,3,'a','b','c']
239
- assert_equal(a.reverse!,ha.reverse!.to_a)
240
- assert_equal(a,ha.to_a)
241
- end
242
-
243
- Unit :reverse_each do
244
- a, ha = aha [4,'a',nil,'b']
245
- # test each
246
- ca, cha = '', ''
247
- a.reverse_each{|e| ca += e.to_s}
248
- ha.reverse_each{|e| cha += e.to_s}
249
- assert_equal(ca,cha)
250
- assert_equal(a,ha.to_a)
251
- end
252
-
253
- Unit :rindex do
254
- a, ha = aha ['a','b','c','c','d']
255
- assert_equal(a.rindex('c'),ha.rindex('c'))
256
- assert_equal(a.rindex('x'),ha.rindex('x'))
257
- end
258
-
259
- Unit :shift do
260
- a, ha = aha ['a','b','c','c','d']
261
- assert_equal(a.shift,ha.shift)
262
- assert_equal(a,ha.to_a)
263
- end
264
-
265
- Unit :slice do
266
- a, ha = aha [1,2,3,4]
267
- # test []
268
- assert_equal(a[1], ha[1])
269
- assert_equal(a[1..2], ha[1..2].to_a)
270
- assert_equal(a[1...2], ha[1...2].to_a)
271
- assert_equal(a[1..7], ha[1..7].to_a)
272
- assert_equal(a[1,2], ha[1,2].to_a)
273
- # test slice
274
- assert_equal(a.slice(1), ha.slice(1))
275
- assert_equal(a.slice(1..2), ha.slice(1..2).to_a)
276
- assert_equal(a.slice(1...2), ha.slice(1...2).to_a)
277
- assert_equal(a.slice(1...2), ha.slice(1...2).to_a)
278
- assert_equal(a.slice(1,2), ha.slice(1,2).to_a)
279
- # test slice!
280
- assert_equal(a.slice!(1..2), ha.slice!(1..2).to_a)
281
- assert_equal(a, ha.to_a)
282
- end
283
-
284
- Unit :sort do
285
- a, ha = aha [1,2,3,4]
286
- # test sort
287
- assert_equal(a.sort, ha.sort.to_a)
288
- #assert_equal(a.sort{|x,y| y<=>x}, ha.sort{|x,y| y<=>x}.to_a)
289
- # test sort!
290
- assert_equal(a.sort!, ha.sort!.to_a)
291
- assert_equal(a, ha.to_a)
292
- end
293
-
294
- Unit :uniq do
295
- a, ha = aha [1,1,2,3,3,4,5,6,6]
296
- assert_equal(a.uniq, ha.uniq.to_a)
297
- end
298
-
299
- Unit :uniq! do
300
- a, ha = aha [1,1,2,3,3,4,5,6,6]
301
- a.uniq!; ha.uniq!
302
- assert_equal(a, ha.to_a)
303
- end
304
-
305
- Unit :values_at do
306
- a, ha = aha ['a','b','c','d']
307
- assert_equal(a.values_at(1,3),ha.values_at(1,3).to_a)
308
- end
309
-
310
- Unit :unshift do
311
- a, ha = aha ['a','b','c','c','d']
312
- assert_equal(a.unshift('x'),ha.unshift('x').to_a)
313
- assert_equal(a,ha.to_a)
314
- end
315
- end
316
-
@@ -1,131 +0,0 @@
1
- require 'hashery/stash'
2
-
3
- TestCase Stash do
4
-
5
- Unit :[] => 'class level fetch' do
6
- s = Stash[:a=>1, :b=>2]
7
- assert(s)
8
- end
9
-
10
- Unit :[] => 'instance level fetch' do
11
- s = Stash[:a=>1, :b=>2]
12
- s[:a].assert == 1
13
- s[:b].assert == 2
14
- s['a'].assert == 1
15
- s['b'].assert == 2
16
- end
17
-
18
- Unit :[]= => '' do
19
- s = Stash.new
20
- s[:a] = 1
21
- s[:b] = 2
22
- s[:a].assert == 1
23
- s[:b].assert == 2
24
- s['a'].assert == 1
25
- s['b'].assert == 2
26
- end
27
-
28
- Unit :initialize do
29
- s = Stash.new
30
- assert(s)
31
- end
32
-
33
- Unit :to_hash do
34
- s = Stash[:a=>1, :b=>2]
35
- s.to_hash.assert == {'a'=>1, 'b'=>2}
36
- end
37
-
38
- Unit :to_h do
39
- s = Stash[:a=>1, :b=>2]
40
- s.to_h.assert == {'a'=>1, 'b'=>2}
41
- end
42
-
43
- Unit :replace do
44
- s = Stash.new
45
- s.replace(:a=>1, :b=>2)
46
- s.to_h.assert == {'a'=>1, 'b'=>2}
47
- end
48
-
49
- Unit :delete do
50
- s = Stash[:a=>1, :b=>2]
51
- s.delete(:a)
52
- s.to_h.assert == {'b'=>2}
53
- end
54
-
55
- Unit :each do
56
- s = Stash[:a=>1, :b=>2]
57
- s.each do |k,v|
58
- String.assert === k
59
- end
60
- end
61
-
62
- Unit :store => '' do
63
- s = Stash.new
64
- s.store(:a, 1)
65
- s.to_h.assert == {'a'=>1}
66
- end
67
-
68
- Unit :update => '' do
69
- s1 = Stash[:a=>1,:b=>2]
70
- s2 = Stash[:c=>3,:d=>4]
71
- s1.update(s2)
72
- s1.to_h.assert == {'a'=>1,'b'=>2,'c'=>3,'d'=>4}
73
- end
74
-
75
- Unit :rekey => '' do
76
- s = Stash[:a=>1,:b=>2,:c=>3]
77
- x = s.rekey{ |k| k.upcase }
78
- x.to_h.assert == {'A'=>1,'B'=>2,'C'=>3}
79
- end
80
-
81
- Unit :rekey! => '' do
82
- s = Stash[:a=>1,:b=>2,:c=>3]
83
- s.rekey!{ |k| k.upcase }
84
- s.to_h.assert == {'A'=>1,'B'=>2,'C'=>3}
85
- end
86
-
87
- Unit :key? => '' do
88
- s = Stash[:a=>1]
89
- s.assert.key?(:a)
90
- s.assert.key?('a')
91
- end
92
-
93
- Unit :has_key? => '' do
94
- s = Stash[:a=>1]
95
- s.assert.has_key?(:a)
96
- s.assert.has_key?('a')
97
- end
98
-
99
- Unit :<< => '' do
100
- s = Stash.new
101
- s << [:a, 1]
102
- s << [:b, 2]
103
- s.to_h.assert == {'a'=>1, 'b'=>2}
104
- end
105
-
106
- Unit :merge! => '' do
107
- s1 = Stash[:a=>1,:b=>2]
108
- s2 = Stash[:c=>3,:d=>4]
109
- s1.merge!(s2)
110
- s1.to_h.assert == {'a'=>1,'b'=>2,'c'=>3,'d'=>4}
111
- end
112
-
113
- Unit :values_at => '' do
114
- s = Stash[:a=>1,:b=>2,:c=>3]
115
- s.values_at(:a, :b).assert == [1,2]
116
- s.values_at('a','b').assert == [1,2]
117
- end
118
-
119
- Unit :fetch => '' do
120
- s = Stash[:a=>1,:b=>2,:c=>3]
121
- s.fetch(:a).assert == 1
122
- s.fetch('a').assert == 1
123
- end
124
-
125
- Unit :convert_key => '' do
126
- s = Stash.new
127
- s.pry.convert_key(:a).assert == 'a'
128
- end
129
-
130
- end
131
-