From 742adb59581f1b944bc571a4e2249d6b11fa7267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20St-Jean?= Date: Sat, 2 Mar 2019 13:29:30 -0500 Subject: [PATCH] Support for missing values (#48) * Support `missing in a..b` * Add tests for missing interval endpoints * Drop 0.6 compatibility * Add test cases --- .travis.yml | 1 - REQUIRE | 3 +-- src/IntervalSets.jl | 13 ++++++++----- test/runtests.jl | 22 +++++++++++++++++----- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7abccbc..541665a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,6 @@ os: - linux - osx julia: - - 0.6 - 0.7 - 1.0 - nightly diff --git a/REQUIRE b/REQUIRE index ab2915c..859ad46 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1 @@ -julia 0.6 -Compat 1.0 +julia 0.7 diff --git a/src/IntervalSets.jl b/src/IntervalSets.jl index 6e9e446..aa79f69 100644 --- a/src/IntervalSets.jl +++ b/src/IntervalSets.jl @@ -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, @@ -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}) = diff --git a/test/runtests.jl b/test/runtests.jl index 2cca9b9..703b8c7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 @@ -593,6 +592,11 @@ 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 @@ -600,6 +604,14 @@ closedendpoints(I::MyUnitInterval) = (I.isleftclosed,I.isrightclosed) @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