Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/elixir/lib/range.ex
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,10 @@ defmodule Range do
defp normalize(first, last, step) when first > last,
do: {first - abs(div(first - last, step) * step), first, -step}

# A single-element range holds the same element regardless of the step, so
# make the step positive to keep the progression in disjoint?/2 increasing.
defp normalize(first, last, step) when first == last, do: {first, last, abs(step)}

defp normalize(first, last, step), do: {first, last, step}

@doc false
Expand Down
5 changes: 5 additions & 0 deletions lib/elixir/test/elixir/range_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ defmodule RangeTest do
assert_overlap(-7..-5, -5..-1)

assert Range.disjoint?(1..1, 1..1) == false

# Single-element ranges still contain their element regardless of the step
assert Range.disjoint?(1..1//-2, 1..1//-2) == false
assert Range.disjoint?(3..3//-3, 1..5) == false
assert Range.disjoint?(1..5, 3..3//-3) == false
end
end

Expand Down
Loading