From d13b0faa7cd35414bdab8b19c3b3da26810bffd8 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 15 Mar 2018 00:52:29 +0100 Subject: [PATCH] add Base.extrema (#24) --- src/IntervalSets.jl | 2 +- src/closed.jl | 2 +- test/runtests.jl | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/IntervalSets.jl b/src/IntervalSets.jl index 29fa3d0..82e2476 100644 --- a/src/IntervalSets.jl +++ b/src/IntervalSets.jl @@ -5,7 +5,7 @@ module IntervalSets # package code goes here using Base: @pure -import Base: eltype, convert, show, in, length, isempty, isequal, issubset, ==, hash, union, intersect, minimum, maximum, range +import Base: eltype, convert, show, in, length, isempty, isequal, issubset, ==, hash, union, intersect, minimum, maximum, extrema, range if isdefined(Main, :⊇) import Base: ⊇ end diff --git a/src/closed.jl b/src/closed.jl index 85c1ef7..c34c4f8 100644 --- a/src/closed.jl +++ b/src/closed.jl @@ -56,6 +56,7 @@ hash(I::ClosedInterval, h::UInt) = hash(I.left, hash(I.right, hash(_closed_inter minimum(I::ClosedInterval) = I.left maximum(I::ClosedInterval) = I.right +extrema(I::ClosedInterval) = (minimum(I), maximum(I)) function intersect(A::ClosedInterval, B::ClosedInterval) left = max(A.left, B.left) @@ -105,4 +106,3 @@ end range{I<:Integer}(i::ClosedInterval{I}) = convert(UnitRange{I}, i) Base.promote_rule{T1,T2}(::Type{ClosedInterval{T1}}, ::Type{ClosedInterval{T2}}) = ClosedInterval{promote_type(T1, T2)} - diff --git a/test/runtests.jl b/test/runtests.jl index 7d8efd5..bf94d37 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -46,6 +46,7 @@ using Base.Test @test maximum(I) === 3 @test minimum(I) === 0 + @test extrema(I) === (0, 3) @test 2 in I @test 1..2 in 0.5..2.5