Skip to content

Commit

Permalink
Update assertions.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ddsjoberg committed Apr 27, 2024
1 parent a439afa commit 6075790
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions tests/testthat/_snaps/assertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
Error in `example_fun()`:
! Required variables `STUDYID` and `USUBJID` are missing in `dataset`

# assert_character_scalar Test 13: error if `arg` not in values
# assert_character_scalar Test 15: error if `arg` not in values

Code
check_unit("month")
Expand All @@ -54,39 +54,39 @@
Error in `check_unit2()`:
! Argument `duration_unit` must be equal to one of "YEARS", "MONTHS", "WEEKS", "DAYS", "HOURS", "MINUTES", or "SECONDS".

# assert_character_scalar Test 14: error if not character
# assert_character_scalar Test 16: error if not character

Code
example_fun2(2)
Condition
Error in `example_fun2()`:
! Argument `msg_type` must be a scalar of class <character>, but is a number.

# assert_character_scalar Test 15: error if input is a vector
# assert_character_scalar Test 17: error if input is a vector

Code
example_fun2(c("admiral", "admiralonco"))
Condition
Error in `example_fun2()`:
! Argument `msg_type` must be a scalar of class <character>, but is length 2

# assert_character_vector Test 16: error if `arg` not a character vector
# assert_character_vector Test 18: error if `arg` not a character vector

Code
assert_character_vector(arg)
Condition
Error:
! Argument `arg` must be <character>, but is a double vector.

# assert_character_vector Test 17: error if `arg` is not in values
# assert_character_vector Test 19: error if `arg` is not in values

Code
example_fun(character = c("oak", "mint"))
Condition
Error in `example_fun()`:
! Argument `character` must be <character> with values "test" and "oak".

# assert_character_vector Test 18: arg_name correctly displayed in name check
# assert_character_vector Test 20: arg_name correctly displayed in name check

Code
example_fun(character = c(tree = "oak", "test"))
Expand All @@ -95,31 +95,31 @@
! All elements of `character` argument must be named.
i The indices of the unnamed elements are 2

# assert_logical_scalar Test 20: error if `arg` is not TRUE or FALSE
# assert_logical_scalar Test 22: error if `arg` is not TRUE or FALSE

Code
example_fun("test")
Condition
Error in `example_fun()`:
! Argument `arg` must be either TRUE or FALSE, but is a string.

# assert_symbol Test 22: `assert_symbol` throws an error if `arg` is missing
# assert_symbol Test 24: `assert_symbol` throws an error if `arg` is missing

Code
example_fun(f())
Condition
Error in `example_fun()`:
! Argument `arg` must be a <symbol>, but is missing.

# assert_symbol Test 23: `assert_symbol` throws an error if `arg` is not a symbol
# assert_symbol Test 25: `assert_symbol` throws an error if `arg` is not a symbol

Code
example_fun(f(NULL))
Condition
Error in `example_fun()`:
! Argument `arg` must be a <symbol>, but is NULL.

# assert_expr Test 27: `assert_expr` throws an error if `arg` is missing
# assert_expr Test 29: `assert_expr` throws an error if `arg` is missing

Code
assert_expr()
Expand All @@ -135,7 +135,7 @@
Error in `example_fun()`:
! Argument `data` cannot be missing.

# assert_expr Test 28: `assert_expr` throws an error if `arg` is not an expression
# assert_expr Test 30: `assert_expr` throws an error if `arg` is not an expression

Code
var <- c(1, 2)
Expand All @@ -144,7 +144,7 @@
Error:
! Argument `var` must be an expression, but is a double vector

# assert_vars Test 30: error if unexpected input
# assert_vars Test 32: error if unexpected input

Code
assert_vars(AVAL + 1)
Expand Down Expand Up @@ -187,7 +187,7 @@
! All elements of `exprs(APERSDT = APxxSDT, APxxEDT)` argument must be named.
i The indices of the unnamed elements are 2

# assert_vars Test 31: error if some elements of `arg` are not unquoted variable names
# assert_vars Test 33: error if some elements of `arg` are not unquoted variable names

Code
example_fun(exprs(USUBJID, PARAMCD, NULL))
Expand All @@ -196,23 +196,23 @@
! Each element of the list in argument `arg` must be class/type <symbol>.
i But, element 3 is NULL

# assert_integer_scalar Test 33: error if chosen subset not in subsets
# assert_integer_scalar Test 35: error if chosen subset not in subsets

Code
example_fun(1)
Condition
Error in `assert_integer_scalar()`:
! Argument `subset` must be equal to one of "positive", "non-negative", "negative", or "none".

# assert_integer_scalar Test 35: error if `arg` is not an integer scalar
# assert_integer_scalar Test 37: error if `arg` is not an integer scalar

Code
example_fun(1.5)
Condition
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 39: error if `arg` is not a numeric vector

Code
example_fun(TRUE)
Expand All @@ -236,23 +236,23 @@
Error in `example_fun()`:
! Argument `arg` must be a numeric vector, but it is a string.

# assert_s3_class Test 38: 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")
Condition
Error in `example_fun()`:
! Argument `arg` must be class <factor>, but is a string.

# assert_s3_class Test 40: 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)
Condition
Error in `example_fun()`:
! Argument `arg` must be class <factor>, but is NULL.

# assert_list_of Test 42: 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"))
Expand All @@ -261,15 +261,15 @@
! Each element of the list in argument `arg` must be class/type <factor>.
i But, element 1 is a string

