Skip to content

Commit

Permalink
Fix allunique(::StepRangeLen)
Browse files Browse the repository at this point in the history
  • Loading branch information
sostock committed Jul 30, 2020
1 parent 7f348c5 commit 4d215e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 1 addition & 3 deletions base/set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,7 @@ end

allunique(::Union{AbstractSet,AbstractDict}) = true

allunique(r::AbstractRange{T}) where {T} = (step(r) != zero(T)) || (length(r) <= 1)
allunique(r::StepRange{T,S}) where {T,S} = (step(r) != zero(S)) || (length(r) <= 1)
allunique(r::StepRangeLen{T,R,S}) where {T,R,S} = (step(r) != zero(S)) || (length(r) <= 1)
allunique(r::AbstractRange) = !iszero(step(r)) || length(r) <= 1

filter!(f, s::Set) = unsafe_filter!(f, s)

Expand Down
7 changes: 7 additions & 0 deletions test/sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,13 @@ end
@test allunique(Date(2018, 8, 7):Day(1):Date(2018, 8, 11)) # JuliaCon 2018
@test allunique(DateTime(2018, 8, 7):Hour(1):DateTime(2018, 8, 11))
@test allunique(('a':1:'c')[1:2]) == true
for r = (Base.OneTo(-1), Base.OneTo(0), Base.OneTo(1), Base.OneTo(5),
1:0, 1:1, 1:2, 1:10, 1:.5:.5, 1:.5:1, 1:.5:10, 3:-2:5, 3:-2:3, 3:-2:1,
StepRangeLen(1.0, 2.0, 0), StepRangeLen(1.0, 2.0, 2), StepRangeLen(1.0, 2.0, 3),
StepRangeLen(1.0, 0.0, 0), StepRangeLen(1.0, -0.0, 1), StepRangeLen(1.0, 0.0, 2),
LinRange(1, 2, 3), LinRange(1, 1, 0), LinRange(1, 1, 1), LinRange(1, 1, 10))
@test allunique(r) == invoke(allunique, Tuple{Any}, r)
end
end
@testset "filter(f, ::$S)" for S = (Set, BitSet)
s = S([1,2,3,4])
Expand Down

0 comments on commit 4d215e4

Please sign in to comment.