native_btree 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -156,18 +156,6 @@ RSpec.describe NativeBtree do
156
156
  end
157
157
  end
158
158
 
159
- describe "#filter method" do
160
- xit "respond to" do
161
- expect(described_cless.respond_to?(:filter)).to be true
162
- end
163
- end
164
-
165
- describe "#filter! method" do
166
- xit "respond to" do
167
- expect(described_cless.respond_to?(:filter!)).to be true
168
- end
169
- end
170
-
171
159
  describe "#include? method" do
172
160
  it "respond to" do
173
161
  expect(tree).to respond_to(:include?)
@@ -184,99 +172,18 @@ RSpec.describe NativeBtree do
184
172
  end
185
173
  end
186
174
 
187
- describe "to_ methods" do
188
- describe "#to_a" do
189
- it "respond to" do
190
- expect(tree).to respond_to(:to_a)
191
- end
192
-
193
- it 'return Array' do
194
- expect(tree.to_a).to be_kind_of(Array)
195
- end
196
-
197
- it 'has similar items' do
198
- tree[2] = 22
199
- tree[1] = 11
200
- expect(tree.to_a()[0][1]).to be 11
201
- end
175
+ describe "#empty? method" do
176
+ it 'respond to' do
177
+ expect(tree).to respond_to(:empty?)
202
178
  end
203
179
 
204
- describe "#to_h" do
205
- it "respond to" do
206
- expect(tree).to respond_to(:to_h)
207
- end
208
-
209
- it "return Hash" do
210
- expect(tree.to_h).to be_kind_of(Hash)
211
- end
212
-
213
- it 'has similar keys' do
214
- tree[2] = 22
215
- tree[1] = 11
216
- expect(tree.to_h()[1]).to be 11
217
- end
218
- end
219
- end
220
-
221
- describe "#each method" do
222
- it "respond to" do
223
- expect(tree).to respond_to(:each)
224
- end
225
-
226
- it 'yield in to block value first' do
227
- tree[2] = 22
228
-
229
- value = nil
230
- tree.each { |v| value = v }
231
-
232
- expect(value).to be 22
233
- end
234
-
235
- it 'yield in to block key second' do
236
- tree[2] = 22
237
-
238
- key = nil
239
- tree.each { |_v, k| key = k }
240
-
241
- expect(key).to be 2
242
- end
243
-
244
- it 'yield ordered keys' do
245
- tree[16] = 16
246
- tree[0] = 0
247
- tree[5] = 5
248
- tree[-4] = -4
249
- tree[7] = 7
250
-
251
- check = [-4, 0, 5, 7, 16]
252
- result = []
253
- tree.each { |value| result << value }
254
-
255
- expect(result).to eq(check)
256
- end
257
- end
258
-
259
- describe "#each_key method" do
260
- xit "respond to" do
261
- expect(described_cless.respond_to?(:each_key)).to be true
262
- end
263
- end
264
-
265
- describe "#each_value method" do
266
- xit "respond to" do
267
- expect(described_cless.respond_to?(:each_value)).to be true
268
- end
269
- end
270
-
271
- describe "#select method" do
272
- xit "respond to" do
273
- expect(described_cless.respond_to?(:select)).to be true
180
+ it 'return false if nodes exists' do
181
+ tree[3] = 33
182
+ expect(tree.empty?).to be false
274
183
  end
275
- end
276
184
 
277
- describe "#select! method" do
278
- xit "respond to" do
279
- expect(described_cless.respond_to?(:select!)).to be true
185
+ it 'return true if nodes not exists' do
186
+ expect(tree.empty?).to be true
280
187
  end
281
188
  end
282
189
  end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe NativeBtree do
