Skip to content

Commit

Permalink
Merge pull request #14 from JuliaArrays/teh/combine_all_the_commits
Browse files Browse the repository at this point in the history
Combine all the commits
  • Loading branch information
timholy authored Aug 11, 2018
2 parents c86672d + f68be48 commit a710fb7
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 51 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ language: julia
os:
- linux
julia:
- 0.6
- 0.7
- 1.0
- nightly
notifications:
email: false
Expand All @@ -13,4 +14,4 @@ notifications:
# - julia -e 'Pkg.clone(pwd()); Pkg.build("CustomUnitRanges"); Pkg.test("CustomUnitRanges"; coverage=true)'
after_success:
# push coverage results to Codecov
- julia -e 'cd(Pkg.dir("CustomUnitRanges")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
- julia -e 'using Pkg, CustomUnitRanges; cd(joinpath(pathof(CustomUnitRanges), "..")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module MyArrayType
using CustomUnitRanges: filename_for_urange
include(filename_for_urange)

immutable MyArray{T,N} <: AbstractArray{T,N}
struct MyArray{T,N} <: AbstractArray{T,N}
...
end

Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
julia 0.6
julia 0.7
28 changes: 12 additions & 16 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
- julia_version: 1.0
- julia_version: nightly

matrix:
allow_failures:
- julia_version: latest


branches:
only:
Expand All @@ -17,19 +20,12 @@ notifications:
on_build_status_changed: false

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"CustomUnitRanges\"); Pkg.build(\"CustomUnitRanges\")"
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"CustomUnitRanges\")"
- echo "%JL_TEST_SCRIPT%"
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"
17 changes: 10 additions & 7 deletions src/URange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ urange_last(start::T, stop::T) where {T} =
ifelse(stop >= start, convert(T,start+floor(stop-start)),
convert(T,start-one(stop-start)))

Base.start(r::URange{T}) where {T} = oftype(r.start + one(T), r.start)
function Base.iterate(r::URange{T}) where {T}
r.start > r.stop && return nothing
x = oftype(r.start + one(T), r.start)
return (x,x)
end
function Base.iterate(r::URange{T}, i) where T
x = i + one(T)
return (x > oftype(x, r.stop) ? nothing : (x,x))
end

Base.intersect(r::URange{T1}, s::URange{T2}) where {T1<:Integer,T2<:Integer} = URange(max(first(r),first(s)), min(last(r),last(s)))

