itree 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/itree/tree.rb +2 -2
- data/lib/itree/version.rb +1 -1
- data/spec/tree_spec.rb +44 -9
- metadata +2 -2
data/lib/itree/tree.rb
CHANGED
@@ -227,7 +227,7 @@ module Intervals
|
|
227
227
|
elsif diff > 0
|
228
228
|
if locNode.left
|
229
229
|
heightDelta,removed = removeNode(locNode.left,delNode)
|
230
|
-
if heightDelta
|
230
|
+
if heightDelta != 0
|
231
231
|
locNode.balance = locNode.balance + 1
|
232
232
|
if locNode.balance == 0
|
233
233
|
return -1,removed
|
@@ -273,7 +273,7 @@ module Intervals
|
|
273
273
|
elsif diff < 0
|
274
274
|
if locNode.right
|
275
275
|
heightDelta,removed = removeNode(locNode.right,delNode)
|
276
|
-
if heightDelta
|
276
|
+
if heightDelta != 0
|
277
277
|
locNode.balance = locNode.balance - 1
|
278
278
|
if locNode.balance == 0
|
279
279
|
return 1,removed
|
data/lib/itree/version.rb
CHANGED
data/spec/tree_spec.rb
CHANGED
@@ -139,7 +139,46 @@ describe Intervals::Tree do
|
|
139
139
|
tree.insert(51,101)
|
140
140
|
end
|
141
141
|
|
142
|
+
it { tree.remove(0,25).should be true }
|
143
|
+
it { tree.remove(0,24).should be false }
|
144
|
+
|
145
|
+
context "two ranges removed" do
|
146
|
+
before(:each) do
|
147
|
+
tree.remove(100,200)
|
148
|
+
tree.remove(50,100)
|
149
|
+
end
|
142
150
|
|
151
|
+
it { tree.stab(23).length.should eq 1 }
|
152
|
+
it "returns a single range" do
|
153
|
+
results = tree.stab(23).map{|n| n.scores }.sort{|a,b| a[0] <=> b[0]}
|
154
|
+
results[0].should eq [0,25]
|
155
|
+
end
|
156
|
+
|
157
|
+
it { tree.stab(40).length.should eq 1 }
|
158
|
+
it "returns a single range" do
|
159
|
+
results = tree.stab(40).map{|n| n.scores }.sort{|a,b| a[0] <=> b[0]}
|
160
|
+
results[0].should eq [25,50]
|
161
|
+
end
|
162
|
+
|
163
|
+
it { tree.stab(77).length.should eq 2 }
|
164
|
+
it "returns two ranges" do
|
165
|
+
results = tree.stab(77).map{|n| n.scores }.sort{|a,b| a[0] <=> b[0]}
|
166
|
+
results[0].should eq [51,101]
|
167
|
+
results[1].should eq [75,125]
|
168
|
+
end
|
169
|
+
|
170
|
+
it { tree.stab(175).length.should eq 1 }
|
171
|
+
it "returns a single range" do
|
172
|
+
results = tree.stab(175).map{|n| n.scores }.sort{|a,b| a[0] <=> b[0]}
|
173
|
+
results[0].should eq [150,250]
|
174
|
+
end
|
175
|
+
|
176
|
+
it { tree.stab(350).length.should eq 1 }
|
177
|
+
it "returns a single range" do
|
178
|
+
results = tree.stab(350).map{|n| n.scores }.sort{|a,b| a[0] <=> b[0]}
|
179
|
+
results[0].should eq [300,400]
|
180
|
+
end
|
181
|
+
end
|
143
182
|
end
|
144
183
|
|
145
184
|
describe "#stab" do
|
@@ -153,13 +192,8 @@ describe Intervals::Tree do
|
|
153
192
|
tree.insert(75,125)
|
154
193
|
tree.insert(25,50)
|
155
194
|
tree.insert(0,25)
|
156
|
-
tree.insert(51,101)
|
157
|
-
tree.remove(100,200)
|
158
|
-
tree.remove(50,100)
|
159
195
|
end
|
160
196
|
|
161
|
-
it { tree.remove(0,25).should be true }
|
162
|
-
it { tree.remove(0,24).should be false }
|
163
197
|
|
164
198
|
it { tree.stab(23).length.should eq 1 }
|
165
199
|
it "returns a single range" do
|
@@ -176,14 +210,15 @@ describe Intervals::Tree do
|
|
176
210
|
it { tree.stab(77).length.should eq 2 }
|
177
211
|
it "returns two ranges" do
|
178
212
|
results = tree.stab(77).map{|n| n.scores }.sort{|a,b| a[0] <=> b[0]}
|
179
|
-
results[0].should eq [
|
213
|
+
results[0].should eq [50,100]
|
180
214
|
results[1].should eq [75,125]
|
181
215
|
end
|
182
216
|
|
183
|
-
it { tree.stab(175).length.should eq
|
184
|
-
it "returns a
|
217
|
+
it { tree.stab(175).length.should eq 2 }
|
218
|
+
it "returns a two ranges" do
|
185
219
|
results = tree.stab(175).map{|n| n.scores }.sort{|a,b| a[0] <=> b[0]}
|
186
|
-
results[0].should eq [
|
220
|
+
results[0].should eq [100,200]
|
221
|
+
results[1].should eq [150,250]
|
187
222
|
end
|
188
223
|
|
189
224
|
it { tree.stab(350).length.should eq 1 }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|