Skip to content

Commit

Permalink
Update test-utils-na_as.R
Browse files Browse the repository at this point in the history
  • Loading branch information
danielvartan committed May 25, 2021
1 parent 3c563ef commit 367cef0
Showing 1 changed file with 42 additions and 10 deletions.
52 changes: 42 additions & 10 deletions tests/testthat/test-utils-na_as.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,50 @@
test_that("na_as() | general test", {
expect_equal(na_as(TRUE),as.logical(NA))
expect_equal(na_as(""),as.character(NA))
expect_equal(na_as(1L),as.integer(NA))
expect_equal(na_as(1),as.numeric(NA))
expect_equal(na_as(lubridate::dhours()), lubridate::as.duration(NA))
expect_equal(na_as(lubridate::hours()), lubridate::as.period(NA))
# Nonexistent method error
expect_error(na_as(list(NA)))
})

test_that("na_as.logical() | general test", {
expect_equal(na_as(logical()),as.logical(NA))
})

test_that("na_as.character() | general test", {
expect_equal(na_as(character()),as.character(NA))
})

test_that("na_as.integer() | general test", {
expect_equal(na_as(integer()),as.integer(NA))
})

test_that("na_as.numeric() | general test", {
expect_equal(na_as(numeric()),as.numeric(NA))
})

test_that("na_as.Duration() | general test", {
expect_equal(na_as(lubridate::duration()), lubridate::as.duration(NA))
})

test_that("na_as.Period() | general test", {
expect_equal(na_as(lubridate::period()), lubridate::as.period(NA))
})

test_that("na_as.difftime() | general test", {
expect_equal(na_as(as.difftime(1, units = "secs")),
as.difftime(as.numeric(NA), units = "secs"))
expect_equal(na_as(hms::hms(1)), hms::as_hms(NA))
})

test_that("na_as.hms() | general test", {
expect_equal(na_as(hms::hms()), hms::as_hms(NA))
})

test_that("na_as.Date() | general test", {
expect_equal(na_as(as.Date("1970-01-01")), as.Date(NA))
})

test_that("na_as.POSIXct() | general test", {
expect_equal(na_as(lubridate::as_datetime(0)), lubridate::as_datetime(NA))
})

test_that("na_as.POSIXlt() | general test", {
expect_equal(na_as(as.POSIXlt(lubridate::as_datetime(0))),
as.POSIXlt(lubridate::as_datetime(NA)))

# Nonexistent method error
expect_error(na_as(list(NA)))
})

0 comments on commit 367cef0

Please sign in to comment.