Commit 96e1bac3 authored by Alex Kalderimis's avatar Alex Kalderimis

Remove tests of private members

These are tested by their behavior
parent 66444cd3
...@@ -323,6 +323,14 @@ module RelativePositioning ...@@ -323,6 +323,14 @@ module RelativePositioning
end end
end end
def context(object, ignoring: nil)
return unless object
c = ItemContext.new(object, range)
c.ignoring = ignoring
c
end
private private
def gap_too_small?(pos_a, pos_b) def gap_too_small?(pos_a, pos_b)
...@@ -383,14 +391,6 @@ module RelativePositioning ...@@ -383,14 +391,6 @@ module RelativePositioning
end end
end end
def context(object, ignoring: nil)
return unless object
c = ItemContext.new(object, range)
c.ignoring = ignoring
c
end
# This method takes two integer values (positions) and # This method takes two integer values (positions) and
# calculates the position between them. The range is huge as # calculates the position between them. The range is huge as
# the maximum integer value is 2147483647. # the maximum integer value is 2147483647.
...@@ -463,7 +463,7 @@ module RelativePositioning ...@@ -463,7 +463,7 @@ module RelativePositioning
private private
# @api private # @api private
def gap_size(object, gaps:, at_end:, starting_from:) def gap_size(context, gaps:, at_end:, starting_from:)
total_width = IDEAL_DISTANCE * gaps total_width = IDEAL_DISTANCE * gaps
size = if at_end && starting_from + total_width >= MAX_POSITION size = if at_end && starting_from + total_width >= MAX_POSITION
(MAX_POSITION - starting_from) / gaps (MAX_POSITION - starting_from) / gaps
...@@ -473,23 +473,17 @@ module RelativePositioning ...@@ -473,23 +473,17 @@ module RelativePositioning
IDEAL_DISTANCE IDEAL_DISTANCE
end end
# Shift max elements leftwards if there isn't enough space
return [size, starting_from] if size >= MIN_GAP return [size, starting_from] if size >= MIN_GAP
order = at_end ? :desc : :asc
terminus = object
.send(:relative_siblings) # rubocop:disable GitlabSecurity/PublicSend
.where('relative_position IS NOT NULL')
.order(relative_position: order)
.first
if at_end if at_end
terminus.move_sequence_before(true) terminus = context.max_sibling
max_relative_position = terminus.reset.relative_position terminus.shift_left
max_relative_position = terminus.relative_position
[[(MAX_POSITION - max_relative_position) / gaps, IDEAL_DISTANCE].min, max_relative_position] [[(MAX_POSITION - max_relative_position) / gaps, IDEAL_DISTANCE].min, max_relative_position]
else else
terminus.move_sequence_after(true) terminus = min_sibling
min_relative_position = terminus.reset.relative_position terminus.shift_right
min_relative_position = terminus.relative_position
[[(min_relative_position - MIN_POSITION) / gaps, IDEAL_DISTANCE].min, min_relative_position] [[(min_relative_position - MIN_POSITION) / gaps, IDEAL_DISTANCE].min, min_relative_position]
end end
end end
...@@ -507,8 +501,10 @@ module RelativePositioning ...@@ -507,8 +501,10 @@ module RelativePositioning
objects = objects.reject(&:relative_position) objects = objects.reject(&:relative_position)
return 0 if objects.empty? return 0 if objects.empty?
representative = objects.first
number_of_gaps = objects.size # 1 to the nearest neighbour, and one between each number_of_gaps = objects.size # 1 to the nearest neighbour, and one between each
mover = Mover.new(START_POSITION, (MIN_POSITION..MAX_POSITION))
representative = mover.context(objects.first)
position = if at_end position = if at_end
representative.max_relative_position representative.max_relative_position
else else
......
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