2016-05-18 01:03:08 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
require_dependency 'timeline_lookup'
|
|
|
|
|
|
|
|
describe TimelineLookup do
|
|
|
|
it "returns an empty array for empty input" do
|
|
|
|
expect(TimelineLookup.build([])).to eq([])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the lookup for a series of posts" do
|
|
|
|
result = TimelineLookup.build([[111, 1, 10], [222, 2, 9], [333, 3, 8]])
|
|
|
|
expect(result).to eq([[1, 10], [2, 9], [3, 8]])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "omits duplicate dates" do
|
|
|
|
result = TimelineLookup.build([[111, 1, 10], [222, 2, 10], [333, 3, 8]])
|
|
|
|
expect(result).to eq([[1, 10], [3, 8]])
|
|
|
|
end
|
|
|
|
|
2016-05-27 00:49:54 +08:00
|
|
|
it "respects holes in the post numbers" do
|
|
|
|
result = TimelineLookup.build([[111, 1, 10], [222, 12, 10], [333, 30, 8]])
|
|
|
|
expect(result).to eq([[1, 10], [3, 8]])
|
|
|
|
end
|
|
|
|
|
2016-05-18 01:03:08 +08:00
|
|
|
it "respects a `max_values` setting" do
|
2017-07-28 09:20:09 +08:00
|
|
|
input = (1..100).map { |i| [1000 + i, i, 100 - i] }
|
2016-05-18 01:03:08 +08:00
|
|
|
|
|
|
|
result = TimelineLookup.build(input, 5)
|
|
|
|
expect(result.size).to eq(5)
|
|
|
|
expect(result).to eq([[1, 99], [21, 79], [41, 59], [61, 39], [81, 19]])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "respects an uneven `max_values` setting" do
|
2017-07-28 09:20:09 +08:00
|
|
|
input = (1..100).map { |i| [1000 + i, i, 100 - i] }
|
2016-05-18 01:03:08 +08:00
|
|
|
|
|
|
|
result = TimelineLookup.build(input, 3)
|
|
|
|
expect(result.size).to eq(3)
|
|
|
|
expect(result).to eq([[1, 99], [35, 65], [69, 31]])
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|