Skip to content

Commit

Permalink
Added tests for rounding and updatig functions on length zero input, …
Browse files Browse the repository at this point in the history
…decimal_date on first second of year
  • Loading branch information
garrettgman committed Nov 14, 2012
1 parent 9387531 commit c2dfc2f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions inst/tests/test-decimal-date.R
Expand Up @@ -12,3 +12,9 @@ test_that("decimal_date works handles vectors",{
expect_that(round(decimal_date(x), 3), equals(c(2008.589, 2009.587)))

})

test_that("decimal_date handles first second of year without returning NaN",{

expect_equal(decimal_date(ymd("2012-01-01")), 2012)

})
18 changes: 18 additions & 0 deletions inst/tests/test-round.R
Expand Up @@ -186,4 +186,22 @@ test_that("floor_date does not round down dates that are already on a boundary",

test_that("round_date does not round dates that are already on a boundary",{
expect_equal(round_date(as.Date("2012-09-27"), 'day'), as.Date("2012-09-27"))
})

test_that("ceiling_date returns input of length zero when given input of length zero",{
x <- structure(vector(mode = "numeric"), class = c("POSIXct", "POSIXt"))

expect_equal(ceiling_date(x), x)
})

test_that("floor_date returns input of length zero when given input of length zero",{
x <- structure(vector(mode = "numeric"), class = c("POSIXct", "POSIXt"))

expect_equal(floor_date(x), x)
})

test_that("round_date returns input of length zero when given input of length zero",{
x <- structure(vector(mode = "numeric"), class = c("POSIXct", "POSIXt"))

expect_equal(round_date(x), x)
})
12 changes: 12 additions & 0 deletions inst/tests/test-update.R
Expand Up @@ -410,3 +410,15 @@ test_that("update handles gives error for non-conformable vectors of inputs",{
expect_that(day(update(date, days = c(1,2), months =
c(1,2,3))), throws_error())
})

test_that("update.POSIXct returns input of length zero when given input of length zero",{
x <- structure(vector(mode = "numeric"), class = c("POSIXct", "POSIXt"))

expect_equal(update(x, days = 1), x)
})

test_that("update.POSIXlt returns input of length zero when given input of length zero",{
x <- as.POSIXlt(structure(vector(mode = "numeric"), class = c("POSIXct", "POSIXt")))

expect_equal(update(x, days = 1), x)
})

0 comments on commit c2dfc2f

Please sign in to comment.