Skip to content

Commit

Permalink
Remove some redundant dates tests to make dates test suite run a litt…
Browse files Browse the repository at this point in the history
…le faster.
  • Loading branch information
quinnj committed Aug 18, 2014
1 parent 9f81a60 commit c1b843c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 33 deletions.
32 changes: 15 additions & 17 deletions test/dates/accessors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,24 @@ function test_dates(from,to)
end
end
end
test_dates(-1000,3000)
test_dates(0,2100)

# Test year, month, day, hour, minute
function test_dates()
y = m = d = h = mi = 0
for y in [-2013,-1,0,1,2013]
for m = 1:12
for d = 1:Dates.daysinmonth(y,m)
for h = 0:23
for mi = 0:59
dt = Dates.DateTime(y,m,d,h,mi)
@test y == Dates.year(dt)
@test m == Dates.month(dt)
@test d == Dates.day(dt)
@test d == Dates.dayofmonth(dt)
@test h == Dates.hour(dt)
@test mi == Dates.minute(dt)
#@test s == Dates.second(dt)
#@test ms == Dates.millisecond(dt)
end
for m = 1:12
for d = 1:Dates.daysinmonth(y,m)
for h = 0:23
for mi = 0:59
dt = Dates.DateTime(y,m,d,h,mi)
@test y == Dates.year(dt)
@test m == Dates.month(dt)
@test d == Dates.day(dt)
@test d == Dates.dayofmonth(dt)
@test h == Dates.hour(dt)
@test mi == Dates.minute(dt)
#@test s == Dates.second(dt)
#@test ms == Dates.millisecond(dt)
end
end
end
Expand Down Expand Up @@ -117,7 +115,7 @@ function test_dates(from,to)
end
end
end
test_dates(-2000,2000)
test_dates(0,2100)

# week function
# Tests from http:https://en.wikipedia.org/wiki/ISO_week_date
Expand Down
32 changes: 16 additions & 16 deletions test/dates/adjusters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,20 @@ januarymondays2014 = [Dates.Date(2014,1,6),Dates.Date(2014,1,13),Dates.Date(2014
@test Dates.recur(Dates.ismonday,startdate:stopdate) == januarymondays2014
@test Dates.recur(x->!Dates.ismonday(x),startdate,stopdate;negate=true) == januarymondays2014

@test_throws ArgumentError recur((x,y)->x+y,Dates.Date(2013):Dates.Date(2014))
@test length(recur(x->true,Dates.Date(2013):Dates.Date(2013,2))) == 32
@test length(recur(x->true,Dates.Date(2013):Dates.Date(2013,1,1))) == 1
@test length(recur(x->true,Dates.Date(2013):Dates.Date(2013,1,2))) == 2
@test length(recur(x->true,Dates.Date(2013):Dates.Date(2013,1,3))) == 3
@test length(recur(x->true,Dates.Date(2013):Dates.Date(2013,1,4))) == 4
@test length(recur(x->true,Dates.Date(2013):Dates.Date(2013,1,5))) == 5
@test length(recur(x->true,Dates.Date(2013):Dates.Date(2013,1,6))) == 6
@test length(recur(x->true,Dates.Date(2013):Dates.Date(2013,1,7))) == 7
@test length(recur(x->true,Dates.Date(2013):Dates.Date(2013,1,8))) == 8
@test length(recur(x->true,Dates.Date(2013):Dates.Month(1):Dates.Date(2013,1,1))) == 1
@test length(recur(x->true,Dates.Date(2013):Dates.Day(-1):Dates.Date(2012,1,1))) == 367
@test_throws ArgumentError Dates.recur((x,y)->x+y,Dates.Date(2013):Dates.Date(2014))
@test length(Dates.recur(x->true,Dates.Date(2013):Dates.Date(2013,2))) == 32
@test length(Dates.recur(x->true,Dates.Date(2013):Dates.Date(2013,1,1))) == 1
@test length(Dates.recur(x->true,Dates.Date(2013):Dates.Date(2013,1,2))) == 2
@test length(Dates.recur(x->true,Dates.Date(2013):Dates.Date(2013,1,3))) == 3
@test length(Dates.recur(x->true,Dates.Date(2013):Dates.Date(2013,1,4))) == 4
@test length(Dates.recur(x->true,Dates.Date(2013):Dates.Date(2013,1,5))) == 5
@test length(Dates.recur(x->true,Dates.Date(2013):Dates.Date(2013,1,6))) == 6
@test length(Dates.recur(x->true,Dates.Date(2013):Dates.Date(2013,1,7))) == 7
@test length(Dates.recur(x->true,Dates.Date(2013):Dates.Date(2013,1,8))) == 8
@test length(Dates.recur(x->true,Dates.Date(2013):Dates.Month(1):Dates.Date(2013,1,1))) == 1
@test length(Dates.recur(x->true,Dates.Date(2013):Dates.Day(-1):Dates.Date(2012,1,1))) == 367
# Empty range
@test length(recur(x->true,Dates.Date(2013):Dates.Date(2012,1,1))) == 0
@test length(Dates.recur(x->true,Dates.Date(2013):Dates.Date(2012,1,1))) == 0

# All leap days in 20th century
@test length(Dates.recur(Dates.Date(1900):Dates.Date(2000)) do x
Expand All @@ -340,7 +340,7 @@ end == Dates.Date(2013,11,28)

# Pittsburgh street cleaning
dr = Dates.Date(2014):Dates.Date(2015)
@test length(recur(dr) do x
@test length(Dates.recur(dr) do x
Dates.dayofweek(x) == Dates.Tue &&
Dates.April < Dates.month(x) < Dates.Nov &&
Dates.dayofweekofmonth(x) == 2
Expand All @@ -362,10 +362,10 @@ ispresidentsday(dt) = Dates.dayofweek(dt) == Dates.Mon &&
Dates.month(dt) == Dates.Feb && Dates.dayofweekofmonth(dt) == 3
# Last Monday of May
ismemorialday(dt) = Dates.dayofweek(dt) == Dates.Mon &&
Dates.month(dt) == May &&
Dates.month(dt) == Dates.May &&
Dates.dayofweekofmonth(dt) == Dates.daysofweekinmonth(dt)
islaborday(dt) = Dates.dayofweek(dt) == Dates.Mon &&
Dates.month(dt) == Dates.Sep && dayofweekofmonth(dt) == 1
Dates.month(dt) == Dates.Sep && Dates.dayofweekofmonth(dt) == 1
iscolumbusday(dt) = Dates.dayofweek(dt) == Dates.Mon &&
Dates.month(dt) == Dates.Oct && Dates.dayofweekofmonth(dt) == 2
isthanksgiving(dt) = Dates.dayofweek(dt) == Dates.Thu &&
Expand Down

0 comments on commit c1b843c

Please sign in to comment.