From 3b7c9edc195ed8305a0af30219f32b0770c22db3 Mon Sep 17 00:00:00 2001 From: Stefan Bundfuss Date: Tue, 3 Dec 2024 11:42:17 +0000 Subject: [PATCH] #473 assert_length: improve coverage --- tests/testthat/_snaps/assertions.md | 52 +++---- tests/testthat/test-assertions.R | 232 ++++++++++++++-------------- 2 files changed, 146 insertions(+), 138 deletions(-) diff --git a/tests/testthat/_snaps/assertions.md b/tests/testthat/_snaps/assertions.md index 67b53575..fdd6048d 100644 --- a/tests/testthat/_snaps/assertions.md +++ b/tests/testthat/_snaps/assertions.md @@ -212,7 +212,7 @@ Error in `example_fun()`: ! Argument `arg` must be an integer scalar. -# assert_numeric_vector Test 37: error if `arg` is not a numeric vector +# assert_numeric_vector Test 38: error if `arg` is not a numeric vector Code example_fun(TRUE) @@ -236,7 +236,7 @@ Error in `example_fun()`: ! Argument `arg` must be a numeric vector, but it is a string. -# assert_numeric_vector Test 38: error if length is not as expected +# assert_numeric_vector Test 39: error if length is not as expected Code assert_numeric_vector(numbers, length = 2) @@ -244,7 +244,7 @@ Error: ! Argument `numbers` must be a vector of length 2, but has length 3. -# assert_s3_class Test 39: error if `arg` is not an object of a specific class S3 +# assert_s3_class Test 40: error if `arg` is not an object of a specific class S3 Code example_fun("test") @@ -252,7 +252,7 @@ Error in `example_fun()`: ! Argument `arg` must be class , but is a string. -# assert_s3_class Test 41: error if `arg` is NULL and optional is FALSE +# assert_s3_class Test 42: error if `arg` is NULL and optional is FALSE Code example_fun(NULL) @@ -260,7 +260,7 @@ Error in `example_fun()`: ! Argument `arg` must be class , but is NULL. -# assert_list_of Test 43: error if `arg` is not a list of specific class S3 objects +# assert_list_of Test 44: error if `arg` is not a list of specific class S3 objects Code example_fun(list("test")) @@ -269,7 +269,7 @@ ! Each element of the list in argument `arg` must be class/type . i But, element 1 is a string -# assert_list_of Test 45: error if `arg` is NULL and optional is FALSE +# assert_list_of Test 46: error if `arg` is NULL and optional is FALSE Code example_fun(NULL) @@ -277,7 +277,7 @@ Error in `example_fun()`: ! Argument `arg` must be class , but is NULL. -# assert_list_of Test 47: error if `arg` is not a named list (no elements named) +# assert_list_of Test 48: error if `arg` is not a named list (no elements named) Code mylist <- list(1, 2, 3) @@ -287,7 +287,7 @@ ! All elements of `mylist` argument must be named. i The indices of the unnamed elements are 1, 2, and 3 -# assert_list_of Test 48: error if `arg` is not a named list (some elements named) +# assert_list_of Test 49: error if `arg` is not a named list (some elements named) Code mylist <- list(1, 2, 3, d = 4) @@ -297,7 +297,7 @@ ! All elements of `mylist` argument must be named. i The indices of the unnamed elements are 1, 2, and 3 -# assert_named Test 51: error if no elements are named +# assert_named Test 52: error if no elements are named Code arg <- c(1, 2) @@ -307,7 +307,7 @@ ! All elements of `arg` argument must be named. i The indices of the unnamed elements are 1 and 2 -# assert_function Test 52: error if `arg` is not a function +# assert_function Test 53: error if `arg` is not a function Code example_fun(5) @@ -315,7 +315,7 @@ Error in `example_fun()`: ! Argument `arg` must be a function, but is a number. -# assert_function Test 55: error if `params` is missing with no default +# assert_function Test 56: error if `params` is missing with no default Code example_fun(sum) @@ -331,7 +331,7 @@ Error in `example_fun()`: ! "x" and "y" are not arguments of the function specified for `arg`. -# assert_unit Test 60: error if multiple units in the input dataset +# assert_unit Test 61: error if multiple units in the input dataset Code assert_unit(advs, param = "WEIGHT", get_unit_expr = VSSTRESU) @@ -339,7 +339,7 @@ Error: ! Multiple units "kg" and "lb" found for "WEIGHT". Please review and update the units. -# assert_unit Test 61: error if unexpected unit in the input dataset +# assert_unit Test 62: error if unexpected unit in the input dataset Code assert_unit(advs, param = "WEIGHT", required_unit = "lb", get_unit_expr = VSSTRESU) @@ -347,7 +347,7 @@ Error: ! It is expected that "WEIGHT" has unit of "lb". In the input dataset the unit is "kg". -# assert_unit Test 62: error if get_unit_expr invalid +# assert_unit Test 63: error if get_unit_expr invalid Code assert_unit(advs, param = "WEIGHT", required_unit = "kg", get_unit_expr = VSTRESU) @@ -357,7 +357,7 @@ See error message below: i In argument: `_unit = VSTRESU`. Caused by error: ! object 'VSTRESU' not found -# assert_param_does_not_exist Test 63: error if parameter exists in the input dataset +# assert_param_does_not_exist Test 64: error if parameter exists in the input dataset Code assert_param_does_not_exist(advs, param = "WEIGHT") @@ -365,7 +365,7 @@ Error: ! The parameter code "WEIGHT" already exists in dataset `advs`. -# assert_varval_list Test 65: error if `arg` is not a list of var-value expressions +# assert_varval_list Test 66: error if `arg` is not a list of expressions Code example_fun(c("USUBJID", "PARAMCD", "VISIT")) @@ -374,7 +374,7 @@ ! Argument `arg` must be a named list of expressions where each element is a symbol, character scalar, numeric scalar, an expression, or NA, but is a character vector. i To create a list of expressions use `exprs()`. -# assert_varval_list Test 66: error if `arg` is not a list of var-value expressions +# assert_varval_list Test 67: error if not all elements are variables Code example_fun(exprs(USUBJID, PARAMCD, NULL)) @@ -383,7 +383,7 @@ ! Argument `arg` must be a list of expressions where each element is a symbol, character scalar, numeric scalar, an expression, or NA, but is a list. i To create a list of expressions use `exprs()`. -# assert_varval_list Test 67: error if `required_elements` are missing from `arg` +# assert_varval_list Test 68: error if `required_elements` are missing from `arg` Code example_fun(exprs(DTHSEQ = AESEQ)) @@ -391,7 +391,7 @@ Error in `example_fun()`: ! The following required elements are missing from argument `arg`: "DTHDOM". -# assert_varval_list Test 69: error if `accept_expr` is TRUE and value is invalid +# assert_varval_list Test 70: error if `accept_expr` is TRUE and value is invalid Code example_fun(exprs(DTHSEQ = TRUE)) @@ -400,7 +400,7 @@ ! The elements of the list in argument `arg` must be a symbol, character scalar, numeric scalar, an expression, or NA. i "DTHSEQ" = `TRUE` is of type -# assert_varval_list Test 70: error if `accept_expr` is FALSE and value is invalid +# assert_varval_list Test 71: error if `accept_expr` is FALSE and value is invalid Code example_fun(exprs(DTHSEQ = exprs())) @@ -409,7 +409,7 @@ ! The elements of the list in argument `arg` must be a symbol, character scalar, numeric scalar, or NA. i "DTHSEQ" = `exprs()` is of type -# assert_list_element Test 79: error if the elements do not fulfill the condition +# assert_list_element Test 80: error if the elements do not fulfill the condition Code assert_list_element(list(list(var = expr(DTHDT), val = 1), list(var = expr( @@ -433,7 +433,7 @@ ! List element "val" must one of 0 and 1 in argument `input`. i But, `input[[2]]$val = -1`, and `input[[3]]$val = -2` -# assert_one_to_one Test 80: error if there is a one to many mapping +# assert_one_to_one Test 81: error if there is a one to many mapping Code assert_one_to_one(dm, exprs(DOMAIN), exprs(USUBJID)) @@ -442,7 +442,7 @@ ! For some values of "DOMAIN" there is more than one value of "USUBJID" i Call `admiral::get_one_to_many_dataset()` to get all one-to-many values. -# assert_date_var Test 83: error if variable is not a date or datetime variable +# assert_date_var Test 84: error if variable is not a date or datetime variable Code example_fun(dataset = my_data, var = USUBJID) @@ -450,7 +450,7 @@ Error in `example_fun()`: ! Column "USUBJID" in dataset `dataset` must be a date or datetime, but is a character vector. -# assert_date_vector Test 87: error if `arg` is NULL and optional is FALSE +# assert_date_vector Test 88: error if `arg` is NULL and optional is FALSE Code example_fun(NULL) @@ -458,7 +458,7 @@ Error in `example_fun()`: ! Argument `arg` must be a date or datetime, but is NULL. -# assert_atomic_vector Test 88: error if input is not atomic vector +# assert_atomic_vector Test 89: error if input is not atomic vector Code assert_atomic_vector(x) @@ -466,7 +466,7 @@ Error: ! Argument `x` must be an atomic vector, but is a list. -# assert_same_type Test 90: error if different type +# assert_same_type Test 91: error if different type Code assert_same_type(true_value, false_value, missing_value) diff --git a/tests/testthat/test-assertions.R b/tests/testthat/test-assertions.R index 6ee7428d..79ae6b42 100644 --- a/tests/testthat/test-assertions.R +++ b/tests/testthat/test-assertions.R @@ -685,8 +685,16 @@ test_that("assert_integer_scalar Test 35: error if `arg` is not an integer scala }) # assert_numeric_vector ---- -## Test 36: no error if `arg` is NULL and optional is TRUE ---- -test_that("assert_numeric_vector Test 36: no error if `arg` is NULL and optional is TRUE", { + +## Test 36: no error for expected input ---- +test_that("assert_numeric_vector Test 36: no error for expected input", { + expect_invisible( + assert_numeric_vector(c(0, 1), length = 2) + ) +}) + +## Test 37: no error if `arg` is NULL and optional is TRUE ---- +test_that("assert_numeric_vector Test 37: no error if `arg` is NULL and optional is TRUE", { example_fun <- function(arg) { assert_numeric_vector(arg, optional = TRUE) } @@ -696,8 +704,8 @@ test_that("assert_numeric_vector Test 36: no error if `arg` is NULL and optional ) }) -## Test 37: error if `arg` is not a numeric vector ---- -test_that("assert_numeric_vector Test 37: error if `arg` is not a numeric vector", { +## Test 38: error if `arg` is not a numeric vector ---- +test_that("assert_numeric_vector Test 38: error if `arg` is not a numeric vector", { example_fun <- function(arg) { assert_numeric_vector(arg) } @@ -732,8 +740,8 @@ test_that("assert_numeric_vector Test 37: error if `arg` is not a numeric vector ) }) -## Test 38: error if length is not as expected ---- -test_that("assert_numeric_vector Test 38: error if length is not as expected", { +## Test 39: error if length is not as expected ---- +test_that("assert_numeric_vector Test 39: error if length is not as expected", { numbers <- c(1, 2, 3) expect_snapshot( assert_numeric_vector( @@ -745,8 +753,8 @@ test_that("assert_numeric_vector Test 38: error if length is not as expected", { }) # assert_s3_class ---- -## Test 39: error if `arg` is not an object of a specific class S3 ---- -test_that("assert_s3_class Test 39: error if `arg` is not an object of a specific class S3", { +## Test 40: error if `arg` is not an object of a specific class S3 ---- +test_that("assert_s3_class Test 40: error if `arg` is not an object of a specific class S3", { example_fun <- function(arg) { assert_s3_class(arg, "factor") } @@ -761,8 +769,8 @@ test_that("assert_s3_class Test 39: error if `arg` is not an object of a specifi ) }) -## Test 40: no error if `arg` is NULL and optional is TRUE ---- -test_that("assert_s3_class Test 40: no error if `arg` is NULL and optional is TRUE", { +## Test 41: no error if `arg` is NULL and optional is TRUE ---- +test_that("assert_s3_class Test 41: no error if `arg` is NULL and optional is TRUE", { example_fun <- function(arg) { assert_s3_class(arg, cls = "factor", optional = TRUE) } @@ -772,8 +780,8 @@ test_that("assert_s3_class Test 40: no error if `arg` is NULL and optional is TR ) }) -## Test 41: error if `arg` is NULL and optional is FALSE ---- -test_that("assert_s3_class Test 41: error if `arg` is NULL and optional is FALSE", { +## Test 42: error if `arg` is NULL and optional is FALSE ---- +test_that("assert_s3_class Test 42: error if `arg` is NULL and optional is FALSE", { example_fun <- function(arg) { assert_s3_class(arg, cls = "factor", optional = FALSE) } @@ -785,8 +793,8 @@ test_that("assert_s3_class Test 41: error if `arg` is NULL and optional is FALSE expect_snapshot(example_fun(NULL), error = TRUE) }) -## Test 42: no error if `arg` is an object of a specific class S3 ---- -test_that("assert_s3_class Test 42: no error if `arg` is an object of a specific class S3", { +## Test 43: no error if `arg` is an object of a specific class S3 ---- +test_that("assert_s3_class Test 43: no error if `arg` is an object of a specific class S3", { example_fun <- function(arg) { assert_s3_class(arg, "factor") } @@ -795,8 +803,8 @@ test_that("assert_s3_class Test 42: no error if `arg` is an object of a specific }) # assert_list_of ---- -## Test 43: error if `arg` is not a list of specific class S3 objects ---- -test_that("assert_list_of Test 43: error if `arg` is not a list of specific class S3 objects", { +## Test 44: error if `arg` is not a list of specific class S3 objects ---- +test_that("assert_list_of Test 44: error if `arg` is not a list of specific class S3 objects", { example_fun <- function(arg) { assert_list_of(arg, "factor") } @@ -811,8 +819,8 @@ test_that("assert_list_of Test 43: error if `arg` is not a list of specific clas ) }) -## Test 44: no error if `arg` is NULL and optional is TRUE ---- -test_that("assert_list_of Test 44: no error if `arg` is NULL and optional is TRUE", { +## Test 45: no error if `arg` is NULL and optional is TRUE ---- +test_that("assert_list_of Test 45: no error if `arg` is NULL and optional is TRUE", { example_fun <- function(arg) { assert_list_of(arg, cls = "factor", optional = TRUE) } @@ -822,8 +830,8 @@ test_that("assert_list_of Test 44: no error if `arg` is NULL and optional is TRU ) }) -## Test 45: error if `arg` is NULL and optional is FALSE ---- -test_that("assert_list_of Test 45: error if `arg` is NULL and optional is FALSE", { +## Test 46: error if `arg` is NULL and optional is FALSE ---- +test_that("assert_list_of Test 46: error if `arg` is NULL and optional is FALSE", { example_fun <- function(arg) { assert_list_of(arg, cls = "factor", optional = FALSE) } @@ -835,8 +843,8 @@ test_that("assert_list_of Test 45: error if `arg` is NULL and optional is FALSE" expect_snapshot(example_fun(NULL), error = TRUE) }) -## Test 46: no error if `arg` is a list of specific class S3 objects ---- -test_that("assert_list_of Test 46: no error if `arg` is a list of specific class S3 objects", { +## Test 47: no error if `arg` is a list of specific class S3 objects ---- +test_that("assert_list_of Test 47: no error if `arg` is a list of specific class S3 objects", { example_fun <- function(arg) { assert_list_of(arg, "factor") } @@ -848,8 +856,8 @@ test_that("assert_list_of Test 46: no error if `arg` is a list of specific class ) }) -## Test 47: error if `arg` is not a named list (no elements named) ---- -test_that("assert_list_of Test 47: error if `arg` is not a named list (no elements named)", { +## Test 48: error if `arg` is not a named list (no elements named) ---- +test_that("assert_list_of Test 48: error if `arg` is not a named list (no elements named)", { expect_error( { mylist <- list(1, 2, 3) @@ -866,8 +874,8 @@ test_that("assert_list_of Test 47: error if `arg` is not a named list (no elemen ) }) -## Test 48: error if `arg` is not a named list (some elements named) ---- -test_that("assert_list_of Test 48: error if `arg` is not a named list (some elements named)", { +## Test 49: error if `arg` is not a named list (some elements named) ---- +test_that("assert_list_of Test 49: error if `arg` is not a named list (some elements named)", { expect_error( { mylist <- list(1, 2, 3, d = 4) @@ -884,21 +892,21 @@ test_that("assert_list_of Test 48: error if `arg` is not a named list (some elem ) }) -## Test 49: no error if `arg` is a named list ---- -test_that("assert_list_of Test 49: no error if `arg` is a named list", { +## Test 50: no error if `arg` is a named list ---- +test_that("assert_list_of Test 50: no error if `arg` is a named list", { expect_invisible( assert_list_of(mylist <- list(a = 1, b = 2, c = 3), cls = "numeric", named = TRUE) ) }) # assert_named ---- -## Test 50: no error if arg is NULL and optional = TRUE ---- -test_that("assert_named Test 50: no error if arg is NULL and optional = TRUE", { +## Test 51: no error if arg is NULL and optional = TRUE ---- +test_that("assert_named Test 51: no error if arg is NULL and optional = TRUE", { expect_invisible(assert_named(arg <- NULL, optional = TRUE)) }) -## Test 51: error if no elements are named ---- -test_that("assert_named Test 51: error if no elements are named", { +## Test 52: error if no elements are named ---- +test_that("assert_named Test 52: error if no elements are named", { expect_error( { arg <- c(1, 2) @@ -917,8 +925,8 @@ test_that("assert_named Test 51: error if no elements are named", { }) # assert_function ---- -## Test 52: error if `arg` is not a function ---- -test_that("assert_function Test 52: error if `arg` is not a function", { +## Test 53: error if `arg` is not a function ---- +test_that("assert_function Test 53: error if `arg` is not a function", { example_fun <- function(arg) { assert_function(arg) } @@ -931,8 +939,8 @@ test_that("assert_function Test 52: error if `arg` is not a function", { expect_error(example_fun(), class = "assert_function") }) -## Test 53: no error if `arg` is NULL and optional is TRUE ---- -test_that("assert_function Test 53: no error if `arg` is NULL and optional is TRUE", { +## Test 54: no error if `arg` is NULL and optional is TRUE ---- +test_that("assert_function Test 54: no error if `arg` is NULL and optional is TRUE", { example_fun <- function(arg) { assert_function(arg, optional = TRUE) } @@ -942,8 +950,8 @@ test_that("assert_function Test 53: no error if `arg` is NULL and optional is TR ) }) -## Test 54: no error if `arg` is a function with all parameters defined ---- -test_that("assert_function Test 54: no error if `arg` is a function with all parameters defined", { +## Test 55: no error if `arg` is a function with all parameters defined ---- +test_that("assert_function Test 55: no error if `arg` is a function with all parameters defined", { example_fun <- function(arg) { assert_function(arg, params = c("x")) } @@ -951,8 +959,8 @@ test_that("assert_function Test 54: no error if `arg` is a function with all par expect_invisible(example_fun(mean)) }) -## Test 55: error if `params` is missing with no default ---- -test_that("assert_function Test 55: error if `params` is missing with no default", { +## Test 56: error if `params` is missing with no default ---- +test_that("assert_function Test 56: error if `params` is missing with no default", { example_fun <- function(arg) { assert_function(arg, params = c("x")) } @@ -980,8 +988,8 @@ test_that("assert_function Test 55: error if `params` is missing with no defau ) }) -## Test 56: If dot-dot-dot is a argument ---- -test_that("assert_function Test 56: If dot-dot-dot is a argument", { +## Test 57: If dot-dot-dot is a argument ---- +test_that("assert_function Test 57: If dot-dot-dot is a argument", { example_fun <- function(derivation, args = NULL) { assert_function(derivation, names(args)) } @@ -989,8 +997,8 @@ test_that("assert_function Test 56: If dot-dot-dot is a argument", { }) # assert_unit ---- -## Test 57: no error if the parameter is provided in the expected unit ---- -test_that("assert_unit Test 57: no error if the parameter is provided in the expected unit", { +## Test 58: no error if the parameter is provided in the expected unit ---- +test_that("assert_unit Test 58: no error if the parameter is provided in the expected unit", { advs <- dplyr::tribble( ~USUBJID, ~VSTESTCD, ~VSTRESN, ~VSSTRESU, ~PARAMCD, ~AVAL, "P01", "WEIGHT", 80.1, "kg", "WEIGHT", 80.1, @@ -1002,8 +1010,8 @@ test_that("assert_unit Test 57: no error if the parameter is provided in the exp ) }) -## Test 58: no error for multiple expected units ---- -test_that("assert_unit Test 58: no error for multiple expected units", { +## Test 59: no error for multiple expected units ---- +test_that("assert_unit Test 59: no error for multiple expected units", { advs <- dplyr::tribble( ~USUBJID, ~VSTESTCD, ~VSTRESN, ~VSSTRESU, ~PARAMCD, ~AVAL, "P01", "WEIGHT", 80.1, "kg", "WEIGHT", 80.1, @@ -1020,8 +1028,8 @@ test_that("assert_unit Test 58: no error for multiple expected units", { ) }) -## Test 59: no error if all units NA ---- -test_that("assert_unit Test 59: no error if all units NA", { +## Test 60: no error if all units NA ---- +test_that("assert_unit Test 60: no error if all units NA", { advs <- dplyr::tribble( ~USUBJID, ~VSTESTCD, ~VSTRESN, ~VSSTRESU, ~PARAMCD, ~AVAL, "P01", "RATIO", 80.1, NA_character_, "WEIGHT", 80.1, @@ -1038,8 +1046,8 @@ test_that("assert_unit Test 59: no error if all units NA", { ) }) -## Test 60: error if multiple units in the input dataset ---- -test_that("assert_unit Test 60: error if multiple units in the input dataset", { +## Test 61: error if multiple units in the input dataset ---- +test_that("assert_unit Test 61: error if multiple units in the input dataset", { advs <- dplyr::tribble( ~USUBJID, ~VSTESTCD, ~VSTRESN, ~VSSTRESU, ~PARAMCD, ~AVAL, "P01", "WEIGHT", 80.1, "kg", "WEIGHT", 80.1, @@ -1056,8 +1064,8 @@ test_that("assert_unit Test 60: error if multiple units in the input dataset", { ) }) -## Test 61: error if unexpected unit in the input dataset ---- -test_that("assert_unit Test 61: error if unexpected unit in the input dataset", { +## Test 62: error if unexpected unit in the input dataset ---- +test_that("assert_unit Test 62: error if unexpected unit in the input dataset", { advs <- dplyr::tribble( ~USUBJID, ~VSTESTCD, ~VSTRESN, ~VSSTRESU, ~PARAMCD, ~AVAL, "P01", "WEIGHT", 80.1, "kg", "WEIGHT", 80.1, @@ -1074,8 +1082,8 @@ test_that("assert_unit Test 61: error if unexpected unit in the input dataset", ) }) -## Test 62: error if get_unit_expr invalid ---- -test_that("assert_unit Test 62: error if get_unit_expr invalid", { +## Test 63: error if get_unit_expr invalid ---- +test_that("assert_unit Test 63: error if get_unit_expr invalid", { advs <- dplyr::tribble( ~USUBJID, ~VSTESTCD, ~VSTRESN, ~VSSTRESU, ~PARAMCD, ~AVAL, "P01", "WEIGHT", 80.1, "kg", "WEIGHT", 80.1, @@ -1093,8 +1101,8 @@ test_that("assert_unit Test 62: error if get_unit_expr invalid", { }) # assert_param_does_not_exist ---- -## Test 63: error if parameter exists in the input dataset ---- -test_that("assert_param_does_not_exist Test 63: error if parameter exists in the input dataset", { +## Test 64: error if parameter exists in the input dataset ---- +test_that("assert_param_does_not_exist Test 64: error if parameter exists in the input dataset", { advs <- dplyr::tribble( ~USUBJID, ~VSTESTCD, ~VSTRESN, ~VSSTRESU, ~PARAMCD, ~AVAL, "P01", "WEIGHT", 80.1, "kg", "WEIGHT", 80.1, @@ -1112,8 +1120,8 @@ test_that("assert_param_does_not_exist Test 63: error if parameter exists in the ) }) -## Test 64: no error if the parameter exists in the dataset ---- -test_that("assert_param_does_not_exist Test 64: no error if the parameter exists in the dataset", { +## Test 65: no error if the parameter exists in the dataset ---- +test_that("assert_param_does_not_exist Test 65: no error if the parameter exists in the dataset", { advs <- dplyr::tribble( ~USUBJID, ~VSTESTCD, ~VSTRESN, ~VSSTRESU, ~PARAMCD, ~AVAL, "P01", "WEIGHT", 80.1, "kg", "WEIGHT", 80.1, @@ -1126,8 +1134,8 @@ test_that("assert_param_does_not_exist Test 64: no error if the parameter exists }) # assert_varval_list ---- -## Test 65: error if `arg` is not a list of var-value expressions ---- -test_that("assert_varval_list Test 65: error if `arg` is not a list of var-value expressions", { +## Test 66: error if `arg` is not a list of expressions ---- +test_that("assert_varval_list Test 66: error if `arg` is not a list of expressions", { example_fun <- function(arg) { assert_varval_list(arg, accept_var = FALSE) } @@ -1142,8 +1150,8 @@ test_that("assert_varval_list Test 65: error if `arg` is not a list of var-value ) }) -## Test 66: error if `arg` is not a list of var-value expressions ---- -test_that("assert_varval_list Test 66: error if `arg` is not a list of var-value expressions", { +## Test 67: error if not all elements are variables ---- +test_that("assert_varval_list Test 67: error if not all elements are variables", { example_fun <- function(arg) { assert_varval_list(arg, accept_var = TRUE) } @@ -1158,8 +1166,8 @@ test_that("assert_varval_list Test 66: error if `arg` is not a list of var-value ) }) -## Test 67: error if `required_elements` are missing from `arg` ---- -test_that("assert_varval_list Test 67: error if `required_elements` are missing from `arg`", { +## Test 68: error if `required_elements` are missing from `arg` ---- +test_that("assert_varval_list Test 68: error if `required_elements` are missing from `arg`", { example_fun <- function(arg) { assert_varval_list(arg, required_elements = "DTHDOM") } @@ -1174,8 +1182,8 @@ test_that("assert_varval_list Test 67: error if `required_elements` are missing ) }) -## Test 68: no error if `arg` is NULL and optional is TRUE ---- -test_that("assert_varval_list Test 68: no error if `arg` is NULL and optional is TRUE", { +## Test 69: no error if `arg` is NULL and optional is TRUE ---- +test_that("assert_varval_list Test 69: no error if `arg` is NULL and optional is TRUE", { example_fun <- function(arg) { assert_varval_list(arg, optional = TRUE) } @@ -1185,8 +1193,8 @@ test_that("assert_varval_list Test 68: no error if `arg` is NULL and optional is ) }) -## Test 69: error if `accept_expr` is TRUE and value is invalid ---- -test_that("assert_varval_list Test 69: error if `accept_expr` is TRUE and value is invalid", { +## Test 70: error if `accept_expr` is TRUE and value is invalid ---- +test_that("assert_varval_list Test 70: error if `accept_expr` is TRUE and value is invalid", { example_fun <- function(arg) { assert_varval_list(arg, accept_expr = TRUE) } @@ -1201,8 +1209,8 @@ test_that("assert_varval_list Test 69: error if `accept_expr` is TRUE and value ) }) -## Test 70: error if `accept_expr` is FALSE and value is invalid ---- -test_that("assert_varval_list Test 70: error if `accept_expr` is FALSE and value is invalid", { +## Test 71: error if `accept_expr` is FALSE and value is invalid ---- +test_that("assert_varval_list Test 71: error if `accept_expr` is FALSE and value is invalid", { example_fun <- function(arg) { assert_varval_list(arg, accept_expr = FALSE) } @@ -1217,8 +1225,8 @@ test_that("assert_varval_list Test 70: error if `accept_expr` is FALSE and value ) }) -## Test 71: no error if an argument is a variable-value list ---- -test_that("assert_varval_list Test 71: no error if an argument is a variable-value list", { +## Test 72: no error if an argument is a variable-value list ---- +test_that("assert_varval_list Test 72: no error if an argument is a variable-value list", { example_fun <- function(arg) { assert_varval_list(arg) } @@ -1229,24 +1237,24 @@ test_that("assert_varval_list Test 71: no error if an argument is a variable-val }) # assert_expr_list ---- -## Test 72: error if `arg` is not a list of expressions ---- -test_that("assert_expr_list Test 72: error if `arg` is not a list of expressions", { +## Test 73: error if `arg` is not a list of expressions ---- +test_that("assert_expr_list Test 73: error if `arg` is not a list of expressions", { expect_error( assert_expr_list(arg <- c("USUBJID", "PARAMCD", "VISIT")), class = "assert_expr_list" ) }) -## Test 73: error if `arg` is not a named list of expressions ---- -test_that("assert_expr_list Test 73: error if `arg` is not a named list of expressions", { +## Test 74: error if `arg` is not a named list of expressions ---- +test_that("assert_expr_list Test 74: error if `arg` is not a named list of expressions", { expect_error( assert_expr_list(arg <- exprs(USUBJID, PARAMCD, NULL), named = TRUE), regexp = "argument must be named" ) }) -## Test 74: error if `required_elements` are missing from `arg` ---- -test_that("assert_expr_list Test 74: error if `required_elements` are missing from `arg`", { +## Test 75: error if `required_elements` are missing from `arg` ---- +test_that("assert_expr_list Test 75: error if `required_elements` are missing from `arg`", { expect_error( assert_expr_list( arg <- exprs(DTHSEQ = AESEQ), @@ -1256,23 +1264,23 @@ test_that("assert_expr_list Test 74: error if `required_elements` are missing fr ) }) -## Test 75: no error if `arg` is NULL and optional is TRUE ---- -test_that("assert_expr_list Test 75: no error if `arg` is NULL and optional is TRUE", { +## Test 76: no error if `arg` is NULL and optional is TRUE ---- +test_that("assert_expr_list Test 76: no error if `arg` is NULL and optional is TRUE", { expect_invisible( assert_expr_list(NULL, optional = TRUE) ) }) -## Test 76: error if element is invalid ---- -test_that("assert_expr_list Test 76: error if element is invalid", { +## Test 77: error if element is invalid ---- +test_that("assert_expr_list Test 77: error if element is invalid", { expect_error( assert_expr_list(arg <- exprs(DTHSEQ = !!mean)), class = "assert_expr_list" ) }) -## Test 77: no error if argument is valid ---- -test_that("assert_expr_list Test 77: no error if argument is valid", { +## Test 78: no error if argument is valid ---- +test_that("assert_expr_list Test 78: no error if argument is valid", { expect_invisible( assert_expr_list(arg <- exprs( DTHDOM = "AE", @@ -1283,8 +1291,8 @@ test_that("assert_expr_list Test 77: no error if argument is valid", { }) # assert_list_element ---- -## Test 78: no error if the elements fulfill a certain condition ---- -test_that("assert_list_element Test 78: no error if the elements fulfill a certain condition", { +## Test 79: no error if the elements fulfill a certain condition ---- +test_that("assert_list_element Test 79: no error if the elements fulfill a certain condition", { expect_invisible( assert_list_element( list( @@ -1298,8 +1306,8 @@ test_that("assert_list_element Test 78: no error if the elements fulfill a certa ) }) -## Test 79: error if the elements do not fulfill the condition ---- -test_that("assert_list_element Test 79: error if the elements do not fulfill the condition", { +## Test 80: error if the elements do not fulfill the condition ---- +test_that("assert_list_element Test 80: error if the elements do not fulfill the condition", { expect_snapshot( assert_list_element( list( @@ -1335,8 +1343,8 @@ test_that("assert_list_element Test 79: error if the elements do not fulfill the }) # assert_one_to_one ---- -## Test 80: error if there is a one to many mapping ---- -test_that("assert_one_to_one Test 80: error if there is a one to many mapping", { +## Test 81: error if there is a one to many mapping ---- +test_that("assert_one_to_one Test 81: error if there is a one to many mapping", { dm <- dplyr::tribble( ~DOMAIN, ~USUBJID, "DM", "01-701-1015", @@ -1358,8 +1366,8 @@ test_that("assert_one_to_one Test 80: error if there is a one to many mapping", admiraldev_environment$one_to_many <- NULL }) -## Test 81: error if there is a many to one mapping ---- -test_that("assert_one_to_one Test 81: error if there is a many to one mapping", { +## Test 82: error if there is a many to one mapping ---- +test_that("assert_one_to_one Test 82: error if there is a many to one mapping", { dm <- dplyr::tribble( ~DOMAIN, ~USUBJID, "DM", "01-701-1015", @@ -1375,8 +1383,8 @@ test_that("assert_one_to_one Test 81: error if there is a many to one mapping", admiraldev_environment$many_to_one <- NULL }) -## Test 82: dataset is returned invisible if one-to-one ---- -test_that("assert_one_to_one Test 82: dataset is returned invisible if one-to-one", { +## Test 83: dataset is returned invisible if one-to-one ---- +test_that("assert_one_to_one Test 83: dataset is returned invisible if one-to-one", { df <- dplyr::tribble( ~SPECIES, ~SPECIESN, "DOG", 1L, @@ -1392,8 +1400,8 @@ test_that("assert_one_to_one Test 82: dataset is returned invisible if one-to-on }) # assert_date_var ---- -## Test 83: error if variable is not a date or datetime variable ---- -test_that("assert_date_var Test 83: error if variable is not a date or datetime variable", { +## Test 84: error if variable is not a date or datetime variable ---- +test_that("assert_date_var Test 84: error if variable is not a date or datetime variable", { example_fun <- function(dataset, var) { var <- assert_symbol(enexpr(var)) assert_date_var(dataset = dataset, var = !!var) @@ -1421,18 +1429,18 @@ test_that("assert_date_var Test 83: error if variable is not a date or datetime }) # assert_date_vector ---- -## Test 84: returns error if input vector is not a date formatted ---- -test_that("assert_date_vector Test 84: returns error if input vector is not a date formatted", { +## Test 85: returns error if input vector is not a date formatted ---- +test_that("assert_date_vector Test 85: returns error if input vector is not a date formatted", { expect_error(assert_date_vector("2018-08-23")) }) -## Test 85: returns invisible if input is date formatted ---- -test_that("assert_date_vector Test 85: returns invisible if input is date formatted", { +## Test 86: returns invisible if input is date formatted ---- +test_that("assert_date_vector Test 86: returns invisible if input is date formatted", { expect_invisible(assert_date_vector(as.Date("2022-10-25"))) }) -## Test 86: no error if `arg` is NULL and optional is TRUE ---- -test_that("assert_date_vector Test 86: no error if `arg` is NULL and optional is TRUE", { +## Test 87: no error if `arg` is NULL and optional is TRUE ---- +test_that("assert_date_vector Test 87: no error if `arg` is NULL and optional is TRUE", { example_fun <- function(arg) { assert_date_vector(arg, optional = TRUE) } @@ -1442,8 +1450,8 @@ test_that("assert_date_vector Test 86: no error if `arg` is NULL and optional is ) }) -## Test 87: error if `arg` is NULL and optional is FALSE ---- -test_that("assert_date_vector Test 87: error if `arg` is NULL and optional is FALSE", { +## Test 88: error if `arg` is NULL and optional is FALSE ---- +test_that("assert_date_vector Test 88: error if `arg` is NULL and optional is FALSE", { example_fun <- function(arg) { assert_date_vector(arg, optional = FALSE) } @@ -1460,8 +1468,8 @@ test_that("assert_date_vector Test 87: error if `arg` is NULL and optional is FA # assert_atomic_vector ---- -## Test 88: error if input is not atomic vector ---- -test_that("assert_atomic_vector Test 88: error if input is not atomic vector", { +## Test 89: error if input is not atomic vector ---- +test_that("assert_atomic_vector Test 89: error if input is not atomic vector", { x <- list("a", "a", "b", "c", "d", "d", 1, 1, 4) expect_error(assert_atomic_vector(x), class = "assert_atomic_vector") expect_snapshot( @@ -1471,15 +1479,15 @@ test_that("assert_atomic_vector Test 88: error if input is not atomic vector", { }) # assert_same_type ---- -## Test 89: no error if same type ---- -test_that("assert_same_type Test 89: no error if same type", { +## Test 90: no error if same type ---- +test_that("assert_same_type Test 90: no error if same type", { true_value <- "Y" false_value <- "N" expect_invisible(assert_same_type(true_value, false_value)) }) -## Test 90: error if different type ---- -test_that("assert_same_type Test 90: error if different type", { +## Test 91: error if different type ---- +test_that("assert_same_type Test 91: error if different type", { true_value <- "Y" false_value <- "N" missing_value <- 0 @@ -1495,8 +1503,8 @@ test_that("assert_same_type Test 90: error if different type", { ) }) -## Test 91: works as intended ---- -test_that("assert_same_type Test 91: works as intended", { +## Test 92: works as intended ---- +test_that("assert_same_type Test 92: works as intended", { expect_equal( valid_time_units(), c("years", "months", "days", "hours", "minutes", "seconds")