Skip to content

Commit

Permalink
Write unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
seniort committed Apr 25, 2024
1 parent 43a67e7 commit ced13e3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/metacore.R
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ get_keys <- function(metacode, dataset){
subset_data <- metacode$ds_vars %>%
filter(dataset == dataset_val)
if(nrow(subset_data) == 0){
stop(paste0(dataset_val, " not found in the value_spec table. Please check the dataset name"))
stop(paste0(dataset_val, " not found in the ds_vars table. Please check the dataset name"))
}

keys <- subset_data %>%
Expand Down
1 change: 1 addition & 0 deletions man/get_keys.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions tests/testthat/test-metacore.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,18 @@ test_that("pulling out control terminology works", {
)
})

test_that("get_keys works", {
test <- spec_to_metacore(metacore_example("p21_mock.xlsx"), quiet = TRUE)
#Testing Errors
## Domain not in ds_vars table
expect_error(get_keys(test, DS))
## Missing dataset name
expect_error(get_keys(test))
#Testing Correct Output
expect_equal(
get_keys(test, DM),
tibble(variable = c("STUDYID", "USUBJID"), key_seq = c(1L, 2L)) %>%
add_labs(variable = "Variable Name",
key_seq = "Sequence Key")
)
})

0 comments on commit ced13e3

Please sign in to comment.