Commit 9c9142d6 authored by Alex Kalderimis's avatar Alex Kalderimis

Fix a serious bug in midpoint placement

This only compared using `==` which means that we misidentify a lot of
open-ranges when calculating `move_to_end`/`move_to_start`.
parent 77c218a4
...@@ -83,9 +83,9 @@ module RelativePositioning ...@@ -83,9 +83,9 @@ module RelativePositioning
if gap_width < MIN_GAP if gap_width < MIN_GAP
raise NoSpaceLeft raise NoSpaceLeft
elsif gap_width > MAX_GAP elsif gap_width > MAX_GAP
if pos_before == MIN_POSITION if pos_before <= MIN_POSITION
pos_after - IDEAL_DISTANCE pos_after - IDEAL_DISTANCE
elsif pos_after == MAX_POSITION elsif pos_after >= MAX_POSITION
pos_before + IDEAL_DISTANCE pos_before + IDEAL_DISTANCE
else else
midpoint midpoint
......
...@@ -568,6 +568,12 @@ RSpec.shared_examples 'a class that supports relative positioning' do ...@@ -568,6 +568,12 @@ RSpec.shared_examples 'a class that supports relative positioning' do
end end
end end
it 'places items at most IDEAL_DISTANCE from the start when the range is open' do
n = item1.send(:scoped_items).count
expect([item1, item2].map(&:relative_position)).to all(be >= (RelativePositioning::START_POSITION - (n * RelativePositioning::IDEAL_DISTANCE)))
end
it 'moves item to the end' do it 'moves item to the end' do
new_item.move_to_start new_item.move_to_start
...@@ -613,6 +619,12 @@ RSpec.shared_examples 'a class that supports relative positioning' do ...@@ -613,6 +619,12 @@ RSpec.shared_examples 'a class that supports relative positioning' do
end end
end end
it 'places items at most IDEAL_DISTANCE from the start when the range is open' do
n = item1.send(:scoped_items).count
expect([item1, item2].map(&:relative_position)).to all(be <= (RelativePositioning::START_POSITION + (n * RelativePositioning::IDEAL_DISTANCE)))
end
it 'moves item to the end' do it 'moves item to the end' do
new_item.move_to_end new_item.move_to_end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment