start testing
This commit is contained in:
parent
481930aabe
commit
a21b9bd246
|
@ -19,3 +19,5 @@ Imports:
|
||||||
RoxygenNote: 6.1.1
|
RoxygenNote: 6.1.1
|
||||||
URL: https://github.com/dreamRs/apexcharter
|
URL: https://github.com/dreamRs/apexcharter
|
||||||
BugReports: https://github.com/dreamRs/apexcharter/issues
|
BugReports: https://github.com/dreamRs/apexcharter/issues
|
||||||
|
Suggests:
|
||||||
|
testthat
|
||||||
|
|
|
@ -18,8 +18,8 @@ parse_df <- function(data, add_names = FALSE) {
|
||||||
FUN = function(x) {
|
FUN = function(x) {
|
||||||
if (inherits(x, "Date") & identical(add_names, FALSE)) {
|
if (inherits(x, "Date") & identical(add_names, FALSE)) {
|
||||||
as.numeric(x) * 86400000
|
as.numeric(x) * 86400000
|
||||||
} else if (inherits(x, "POSIXt") & identical(add_names, FALSE)) {
|
} else if (inherits(x, "POSIXt")) {
|
||||||
as.numeric(x)
|
as.numeric(x) * 1000
|
||||||
} else if (inherits(x, "factor")) {
|
} else if (inherits(x, "factor")) {
|
||||||
as.character(x)
|
as.character(x)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
library(testthat)
|
||||||
|
library(apexcharter)
|
||||||
|
|
||||||
|
test_check("apexcharter")
|
|
@ -0,0 +1,55 @@
|
||||||
|
context("test-parse_df")
|
||||||
|
|
||||||
|
test_that("parse_df works", {
|
||||||
|
|
||||||
|
x <- head(iris)
|
||||||
|
res <- parse_df(x)
|
||||||
|
|
||||||
|
expect_is(res, "list")
|
||||||
|
expect_length(res, nrow(x))
|
||||||
|
expect_length(res[[1]], ncol(x))
|
||||||
|
expect_named(res[[1]], NULL)
|
||||||
|
})
|
||||||
|
|
||||||
|
test_that("parse_df works with names", {
|
||||||
|
|
||||||
|
x <- head(iris)
|
||||||
|
res <- parse_df(x, add_names = TRUE)
|
||||||
|
|
||||||
|
expect_is(res, "list")
|
||||||
|
expect_length(res, nrow(x))
|
||||||
|
expect_length(res[[1]], ncol(x))
|
||||||
|
expect_named(res[[1]], names(x))
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
test_that("parse_df works with custom names", {
|
||||||
|
|
||||||
|
x <- head(iris)
|
||||||
|
custom <- LETTERS[1:5]
|
||||||
|
res <- parse_df(x, add_names = custom)
|
||||||
|
|
||||||
|
expect_is(res, "list")
|
||||||
|
expect_length(res, nrow(x))
|
||||||
|
expect_length(res[[1]], ncol(x))
|
||||||
|
expect_named(res[[1]], custom)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
test_that("parse_df works with Date/POSIXt", {
|
||||||
|
|
||||||
|
x <- data.frame(
|
||||||
|
date = Sys.Date() + 1:5,
|
||||||
|
datetime = Sys.time() + 1:5
|
||||||
|
)
|
||||||
|
res <- parse_df(x, add_names = TRUE)
|
||||||
|
|
||||||
|
expect_is(res[[1]]$date, "Date")
|
||||||
|
expect_is(res[[1]]$datetime, "numeric")
|
||||||
|
|
||||||
|
res <- parse_df(x, add_names = FALSE)
|
||||||
|
expect_is(res[[1]][[1]], "numeric")
|
||||||
|
expect_is(res[[1]][[2]], "numeric")
|
||||||
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue