Skip to content

Commit

Permalink
REQUIRE -> Project.toml (#53)
Browse files Browse the repository at this point in the history
* REQUIRE -> Project.toml

* Increase coverage

* More coverage
  • Loading branch information
dlfivefifty authored Aug 8, 2019
1 parent 9e277b2 commit ecf4377
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.jl.cov
*.jl.*.cov
*.jl.mem
.DS_Store
16 changes: 16 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name = "IntervalSets"
uuid = "8197267c-284f-5f27-9208-e0e47529a953"
version = "0.3.2"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
julia = "0.7, 1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
1 change: 0 additions & 1 deletion REQUIRE

This file was deleted.

2 changes: 2 additions & 0 deletions src/IntervalSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ isrightclosed(d::TypedEndpointsInterval{L,:open}) where {L} = false
# The third is the one we want, but the first two are needed to resolve ambiguities
Base.Slice{T}(i::TypedEndpointsInterval{:closed,:closed,I}) where {T<:AbstractUnitRange,I<:Integer} =
Base.Slice{T}(minimum(i):maximum(i))
Base.Slice(i::TypedEndpointsInterval{:closed,:closed,I}) where I<:Integer =
Base.Slice(minimum(i):maximum(i))
function Base.OneTo{T}(i::TypedEndpointsInterval{:closed,:closed,I}) where {T<:Integer,I<:Integer}
@noinline throwstart(i) = throw(ArgumentError("smallest element must be 1, got $(minimum(i))"))
minimum(i) == 1 || throwstart(i)
Expand Down
74 changes: 59 additions & 15 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import IntervalSets: Domain, endpoints, closedendpoints, TypedEndpointsInterval

struct MyClosedUnitInterval <: TypedEndpointsInterval{:closed,:closed,Int} end
endpoints(::MyClosedUnitInterval) = (0,1)
Base.promote_rule(::Type{MyClosedUnitInterval}, ::Type{ClosedInterval{T}}) where T =
ClosedInterval{T}

struct MyUnitInterval <: AbstractInterval{Int}
isleftclosed::Bool
Expand All @@ -16,6 +18,8 @@ end
endpoints(::MyUnitInterval) = (0,1)
closedendpoints(I::MyUnitInterval) = (I.isleftclosed,I.isrightclosed)

struct IncompleteInterval <: AbstractInterval{Int} end

@testset "IntervalSets" begin
@test isempty(detect_ambiguities(IntervalSets, Base, Core))

Expand Down Expand Up @@ -59,6 +63,8 @@ closedendpoints(I::MyUnitInterval) = (I.isleftclosed,I.isrightclosed)

@test typeof(leftendpoint(M)) == typeof(rightendpoint(M)) && typeof(leftendpoint(M)) == Float64
@test typeof(leftendpoint(N)) == typeof(rightendpoint(N)) && typeof(leftendpoint(N)) == Int
@test @inferred(endpoints(M)) === (2.0,5.0)
@test @inferred(endpoints(N)) === (255,300)

@test maximum(I) === 3
@test minimum(I) === 0
Expand Down Expand Up @@ -117,6 +123,7 @@ closedendpoints(I::MyUnitInterval) = (I.isleftclosed,I.isrightclosed)

@test promote(1..2, 1.0..2.0) === (1.0..2.0, 1.0..2.0)

@test duration(1..2) == 2
# duration deliberately not defined for non-integer intervals
@test_throws MethodError duration(1.2..2.4)
end
Expand All @@ -135,13 +142,18 @@ closedendpoints(I::MyUnitInterval) = (I.isleftclosed,I.isrightclosed)
@test @inferred(convert(ClosedInterval{Float64}, I)) ===
@inferred(convert(AbstractInterval{Float64}, I)) ===
@inferred(convert(Domain{Float64}, I)) ===
@inferred(ClosedInterval{Float64}(I)) === 0.0..3.0
@inferred(ClosedInterval{Float64}(I)) ===
@inferred(convert(TypedEndpointsInterval{:closed,:closed,Float64},I)) ===
0.0..3.0
@test @inferred(convert(ClosedInterval, I)) ===
@inferred(convert(Interval, I)) ===
@inferred(ClosedInterval(I)) ===
@inferred(Interval(I)) ===
@inferred(convert(AbstractInterval, I)) ===
@inferred(convert(Domain, I)) === I
@inferred(convert(Domain, I)) ===
@inferred(convert(TypedEndpointsInterval{:closed,:closed}, I)) ===
@inferred(convert(TypedEndpointsInterval{:closed,:closed,Int}, I)) ===
@inferred(convert(ClosedInterval{Int}, I)) === I
@test_throws InexactError convert(OpenInterval, I)
@test_throws InexactError convert(Interval{:open,:closed}, I)
@test_throws InexactError convert(Interval{:closed,:open}, I)
Expand All @@ -159,7 +171,9 @@ closedendpoints(I::MyUnitInterval) = (I.isleftclosed,I.isrightclosed)
@inferred(convert(Interval, J)) ===
@inferred(convert(AbstractInterval, J)) ===
@inferred(convert(Domain, J)) ===
@inferred(OpenInterval(J)) === OpenInterval(J)
@inferred(OpenInterval(J)) ===
@inferred(OpenInterval{Int}(J)) ===
@inferred(convert(OpenInterval{Int},J)) === OpenInterval(J)
J = Interval{:open,:closed}(I)
@test_throws InexactError convert(Interval{:closed,:open}, J)
@test @inferred(convert(Interval{:open,:closed,Float64}, J)) ===
Expand Down Expand Up @@ -194,6 +208,8 @@ closedendpoints(I::MyUnitInterval) = (I.isleftclosed,I.isrightclosed)
convert(ClosedInterval{Float64}, 1) ==
1.0..1.0

@test promote_type(Interval{:closed,:open,Float64}, Interval{:closed,:open,Int}) ===
Interval{:closed,:open,Float64}
end


Expand Down Expand Up @@ -226,6 +242,10 @@ closedendpoints(I::MyUnitInterval) = (I.isleftclosed,I.isrightclosed)

@test IntervalSets.isclosed(d)
@test !IntervalSets.isopen(d)
@test IntervalSets.isleftclosed(d)
@test !IntervalSets.isleftopen(d)
@test !IntervalSets.isrightopen(d)
@test IntervalSets.isrightclosed(d)

@test convert(AbstractInterval, d) d
@test convert(AbstractInterval{T}, d) d
Expand All @@ -235,6 +255,12 @@ closedendpoints(I::MyUnitInterval) = (I.isleftclosed,I.isrightclosed)
d = OpenInterval(zero(T) .. one(T))
@test IntervalSets.isopen(d)
@test !IntervalSets.isclosed(d)
@test IntervalSets.isopen(d)
@test !IntervalSets.isclosed(d)
@test !IntervalSets.isleftclosed(d)
@test IntervalSets.isleftopen(d)
@test IntervalSets.isrightopen(d)
@test !IntervalSets.isrightclosed(d)
@test leftendpoint(d) d
@test BigFloat(leftendpoint(d)) d
@test nextfloat(leftendpoint(d)) d
Expand All @@ -257,45 +283,50 @@ closedendpoints(I::MyUnitInterval) = (I.isleftclosed,I.isrightclosed)
d = Interval{:open,:closed}(zero(T) .. one(T))
@test !IntervalSets.isopen(d)
@test !IntervalSets.isclosed(d)
@test !IntervalSets.isleftclosed(d)
@test IntervalSets.isleftopen(d)
@test !IntervalSets.isrightopen(d)
@test IntervalSets.isrightclosed(d)
@test leftendpoint(d) d
@test BigFloat(leftendpoint(d)) d
@test nextfloat(leftendpoint(d)) d
@test nextfloat(BigFloat(leftendpoint(d))) d
@test prevfloat(leftendpoint(d)) d
@test prevfloat(leftendpoint(d)) d
@test prevfloat(BigFloat(leftendpoint(d))) d
@test rightendpoint(d) d
@test BigFloat(rightendpoint(d)) d
@test nextfloat(rightendpoint(d)) d
@test nextfloat(BigFloat(rightendpoint(d))) d
@test prevfloat(rightendpoint(d)) d
@test prevfloat(rightendpoint(d)) d
@test infimum(d) == leftendpoint(d)
@test supremum(d) == rightendpoint(d)
@test prevfloat(BigFloat(rightendpoint(d))) d
@test infimum(d) == leftendpoint(d)
@test maximum(d) == supremum(d) == rightendpoint(d)
@test_throws ArgumentError minimum(d)

d = Interval{:closed,:open}(zero(T) .. one(T))
@test !IntervalSets.isopen(d)
@test !IntervalSets.isclosed(d)
@test IntervalSets.isleftclosed(d)
@test !IntervalSets.isleftopen(d)
@test IntervalSets.isrightopen(d)
@test !IntervalSets.isrightclosed(d)
@test leftendpoint(d) d
@test BigFloat(leftendpoint(d)) d
@test nextfloat(leftendpoint(d)) d
@test nextfloat(BigFloat(leftendpoint(d))) d
@test prevfloat(leftendpoint(d)) d
@test prevfloat(leftendpoint(d)) d
@test prevfloat(BigFloat(leftendpoint(d))) d
@test rightendpoint(d) d
@test BigFloat(rightendpoint(d)) d
@test nextfloat(rightendpoint(d)) d
@test nextfloat(BigFloat(rightendpoint(d))) d
@test prevfloat(rightendpoint(d)) d
@test prevfloat(rightendpoint(d)) d
@test infimum(d) == leftendpoint(d)
@test supremum(d) == rightendpoint(d)
@test prevfloat(BigFloat(rightendpoint(d))) d
@test infimum(d) == minimum(d) == leftendpoint(d)
@test supremum(d) == rightendpoint(d)
@test_throws ArgumentError maximum(d)


# - empty interval
@test isempty(one(T) .. zero(T))
@test zero(T) one(T) .. zero(T)
Expand Down Expand Up @@ -545,19 +576,22 @@ closedendpoints(I::MyUnitInterval) = (I.isleftclosed,I.isrightclosed)

@testset "Custom intervals" begin
I = MyUnitInterval(true,true)
@test eltype(I) == eltype(typeof(I)) == Int
@test leftendpoint(I) == 0
@test rightendpoint(I) == 1
@test isleftclosed(I) == true
@test isrightclosed(I) == true
@test isleftclosed(I)
@test !isleftopen(I)
@test isrightclosed(I)
@test !isrightopen(I)
@test ClosedInterval(I) === convert(ClosedInterval, I) ===
ClosedInterval{Int}(I) === convert(ClosedInterval{Int}, I) ===
convert(Interval, I) === Interval(I) === 0..1
@test_throws InexactError convert(OpenInterval, I)
I = MyUnitInterval(false,false)
@test leftendpoint(I) == 0
@test rightendpoint(I) == 1
@test isleftclosed(I) == false
@test isrightclosed(I) == false
@test !isleftclosed(I)
@test !isrightclosed(I)
@test OpenInterval(I) === convert(OpenInterval, I) ===
OpenInterval{Int}(I) === convert(OpenInterval{Int}, I) ===
convert(Interval, I) === Interval(I) === OpenInterval(0..1)
Expand Down Expand Up @@ -590,6 +624,8 @@ closedendpoints(I::MyUnitInterval) = (I.isleftclosed,I.isrightclosed)
ClosedInterval{Int}(I) === convert(ClosedInterval{Int}, I) ===
convert(Interval, I) === Interval(I) === 0..1
@test_throws InexactError convert(OpenInterval, I)
@test I I === 0..1
@test I (0.0..0.5) === 0.0..0.5
end

@testset "Missing endpoints" begin
Expand Down Expand Up @@ -644,9 +680,17 @@ closedendpoints(I::MyUnitInterval) = (I.isleftclosed,I.isrightclosed)
@test_throws ArgumentError Base.OneTo{Int}(0..5)
@test_throws ArgumentError Base.OneTo(0..5)
@test Base.OneTo(1..5) == Base.OneTo{Int}(1..5) == Base.OneTo(5)
@test Base.Slice(1..5) == Base.Slice{UnitRange{Int}}(1..5) == Base.Slice(1:5)
end

@testset "IteratorSize" begin
@test Base.IteratorSize(ClosedInterval) == Base.SizeUnknown()
end

@testset "IncompleteInterval" begin
I = IncompleteInterval()
@test eltype(I) === Int
@test_throws ErrorException endpoints(I)
@test_throws ErrorException closedendpoints(I)
end
end

2 comments on commit ecf4377

@dlfivefifty
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/2575

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.2 -m "<description of version>" ecf4377adccf5a59c2c0f9252efdf400da6cdfd0
git push origin v0.3.2

Please sign in to comment.