2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-12-05 04:56:09 +08:00
|
|
|
require 'cache'
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe Gaps do
|
2013-12-05 04:56:09 +08:00
|
|
|
it 'returns no gaps for empty data' do
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(Gaps.new(nil, nil)).to be_blank
|
2013-12-05 04:56:09 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns no gaps with one element' do
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(Gaps.new([1], [1])).to be_blank
|
2013-12-05 04:56:09 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns no gaps when all elements are present' do
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(Gaps.new([1, 2, 3], [1, 2, 3])).to be_blank
|
2013-12-05 04:56:09 +08:00
|
|
|
end
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
describe "single element gap" do
|
2013-12-05 04:56:09 +08:00
|
|
|
let(:gap) { Gaps.new([1, 3], [1, 2, 3]) }
|
|
|
|
|
|
|
|
it 'has a gap for post 3' do
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(gap).not_to be_blank
|
|
|
|
expect(gap.before[3]).to eq([2])
|
|
|
|
expect(gap.after).to be_blank
|
2013-12-05 04:56:09 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
describe "larger gap" do
|
2013-12-05 04:56:09 +08:00
|
|
|
let(:gap) { Gaps.new([1, 2, 3, 6, 7], [1, 2, 3, 4, 5, 6, 7]) }
|
|
|
|
|
|
|
|
it 'has a gap for post 6' do
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(gap).not_to be_blank
|
|
|
|
expect(gap.before[6]).to eq([4, 5])
|
|
|
|
expect(gap.after).to be_blank
|
2013-12-05 04:56:09 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
describe "multiple gaps" do
|
2013-12-05 04:56:09 +08:00
|
|
|
let(:gap) { Gaps.new([1, 5, 6, 7, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) }
|
|
|
|
|
|
|
|
it 'has both gaps' do
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(gap).not_to be_blank
|
|
|
|
expect(gap.before[5]).to eq([2, 3, 4])
|
|
|
|
expect(gap.before[10]).to eq([8, 9])
|
|
|
|
expect(gap.after).to be_blank
|
2013-12-05 04:56:09 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
describe "a gap in the beginning" do
|
2013-12-05 04:56:09 +08:00
|
|
|
let(:gap) { Gaps.new([2, 3, 4], [1, 2, 3, 4]) }
|
|
|
|
|
|
|
|
it 'has the gap' do
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(gap).not_to be_blank
|
|
|
|
expect(gap.before[2]).to eq([1])
|
|
|
|
expect(gap.after).to be_blank
|
2013-12-05 04:56:09 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
describe "a gap in the ending" do
|
2013-12-05 04:56:09 +08:00
|
|
|
let(:gap) { Gaps.new([1, 2, 3], [1, 2, 3, 4]) }
|
|
|
|
|
|
|
|
it 'has the gap' do
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(gap).not_to be_blank
|
|
|
|
expect(gap.before).to be_blank
|
|
|
|
expect(gap.after[3]).to eq([4])
|
2013-12-05 04:56:09 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
describe "a large gap in the ending" do
|
2013-12-05 04:56:09 +08:00
|
|
|
let(:gap) { Gaps.new([1, 2, 3], [1, 2, 3, 4, 5, 6]) }
|
|
|
|
|
|
|
|
it 'has the gap' do
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(gap).not_to be_blank
|
|
|
|
expect(gap.before).to be_blank
|
|
|
|
expect(gap.after[3]).to eq([4, 5, 6])
|
2013-12-05 04:56:09 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|