Skip to content

Commit

Permalink
extra input validation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hillalex committed Jul 14, 2024
1 parent 02d016c commit a6c2c4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/scova.R
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ scova <- R6::R6Class(
if (is.null(data)) {
private$data <- data.table::fread(file_path)
} else {
if (!is.data.frame(data)) {
stop("'data' must be a data frame")
if (!data.table::is.data.table(data)) {
stop("'data' must be a data.table")
}
private$data <- data
}
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-input-validation.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,20 @@ test_that("Time type must be 'absolute' or 'relative'", {
"'time_type' must be one of 'relative' or 'absolute'")
})

test_that("Covariate formula must be a formula", {
dat <- data.table(test = 1)
expect_error(scova$new(data = dat, covariate_formula = "bad"),
"'covariate_formula' must be a formula")
})

test_that("Covariates must be present in data", {
dat <- data.table(test = 1)
expect_error(scova$new(data = dat, covariate_formula = 0~ bad),
"All variables in 'covariate_formula' must correspond to data columns. Found unknown variables: bad")
})

test_that("Data must be a data.table", {
dat <- data.frame(test = 1)
expect_error(scova$new(data = dat),
"'data' must be a data.table")
})

0 comments on commit a6c2c4d

Please sign in to comment.