4
+
5
+ describe NativeBtree::Btree do
6
+ let(:tree) do
7
+ described_class.new do |a, b|
8
+ a - b
9
+ end
10
+ end
11
+
12
+ describe "#each method" do
13
+ it "respond to" do
14
+ expect(tree).to respond_to(:each)
15
+ end
16
+
17
+ it 'yield in to block value first' do
18
+ tree[2] = 22
19
+
20
+ value = nil
21
+ tree.each { |v| value = v }
22
+
23
+ expect(value).to be 22
24
+ end
25
+
26
+ it 'yield in to block key second' do
27
+ tree[2] = 22
28
+
29
+ key = nil
30
+ tree.each { |_v, k| key = k }
31
+
32
+ expect(key).to be 2
33
+ end
34
+
35
+ it 'yield ordered keys' do
36
+ tree[16] = 16
37
+ tree[0] = 0
38
+ tree[5] = 5
39
+ tree[-4] = -4
40
+ tree[7] = 7
41
+
42
+ check = [-4, 0, 5, 7, 16]
43
+ result = []
44
+ tree.each { |value| result << value }
45
+
46
+ expect(result).to eq(check)
47
+ end
48
+ end
49
+
50
+ describe "#each_key method" do
51
+ xit "respond to" do
52
+ expect(described_cless.respond_to?(:each_key)).to be true
53
+ end
54
+ end
55
+
56
+ describe "#each_value method" do
57
+ xit "respond to" do
58
+ expect(described_cless.respond_to?(:each_value)).to be true
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe NativeBtree do
4
+
5
+ describe NativeBtree::Btree do
6
+ let(:tree) do
7
+ described_class.new do |a, b|
8
+ a - b
9
+ end
10
+ end
11
+
12
+ describe "#filter method" do
13
+ it "respond to" do
14
+ expect(tree).to respond_to(:filter)
15
+ end
16
+
17
+ it 'raise error if block not given' do
18
+ expect { tree.filter() }.to raise_error(LocalJumpError)
19
+ end
20
+
21
+ it 'return Btree instance' do
22
+ expect(tree.filter() { nil }).to be_kind_of(described_class)
23
+ end
24
+
25
+ it 'filter tree by values' do
26
+ tree[1] = 11
27
+ tree[5] = 90
28
+ tree[2] = 32
29
+ tree[100] = 15
30
+ tree[46] = 8
31
+
32
+ expect(tree.filter { |v| v > 20 }.to_a).to match_array([[2, 32], [5, 90]])
33
+ end
34
+
35
+ it 'filter tree by keys' do
36
+ tree[1] = 11
37
+ tree[5] = 90
38
+ tree[2] = 32
39
+ tree[100] = 15
40
+ tree[46] = 8
41
+
42
+ expect(tree.filter { |_v, k| k > 20 }.to_a).to match_array([[46, 8], [100, 15]])
43
+ end
44
+
45
+ it 'return new object' do
46
+ tree[1] = 11
47
+ tree[5] = 90
48
+ tree[2] = 32
49
+ tree[100] = 15
50
+ tree[46] = 8
51
+
52
+ result = tree.filter { |_v, k| k > 20 }
53
+
54
+ expect(tree.equal?(result)).to be false
55
+ end
56
+
57
+ end
58
+
59
+ describe "#filter! method" do
60
+ it "respond to" do
61
+ expect(tree).to respond_to(:filter!)
62
+ end
63
+
64
+ it 'raise error if block not given' do
65
+ expect { tree.filter!() }.to raise_error(LocalJumpError)
66
+ end
67
+
68
+ it 'return Btree instance' do
69
+ expect(tree.filter!() { nil }).to be_kind_of(described_class)
70
+ end
71
+
72
+ it 'return origin tree' do
73
+ tree[1] = 11
74
+ tree[5] = 90
75
+ tree[2] = 32
76
+ tree[100] = 15
77
+ tree[46] = 8
78
+
79
+ result = tree.filter! { |_v, k| k > 20 }
80
+
81
+ expect(tree.equal?(result)).to be true
82
+ end
83
+
84
+ it 'filter tree by values' do
85
+ tree[1] = 11
86
+ tree[5] = 90
87
+ tree[2] = 32
88
+ tree[100] = 15
89
+ tree[46] = 8
90
+
91
+ expect(tree.filter! { |v| v > 20 }.to_a).to match_array([[2, 32], [5, 90]])
92
+ end
93
+
94
+ it 'filter tree by keys' do
95
+ tree[1] = 11
96
+ tree[5] = 90
97
+ tree[2] = 32
98
+ tree[100] = 15
99
+ tree[46] = 8
100
+
101
+ expect(tree.filter! { |_v, k| k > 20 }.to_a).to match_array([[46, 8], [100, 15]])
102
+ end
103
+
104
+ end
105
+
106
+ describe "#select method" do
107
+ it "respond to" do
108
+ expect(tree).to respond_to(:select)
109
+ end
110
+ end
111
+
112
+ describe "#select! method" do
113
+ it "respond to" do
114
+ expect(tree).to respond_to(:select!)
115
+ end
116
+ end
117
+ end
118
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: native_btree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Feodorov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-07 00:00:00.000000000 Z
11
+ date: 2022-09-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby bindings to GTree balanced binary tree from GLib library.
14
14
  email:
@@ -25,17 +25,12 @@ files:
25
25
  - README.md
26
26
  - Rakefile
27
27
  - ext/native_btree/CMakeLists.txt
28
- - ext/native_btree/Makefile
29
28
  - ext/native_btree/comparator.c
30
29
  - ext/native_btree/constructor.c
31
30
  - ext/native_btree/conversion.c
32
31
  - ext/native_btree/extconf_cmake.rb
33
- - ext/native_btree/include/btree.h
34
32
  - ext/native_btree/include/common.h
35
33
  - ext/native_btree/include/comparator.h
36
- - ext/native_btree/include/constructor.h
37
- - ext/native_btree/include/conversion.h
38
- - ext/native_btree/include/instance.h
39
34
  - ext/native_btree/include/iterators.h
40
35
  - ext/native_btree/include/native_btree.h
41
36
  - ext/native_btree/include/rbtree_type.h
@@ -43,14 +38,18 @@ files:
43
38
  - ext/native_btree/iterators.c
44
39
  - ext/native_btree/native_btree.c
45
40
  - ext/native_btree/rbtree_type.c
41
+ - ext/native_btree/search.c
46
42
  - lib/native_btree.rb
47
- - lib/native_btree/native_btree.so
43
+ - lib/native_btree/native_btree.bundle
48
44
  - lib/native_btree/version.rb
49
45
  - native_btree.gemspec
50
46
  - spec/debug.rb
51
47
  - spec/native_btree_class_spec.rb
48
+ - spec/native_btree_conversion_spec.rb
52
49
  - spec/native_btree_instance_spec.rb
50
+ - spec/native_btree_iterators_spec.rb
53
51
  - spec/native_btree_module_spec.rb
52
+ - spec/native_btree_search_spec.rb
54
53
  - spec/spec_helper.rb
55
54
  homepage: https://github.com/unixs/ruby-native-btree
56
55
  licenses: