1 require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
3 describe IntervalSkipList do
4 it_should_behave_like "the palindromic fixture"
6 describe "#overlapping" do
7 it "returns intervals :d, :e, :f, and :g for 7..9" do
8 list.overlapping(7..9)[0].should have_markers(:d, :e, :f, :g)
11 it "returns intervals :b, :c, :d, :e, :f, and :g for 3..7" do
12 list.overlapping(3..7)[0].should have_markers(:b, :c, :d, :e, :f, :g )
15 it "returns intervals :b, :c, :d, :e, :f, and :g for 3..6" do
16 list.overlapping(3..6)[0].should have_markers(:b, :c, :d, :e, :f, :g )
19 describe ", when :x is inserted on 3..7" do
24 it "returns intervals :b, :c, :d, :e, :f, :x for 3..5" do
25 list.overlapping(3..5)[0].should have_markers(:b, :c, :d, :e, :f, :x)
31 describe "when 7..7 is expired with a length change of 0" do
37 attr_reader :nodes, :node
43 it "has a size of 4" do
44 nodes.size.should == 4
52 it "has a key of 1 and a height of 3" do
54 node.height.should == 3
57 it "has no forward markers at level 0" do
58 node.forward_markers[0].should be_empty
61 it "has :a and :b as its only forward markers on level 1" do
62 node.forward_markers[1].should have_markers(:a, :b)
65 it "has :c as its only forward marker on level 2" do
66 node.forward_markers[2].should have_markers(:c)
69 it "has no markers" do
70 node.markers.should be_empty
79 it "has a key of 3 and a height of 2" do
81 node.height.should == 2
84 it "has :b as its only forward marker on level 0" do
85 node.forward_markers[0].should have_markers(:b)
88 it "has no forward markers on level 1" do
89 node.forward_markers[1].should be_empty
92 it "has :a and :b as its only markers" do
93 node.markers.should have_markers(:a, :b)
102 it "has a key of 5 and a height of 1" do
104 node.height.should == 1
107 it "has no forward markers on level 0" do
108 node.forward_markers[0].should be_empty
111 it "has :b as its only marker" do
112 node.markers.should have_markers(:b)
121 it "has a key of 7 and a height of 3" do
123 node.height.should == 3
126 it "has no forward markers at any level" do
127 node.forward_markers[0].should be_empty
128 node.forward_markers[1].should be_empty
129 node.forward_markers[2].should be_empty
132 it "has :c as its only marker" do
133 node.markers.should have_markers(:c)
139 describe "when 4..4 is expired with a length change of 2" do
144 describe " #nodes" do
145 attr_reader :nodes, :node
151 it "has a size of 4" do
152 nodes.size.should == 4
160 it "has a key of 1 and a height of 3" do
162 node.height.should == 3
165 it "has no forward markers at level 0 and 2" do
166 node.forward_markers[0].should be_empty
167 node.forward_markers[2].should be_empty
170 it "has :a as its only forward marker on level 1" do
171 node.forward_markers[1].should have_markers(:a)
174 it "has no markers" do
175 node.markers.should be_empty
184 it "has a key of 3 and a height of 2" do
186 node.height.should == 2
189 it "has no forward markers at any level" do
190 node.forward_markers[0].should be_empty
191 node.forward_markers[1].should be_empty
194 it "has :a as its only marker" do
195 node.markers.should have_markers(:a)
204 it "has a key of 7 and a height of 1" do
206 node.height.should == 1
209 it "has :g as its only forward marker at level 0" do
210 node.forward_markers[0].should have_markers(:g)
213 it "has no markers" do
214 node.markers.should be_empty
223 it "has a key of 15 and a height of 3" do
224 node.key.should == 15
225 node.height.should == 3
228 it "has no forward markers at any level" do
229 node.forward_markers[0].should be_empty
230 node.forward_markers[1].should be_empty
231 node.forward_markers[2].should be_empty
234 it "has :g as its only marker" do
235 node.markers.should have_markers(:g)
241 describe "when :x is inserted on 1..5, :y on 7..11, and :z on 9..13" do
243 list.insert(1..5, :x)
244 list.insert(7..11, :y)
245 list.insert(9..13, :z)
248 describe "when 4..8 is expired with a length change of -3" do
250 list.expire(4..8, -3)
254 attr_reader :nodes, :node
259 it "has a size of 4" do
260 nodes.size.should == 4
268 it "has a key of 1 and height of 3" do
270 node.height.should == 3
273 it "has :a as its only forward marker on level 1" do
274 node.forward_markers[1].should have_markers(:a)
277 it "has no forward markers at level 0 and 2" do
278 node.forward_markers[0].should be_empty
279 node.forward_markers[2].should be_empty
282 it "has no markers" do
283 node.markers.should be_empty
292 it "has a key of 3 and height of 2" do
294 node.height.should == 2
297 it "has no forward markers" do
298 node.forward_markers[0].should be_empty
299 node.forward_markers[1].should be_empty
302 it "has :a as its only marker" do
303 node.markers.should have_markers(:a)
312 it "has a key of 6 and a height of 1" do
314 node.height.should == 1
317 it "has :z as its only forward marker at level 0" do
318 node.forward_markers[0].should have_markers(:z)
321 it "has no markers" do
322 node.markers.should be_empty
331 it "has a key of 10 and height of 3" do
332 node.key.should == 10
333 node.height.should == 3
336 it "has no forward markers at any level" do
337 node.forward_markers[0].should be_empty
338 node.forward_markers[1].should be_empty
339 node.forward_markers[2].should be_empty
342 it "has :z as its only marker" do
343 node.markers.should have_markers(:z)