mirror of
https://github.com/discourse/discourse.git
synced 2025-06-02 04:08:41 +08:00
DEV: followup to 8edd2b38cb to use existing spec (#11830)
This commit also better explains in spec why max_values might be off by one.
This commit is contained in:
@ -25,16 +25,19 @@ describe TimelineLookup do
|
|||||||
input = (1..100).map { |i| [1000 + i, 100 - i] }
|
input = (1..100).map { |i| [1000 + i, 100 - i] }
|
||||||
|
|
||||||
result = TimelineLookup.build(input, 5)
|
result = TimelineLookup.build(input, 5)
|
||||||
expect(result.size).to eq(5)
|
# even if max_value is 5 we might get 6 (5 + 1)
|
||||||
expect(result).to eq([[1, 99], [21, 79], [41, 59], [61, 39], [81, 19]])
|
# to ensure the last tuple is captured
|
||||||
|
expect(result).to eq([[1, 99], [21, 79], [41, 59], [61, 39], [81, 19], [input.size, input.last[1]]])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "respects an uneven `max_values` setting" do
|
it "respects an uneven `max_values` setting" do
|
||||||
input = (1..100).map { |i| [1000 + i, 100 - i] }
|
input = (1..100).map { |i| [1000 + i, 100 - i] }
|
||||||
|
|
||||||
result = TimelineLookup.build(input, 3)
|
result = TimelineLookup.build(input, 3)
|
||||||
expect(result.size).to eq(3)
|
# even if max_value is 3 we might get 4 (3 + 1)
|
||||||
expect(result).to eq([[1, 99], [35, 65], [69, 31]])
|
# to ensure the last tuple is captured
|
||||||
|
expect(result.size).to eq(4)
|
||||||
|
expect(result).to eq([[1, 99], [35, 65], [69, 31], [input.size, input.last[1]]])
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
describe TimelineLookup do
|
|
||||||
|
|
||||||
context '.build' do
|
|
||||||
it 'keeps the last tuple in the lookup' do
|
|
||||||
tuples = [
|
|
||||||
[7173, 400], [7174, 390], [7175, 380], [7176, 370], [7177, 1]
|
|
||||||
]
|
|
||||||
|
|
||||||
expect(TimelineLookup.build(tuples, 2)).to eq([[1, 400], [4, 370], [5, 1]])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
Reference in New Issue
Block a user