# assert_list_of Test 44: 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)
Condition
Error in `example_fun()`:
! Argument `arg` must be class <list>, but is NULL.

# assert_list_of Test 46: 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)
Expand All @@ -279,7 +279,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 47: 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)
Expand All @@ -289,7 +289,7 @@
! All elements of `mylist` argument must be named.
i The indices of the unnamed elements are 1, 2, and 3

# assert_named Test 50: error if no elements are named
# assert_named Test 52: error if no elements are named

Code
arg <- c(1, 2)
Expand All @@ -299,15 +299,15 @@
! All elements of `arg` argument must be named.
i The indices of the unnamed elements are 1 and 2

# assert_function Test 54: error if `arg` is not a function
# assert_function Test 56: error if `arg` is not a function

Code
example_fun(5)
Condition
Error in `example_fun()`:
! Argument `arg` must be a function, but is a number.

# assert_function Test 57: error if `params` is missing with no default
# assert_function Test 59: error if `params` is missing with no default

Code
example_fun(sum)
Expand All @@ -323,31 +323,31 @@
Error in `example_fun()`:
! "x" and "y" are not arguments of the function specified for `arg`.

# assert_unit Test 62: error if there are multiple units in the input dataset
# assert_unit Test 64: error if there are multiple units in the input dataset

Code
assert_unit(advs, param = "WEIGHT", required_unit = "kg", get_unit_expr = VSSTRESU)
Condition
Error:
! Multiple units "kg" and "lb" found for "WEIGHT". Please review and update the units.

# assert_unit Test 63: error if unexpected unit in the input dataset
# assert_unit Test 65: error if unexpected unit in the input dataset

Code
assert_unit(advs, param = "WEIGHT", required_unit = "lb", get_unit_expr = VSSTRESU)
Condition
Error:
! It is expected that "WEIGHT" has unit of "lb". In the input dataset the unit is "kg".

# assert_param_does_not_exist Test 64: error if parameter exists in the input dataset
# assert_param_does_not_exist Test 66: error if parameter exists in the input dataset

Code
assert_param_does_not_exist(advs, param = "WEIGHT")
Condition
Error:
! The parameter code "WEIGHT" already exists in dataset `advs`.

# assert_varval_list Test 66: error if `arg` is not a list of var-value expressions
# assert_varval_list Test 68: error if `arg` is not a list of var-value expressions

Code
example_fun(c("USUBJID", "PARAMCD", "VISIT"))
Expand All @@ -356,7 +356,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 67: error if `arg` is not a list of var-value expressions
# assert_varval_list Test 69: error if `arg` is not a list of var-value expressions

Code
example_fun(exprs(USUBJID, PARAMCD, NULL))
Expand All @@ -365,15 +365,15 @@
! 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 68: error if `required_elements` are missing from `arg`
# assert_varval_list Test 70: error if `required_elements` are missing from `arg`

Code
example_fun(exprs(DTHSEQ = AESEQ))
Condition
Error in `example_fun()`:
! The following required elements are missing from argument `arg`: "DTHDOM".

# assert_varval_list Test 70: error if `accept_expr` is TRUE and value is invalid
# assert_varval_list Test 72: error if `accept_expr` is TRUE and value is invalid

Code
example_fun(exprs(DTHSEQ = TRUE))
Expand All @@ -382,7 +382,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 <logical>

# assert_varval_list Test 71: error if `accept_expr` is FALSE and value is invalid
# assert_varval_list Test 73: error if `accept_expr` is FALSE and value is invalid

Code
example_fun(exprs(DTHSEQ = exprs()))
Expand All @@ -391,7 +391,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 <language>

# assert_list_element Test 80: error if the elements do not fulfill the condition
# assert_list_element Test 82: error if the elements do not fulfill the condition

Code
assert_list_element(list(list(var = expr(DTHDT), val = 1), list(var = expr(
Expand All @@ -403,7 +403,7 @@
! List element "val" must be `>=0` in argument `input`:
i But, `input[[2]]$val = -1`, and `input[[3]]$val = -2`

# assert_one_to_one Test 81: error if there is a one to many mapping
# assert_one_to_one Test 83: error if there is a one to many mapping

Code
assert_one_to_one(dm, exprs(DOMAIN), exprs(USUBJID))
Expand All @@ -412,31 +412,31 @@
! For some values of "DOMAIN" there is more than one value of "USUBJID"
i Call `get_one_to_many_dataset()` to get all one-to-many values.

# assert_date_var Test 84: error if variable is not a date or datetime variable
# assert_date_var Test 86: error if variable is not a date or datetime variable

Code
example_fun(dataset = my_data, var = USUBJID)
Condition
Error in `example_fun()`:
! Column "USUBJID" in dataset `dataset` must be a date or datetime, but is a character vector.

# assert_date_vector Test 88: error if `arg` is NULL and optional is FALSE
# assert_date_vector Test 90: error if `arg` is NULL and optional is FALSE

Code
example_fun(NULL)
Condition
Error in `example_fun()`:
! Argument `arg` must be a date or datetime, but is NULL.

# assert_atomic_vector Test 89: error if input is not atomic vector
# assert_atomic_vector Test 91: error if input is not atomic vector

Code
assert_atomic_vector(x)
Condition
Error:
! Argument `x` must be an atomic vector, but is a list.

# assert_same_type Test 91: error if different type
# assert_same_type Test 93: error if different type

Code
assert_same_type(true_value, false_value, missing_value)
Expand Down

0 comments on commit 6075790

Please sign in to comment.