Skip to content

Commit

Permalink
Support for missing values (#48)
Browse files Browse the repository at this point in the history
* Support `missing in a..b`

* Add tests for missing interval endpoints

* Drop 0.6 compatibility

* Add test cases
  • Loading branch information
cstjean authored and dlfivefifty committed Mar 2, 2019
1 parent 72ab3fb commit 742adb5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ os:
- linux
- osx
julia:
- 0.6
- 0.7
- 1.0
- nightly
Expand Down
3 changes: 1 addition & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
julia 0.6
Compat 1.0
julia 0.7
13 changes: 8 additions & 5 deletions src/IntervalSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ using Base: @pure
import Base: eltype, convert, show, in, length, isempty, isequal, issubset, ==, hash,
union, intersect, minimum, maximum, extrema, range,

using Compat.Statistics
import Compat.Statistics: mean
using Statistics
import Statistics: mean


using Compat
using Compat.Dates
using Dates

export AbstractInterval, Interval, OpenInterval, ClosedInterval,
, .., ±, ordered, width, duration, leftendpoint, rightendpoint, endpoints,
Expand Down Expand Up @@ -133,6 +131,11 @@ in(v::Complex, I::TypedEndpointsInterval{:open,:open}) = isreal(v) && in(real(v)
in(v::Complex, I::TypedEndpointsInterval{:closed,:open}) = isreal(v) && in(real(v), I)
in(v::Complex, I::TypedEndpointsInterval{:open,:closed}) = isreal(v) && in(real(v), I)

in(::Missing, I::TypedEndpointsInterval{:closed,:closed}) = !isempty(I) && missing
in(::Missing, I::TypedEndpointsInterval{:open,:open}) = !isempty(I) && missing
in(::Missing, I::TypedEndpointsInterval{:closed,:open}) = !isempty(I) && missing
in(::Missing, I::TypedEndpointsInterval{:open,:closed}) = !isempty(I) && missing

in(a::AbstractInterval, b::TypedEndpointsInterval{:closed,:closed}) =
(leftendpoint(a) leftendpoint(b)) & (rightendpoint(a) rightendpoint(b))
in(a::TypedEndpointsInterval{:open,:open}, b::TypedEndpointsInterval{:open,:open}) =
Expand Down
22 changes: 17 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using IntervalSets
using Compat
using Compat.Test
using Compat.Dates
using Compat.Statistics
import Compat.Statistics: mean
using Test
using Dates
using Statistics
import Statistics: mean

import IntervalSets: Domain, endpoints, closedendpoints, TypedEndpointsInterval

Expand Down Expand Up @@ -593,13 +592,26 @@ closedendpoints(I::MyUnitInterval) = (I.isleftclosed,I.isrightclosed)
@test_throws InexactError convert(OpenInterval, I)
end

@testset "Missing endpoints" begin
@test ismissing(2 in 1..missing)
@test_broken ismissing(2 in missing..1) # would be fixed by julialang#31171
end

@testset "issubset" begin
@test issubset(0.1, 0.0..1.0) == true
@test issubset(0.0, 0.0..1.0) == true
@test issubset(1.1, 0.0..1.0) == false
@test issubset(0.0, nextfloat(0.0)..1.0) == false
end

@testset "missing in" begin
@test ismissing(missing in 0..1)
@test !(missing in 1..0)
@test ismissing(missing in OpenInterval(0, 1))
@test ismissing(missing in Interval{:closed, :open}(0, 1))
@test ismissing(missing in Interval{:open, :closed}(0, 1))
end

@testset "complex in" begin
@test 0+im 0..2
@test 0+0im 0..2
Expand Down

0 comments on commit 742adb5

Please sign in to comment.