Expand All @@ -33,11 +41,6 @@ Base.promote_rule(::Type{URange{T1}}, ::Type{UR}) where {T1,UR<:AbstractUnitRang
Base.promote_rule(::Type{UnitRange{T2}}, ::Type{URange{T1}}) where {T1,T2} =
URange{promote_type(T1,T2)}
Base.convert(::Type{URange{T}}, r::AbstractUnitRange) where {T<:Real} = URange{T}(first(r), last(r))

let smallint = (Int === Int64 ?
Union{Int8,UInt8,Int16,UInt16,Int32,UInt32} :
Union{Int8,UInt8,Int16,UInt16})
Base.start(r::URange{T}) where {T<:smallint} = convert(Int, r.start)
end
URange{T}(r::AbstractUnitRange) where {T} = convert(Type{URange{T}}, r)

Base.show(io::IO, r::URange) = print(io, typeof(r).name, '(', repr(first(r)), ',', repr(last(r)), ')')
17 changes: 12 additions & 5 deletions src/ZeroRange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ Base.length(r::ZeroRange{T}) where {T<:Union{Int,Int64}} = T(r.len)
let smallint = (Int === Int64 ?
Union{Int8,UInt8,Int16,UInt16,Int32,UInt32} :
Union{Int8,UInt8,Int16,UInt16})
Base.length(r::ZeroRange{T}) where {T <: smallint} = Int(r.len)
Base.start(r::ZeroRange{T}) where {T<:smallint} = 0
Base.length(r::ZeroRange{T}) where {T<:smallint} = Int(r.len)
end

Base.first(r::ZeroRange{T}) where {T} = zero(T)
Base.last(r::ZeroRange{T}) where { T} = r.len-one(T)
Base.last(r::ZeroRange{T}) where {T} = r.len-one(T)

Base.start(r::ZeroRange{T}) where {T} = oftype(one(T)+one(T), zero(T))
Base.done(r::ZeroRange{T}, i) where {T} = i == oftype(i, r.len)
function Base.iterate(r::ZeroRange{T}) where T
r.len <= 0 && return nothing
x = oftype(one(T) + one(T), zero(T))
return (x,x)
end
function Base.iterate(r::ZeroRange{T}, i) where T
x = i + one(T)
return (x >= oftype(x, r.len) ? nothing : (x,x))
end

@inline function Base.getindex(v::ZeroRange{T}, i::Integer) where T
@boundscheck ((i > 0) & (i <= length(v))) || Base.throw_boundserror(v, i)
Expand All @@ -44,5 +50,6 @@ Base.promote_rule(::Type{ZeroRange{T1}},::Type{ZeroRange{T2}}) where {T1,T2} =
ZeroRange{promote_type(T1,T2)}
Base.convert(::Type{ZeroRange{T}}, r::ZeroRange{T}) where {T<:Real} = r
Base.convert(::Type{ZeroRange{T}}, r::ZeroRange) where {T<:Real} = ZeroRange{T}(r.len)
ZeroRange{T}(r::ZeroRange) where {T} = convert(ZeroRange{T}, r)

Base.show(io::IO, r::ZeroRange) = print(io, typeof(r).name, "(", r.len, ")")
11 changes: 9 additions & 2 deletions src/ZeroTo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ let smallint = (Int === Int64 ?
Union{Int8,UInt8,Int16,UInt16,Int32,UInt32} :
Union{Int8,UInt8,Int16,UInt16})
Base.length(r::ZeroTo{T}) where {T <: smallint} = Int(r.stop)+1
Base.start(r::ZeroTo{T}) where {T<:smallint} = 0
end

Base.first(r::ZeroTo{T}) where {T} = zero(T)

Base.start(r::ZeroTo{T}) where {T} = zero(T)
function Base.iterate(r::ZeroTo{T}) where {T}
x = zero(T)
return (r.stop <= x ? nothing : (x,x))
end
function Base.iterate(r::ZeroTo{T}, i) where T
x = i + one(T)
return (x > oftype(x, r.stop) ? nothing : (x,x))
end

@inline function Base.getindex(v::ZeroTo{T}, i::Integer) where T
@boundscheck ((i > 0) & (i <= length(v))) || Base.throw_boundserror(v, i)
Expand All @@ -43,5 +49,6 @@ Base.promote_rule(::Type{ZeroTo{T1}},::Type{ZeroTo{T2}}) where {T1,T2} =
ZeroTo{promote_type(T1,T2)}
Base.convert(::Type{ZeroTo{T}}, r::ZeroTo{T}) where {T<:Real} = r
Base.convert(::Type{ZeroTo{T}}, r::ZeroTo) where {T<:Real} = ZeroTo{T}(r.stop)
ZeroTo{T}(r::ZeroTo) where {T} = convert(Type{ZeroTo{T}}, r)

Base.show(io::IO, r::ZeroTo) = print(io, typeof(r).name, "(", r.stop, ")")
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Base.Test
using Test

include("zerorange.jl")
include("urange.jl")
Expand Down
10 changes: 5 additions & 5 deletions test/urange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include(filename_for_urange)

end

using ModU: URange
using .ModU: URange

@testset "URange" begin
@testset "Bool" begin
Expand Down Expand Up @@ -50,7 +50,7 @@ using ModU: URange
@test_throws BoundsError r[10]
@test_throws BoundsError r[0]
@test r[2:8] === URange(T(-4), T(2))
@test r+1 === -T(4):T(4)
@test r .+ 1 === -T(4):T(4)
@test 2*r === -T(10):T(2):T(6)
k = -6
for i in r
Expand All @@ -69,15 +69,15 @@ using ModU: URange
@test intersect(r, 2) == intersect(2, r) == [2.0]
@test intersect(r, 7) == intersect(7, r) == Float64[]
end
@test findin(r, 0:5) == (T<:Integer ? (6:9) : collect(6:9))
@test findin(r, URange(0,5)) == (T<:Integer ? (6:9) : collect(6:9))
@test findall(in(0:5), r) == (T<:Integer ? (6:9) : collect(6:9))
@test findall(in(URange(0,5)), r) == (T<:Integer ? (6:9) : collect(6:9))
x, y = promote(r, 1:3)
@test convert(URange{Int16}, 0:3) === URange{Int16}(0,3)
@test convert(URange{Int16}, Base.OneTo(5)) === URange{Int16}(1,5)
@test convert(URange{Int16}, r) === URange{Int16}(-5, 3)
@test x === r
@test y === URange(T(1),T(3))
@test string(r) == "ModU.URange(-$(T(5)),$(T(3)))"
@test string(r) == "URange(-$(T(5)),$(T(3)))"
end
end

Expand Down
14 changes: 8 additions & 6 deletions test/zerorange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include(filename_for_zerorange)

end

using ModZ: ZeroRange
using .ModZ: ZeroRange

@testset "ZeroRange" begin
r = ZeroRange(-5)
Expand All @@ -28,17 +28,18 @@ using ModZ: ZeroRange
@test_throws BoundsError r[-1]
@test r[1:3] === 0:2
@test_throws BoundsError r[r]
@test r+1 === 1:3
@test r .+ 1 === 1:3
@test 2*r === 0:2:4
k = -1
for i in r
@test i == (k+=1)
j = (k+=1)
@test i == j
end
@test k == length(r)-1
@test intersect(r, ZeroRange(2)) === intersect(ZeroRange(2), r) === ZeroRange(2)
@test intersect(r, -1:5) === intersect(-1:5, r) === 0:2
@test intersect(r, 2:5) === intersect(2:5, r) === 2:2
@test string(r) == "ModZ.ZeroRange(3)"
@test string(r) == "ZeroRange(3)"

r = ZeroRange(5)
@test checkindex(Bool, r, 4)
Expand Down Expand Up @@ -67,10 +68,11 @@ using ModZ: ZeroRange

r = ZeroRange{Int16}(5)
@test length(r) === 5
@test start(r) === 0
@test iterate(r) == (0,0)
k = -1
for i in r
@test i == (k+=1)
j = (k+=1)
@test i == j
end
@test k == length(r)-1
x, y = promote(ZeroRange(5), ZeroRange{Int16}(8))
Expand Down
10 changes: 5 additions & 5 deletions test/zeroto.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include(joinpath(dirname(@__FILE__), "..", "src", "ZeroTo.jl"))

end

using ModZT: ZeroTo
using .ModZT: ZeroTo

r = ZeroTo(-5)
@test isempty(r)
Expand All @@ -25,13 +25,13 @@ r = ZeroTo(3)
@test r[4] == 3
@test_throws BoundsError r[5]
@test_throws BoundsError r[-1]
@test r+1 === 1:4
@test r .+ 1 === 1:4
@test 2*r === 0:2:6
k = -1
for i in r
@test i == (k+=1)
@test i == (global k += 1)
end
@test intersect(r, ZeroTo(2)) == ZeroTo(2)
@test intersect(r, ZeroRange(2)) == ZeroRange(2) # deprecated
@test intersect(r, -1:5) == 0:3
@test intersect(r, 2:5) == 2:3
@test string(r) == "ModZT.ZeroTo(3)"
@test string(r) == "ZeroTo(3)"

0 comments on commit a710fb7

Please sign in to comment.