Skip to content

Commit

Permalink
Update tests and doctests for Julia 1.6 (#162)
Browse files Browse the repository at this point in the history
Co-authored-by: Curtis Vogt <curtis.vogt@gmail.com>
  • Loading branch information
mjram0s and omus authored Mar 30, 2021
1 parent 8474023 commit f873f70
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 83 deletions.
58 changes: 29 additions & 29 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ This package defines:

```jldoctest
julia> a = 1..10
Interval{Int64,Closed,Closed}(1, 10)
Interval{Int64, Closed, Closed}(1, 10)
julia> b = 5..15
Interval{Int64,Closed,Closed}(5, 15)
Interval{Int64, Closed, Closed}(5, 15)
julia> intersect(a, b)
Interval{Int64,Closed,Closed}(5, 10)
Interval{Int64, Closed, Closed}(5, 10)
```

### Bounds

```jldoctest
julia> a = Interval{Closed,Closed}(1, 10)
Interval{Int64,Closed,Closed}(1, 10)
julia> a = Interval{Closed, Closed}(1, 10)
Interval{Int64, Closed, Closed}(1, 10)
julia> b = Interval{Open,Open}(5, 15)
Interval{Int64,Open,Open}(5, 15)
julia> b = Interval{Open, Open}(5, 15)
Interval{Int64, Open, Open}(5, 15)
julia> 5 in a
true
Expand All @@ -57,10 +57,10 @@ julia> 5 in b
false
julia> intersect(a, b)
Interval{Int64,Open,Closed}(5, 10)
Interval{Int64, Open, Closed}(5, 10)
julia> c = Interval(15, 20)
Interval{Int64,Closed,Closed}(15, 20)
Interval{Int64, Closed, Closed}(15, 20)
julia> isempty(intersect(b, c))
true
Expand All @@ -70,21 +70,21 @@ true

```jldoctest
julia> a = Interval('a', 'z')
Interval{Char,Closed,Closed}('a', 'z')
Interval{Char, Closed, Closed}('a', 'z')
julia> string(a)
"[a .. z]"
julia> using Dates
julia> b = Interval{Closed,Open}(Date(2013), Date(2016))
Interval{Date,Closed,Open}(Date("2013-01-01"), Date("2016-01-01"))
julia> b = Interval{Closed, Open}(Date(2013), Date(2016))
Interval{Date, Closed, Open}(Date("2013-01-01"), Date("2016-01-01"))
julia> string(b)
"[2013-01-01 .. 2016-01-01)"
julia> c = HourEnding(DateTime(2016, 8, 11))
AnchoredInterval{Hour(-1),DateTime,Open,Closed}(DateTime("2016-08-11T00:00:00"))
HourEnding{DateTime, Open, Closed}(DateTime("2016-08-11T00:00:00"))
julia> string(c)
"(2016-08-10 HE24]"
Expand All @@ -96,13 +96,13 @@ julia> string(c)
julia> using TimeZones, Dates
julia> unrounded = HourEnding(ZonedDateTime(2013, 2, 13, 0, 30, tz"America/Winnipeg"))
AnchoredInterval{Hour(-1),ZonedDateTime,Open,Closed}(ZonedDateTime(2013, 2, 13, 0, 30, tz"America/Winnipeg"))
HourEnding{ZonedDateTime, Open, Closed}(ZonedDateTime(2013, 2, 13, 0, 30, tz"America/Winnipeg"))
julia> he = HE(ZonedDateTime(2013, 2, 13, 0, 30, tz"America/Winnipeg"))
AnchoredInterval{Hour(-1),ZonedDateTime,Open,Closed}(ZonedDateTime(2013, 2, 13, 1, tz"America/Winnipeg"))
HourEnding{ZonedDateTime, Open, Closed}(ZonedDateTime(2013, 2, 13, 1, tz"America/Winnipeg"))
julia> he + Hour(1)
AnchoredInterval{Hour(-1),ZonedDateTime,Open,Closed}(ZonedDateTime(2013, 2, 13, 2, tz"America/Winnipeg"))
HourEnding{ZonedDateTime, Open, Closed}(ZonedDateTime(2013, 2, 13, 2, tz"America/Winnipeg"))
julia> foreach(println, he:he + Day(1))
(2013-02-13 HE01-06:00]
Expand Down Expand Up @@ -168,14 +168,14 @@ Two `AbstractInterval`s are considered equal if they have identical left and rig
endpoints (taking bounds into account):

```jldoctest
julia> a = Interval{Closed,Open}(DateTime(2013, 2, 13), DateTime(2013, 2, 13, 1))
Interval{DateTime,Closed,Open}(DateTime("2013-02-13T00:00:00"), DateTime("2013-02-13T01:00:00"))
julia> a = Interval{Closed, Open}(DateTime(2013, 2, 13), DateTime(2013, 2, 13, 1))
Interval{DateTime, Closed, Open}(DateTime("2013-02-13T00:00:00"), DateTime("2013-02-13T01:00:00"))
julia> b = Interval{Open,Closed}(DateTime(2013, 2, 13), DateTime(2013, 2, 13, 1))
Interval{DateTime,Open,Closed}(DateTime("2013-02-13T00:00:00"), DateTime("2013-02-13T01:00:00"))
julia> b = Interval{Open, Closed}(DateTime(2013, 2, 13), DateTime(2013, 2, 13, 1))
Interval{DateTime, Open, Closed}(DateTime("2013-02-13T00:00:00"), DateTime("2013-02-13T01:00:00"))
julia> c = HourEnding(DateTime(2013, 2, 13, 1))
AnchoredInterval{Hour(-1),DateTime,Open,Closed}(DateTime("2013-02-13T01:00:00"))
HourEnding{DateTime, Open, Closed}(DateTime("2013-02-13T01:00:00"))
julia> a == b
false
Expand Down Expand Up @@ -219,32 +219,32 @@ endpoint should be used for rounding. Valid options are `:left`, `:right`, or

```jldoctest
julia> floor(Interval(0.0, 1.0), on=:left)
Interval{Float64,Closed,Closed}(0.0, 1.0)
Interval{Float64, Closed, Closed}(0.0, 1.0)
julia> floor(Interval(0.5, 1.0), on=:left)
Interval{Float64,Closed,Closed}(0.0, 0.5)
Interval{Float64, Closed, Closed}(0.0, 0.5)
julia> floor(Interval(0.5, 1.5), on=:right)
Interval{Float64,Closed,Closed}(0.0, 1.0)
Interval{Float64, Closed, Closed}(0.0, 1.0)
```

Anchored intervals default to rounding using the anchor point.

```jldoctest
julia> round(AnchoredInterval{-0.5}(1.0))
AnchoredInterval{-0.5,Float64,Open,Closed}(1.0)
AnchoredInterval{-0.5, Float64, Open, Closed}(1.0)
julia> round(AnchoredInterval{+0.5}(0.5))
AnchoredInterval{0.5,Float64,Closed,Open}(0.0)
AnchoredInterval{0.5, Float64, Closed, Open}(0.0)
julia> round(AnchoredInterval{+0.5}(0.5), on=:anchor)
AnchoredInterval{0.5,Float64,Closed,Open}(0.0)
AnchoredInterval{0.5, Float64, Closed, Open}(0.0)
julia> round(AnchoredInterval{+0.5}(0.5), on=:left)
AnchoredInterval{0.5,Float64,Closed,Open}(0.0)
AnchoredInterval{0.5, Float64, Closed, Open}(0.0)
julia> round(AnchoredInterval{+0.5}(0.5), on=:right)
AnchoredInterval{0.5,Float64,Closed,Open}(0.5)
AnchoredInterval{0.5, Float64, Closed, Open}(0.5)
```

## API
Expand Down
12 changes: 6 additions & 6 deletions src/anchoredinterval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,31 @@ specific hour, the constructor makes no guarantees that the anchor provided is r
```jldoctest; setup = :(using Intervals, Dates), filter = r"AnchoredInterval\\{(Day|Hour|Minute)\\(-?\\d+\\),|Hour(Ending|Beginning)\\{"
julia> HourEnding(DateTime(2016, 8, 11, 2, 30))
AnchoredInterval{Hour(-1),DateTime,Open,Closed}(DateTime("2016-08-11T02:30:00"))
HourEnding{DateTime, Open, Closed}(DateTime("2016-08-11T02:30:00"))
```
The `HE` and `HB` pseudoconstructors round the input up or down to the nearest hour, as
appropriate:
```jldoctest; setup = :(using Intervals, Dates), filter = r"AnchoredInterval\\{(Day|Hour|Minute)\\(-?\\d+\\),|Hour(Ending|Beginning)\\{"
julia> HE(DateTime(2016, 8, 11, 2, 30))
AnchoredInterval{Hour(-1),DateTime,Open,Closed}(DateTime("2016-08-11T03:00:00"))
HourEnding{DateTime, Open, Closed}(DateTime("2016-08-11T03:00:00"))
julia> HB(DateTime(2016, 8, 11, 2, 30))
AnchoredInterval{Hour(1),DateTime,Closed,Open}(DateTime("2016-08-11T02:00:00"))
HourBeginning{DateTime, Closed, Open}(DateTime("2016-08-11T02:00:00"))
```
### Example
```jldoctest; setup = :(using Intervals, Dates), filter = r"AnchoredInterval\\{(Day|Hour|Minute)\\(-?\\d+\\),|Hour(Ending|Beginning)\\{"
julia> AnchoredInterval{Hour(-1)}(DateTime(2016, 8, 11, 12))
AnchoredInterval{Hour(-1),DateTime,Open,Closed}(DateTime("2016-08-11T12:00:00"))
HourEnding{DateTime, Open, Closed}(DateTime("2016-08-11T12:00:00"))
julia> AnchoredInterval{Day(1)}(DateTime(2016, 8, 11))
AnchoredInterval{Day(1),DateTime,Closed,Open}(DateTime("2016-08-11T00:00:00"))
AnchoredInterval{Day(1), DateTime, Closed, Open}(DateTime("2016-08-11T00:00:00"))
julia> AnchoredInterval{Minute(5),Closed,Closed}(DateTime(2016, 8, 11, 12, 30))
AnchoredInterval{Minute(5),DateTime,Closed,Closed}(DateTime("2016-08-11T12:30:00"))
AnchoredInterval{Minute(5), DateTime, Closed, Closed}(DateTime("2016-08-11T12:30:00"))
```
See also: [`Interval`](@ref), [`HE`](@ref), [`HB`](@ref)
Expand Down
8 changes: 4 additions & 4 deletions src/docstrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ to each other.
```jldoctest; setup = :(using Intervals; using Intervals: LeftEndpoint)
julia> LeftEndpoint(Interval(0.0, 1.0))
Intervals.Endpoint{Float64,Intervals.Direction{:Left}(),Closed}(0.0)
Intervals.Endpoint{Float64, Intervals.Direction{:Left}(), Closed}(0.0)
julia> LeftEndpoint{Closed}(1.0)
Intervals.Endpoint{Float64,Intervals.Direction{:Left}(),Closed}(1.0)
Intervals.Endpoint{Float64, Intervals.Direction{:Left}(), Closed}(1.0)
julia> LeftEndpoint{Closed}(1) < LeftEndpoint{Closed}(2)
true
Expand All @@ -80,10 +80,10 @@ to each other.
```jldoctest; setup = :(using Intervals; using Intervals: RightEndpoint)
julia> RightEndpoint(Interval(0.0, 1.0))
Intervals.Endpoint{Float64,Intervals.Direction{:Right}(),Closed}(1.0)
Intervals.Endpoint{Float64, Intervals.Direction{:Right}(), Closed}(1.0)
julia> RightEndpoint{Closed}(1.0)
Intervals.Endpoint{Float64,Intervals.Direction{:Right}(),Closed}(1.0)
Intervals.Endpoint{Float64, Intervals.Direction{:Right}(), Closed}(1.0)
julia> RightEndpoint{Closed}(1) < RightEndpoint{Closed}(2)
true
Expand Down
Loading

0 comments on commit f873f70

Please sign in to comment.