Skip to content

Commit

Permalink
Merge pull request #60 from pharmaverse/1379_vignette_progstrategy_un…
Browse files Browse the repository at this point in the history
…ittest_@devel

Closes #1379 - Updated vignettes (programming strategy and unit test guide) to speci…
  • Loading branch information
bms63 authored Aug 29, 2022
2 parents 69f3025 + dd3176b commit 322c749
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 3 additions & 2 deletions vignettes/programming_strategy.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,9 @@ An example is given below:
#' @examples
#' library(lubridate)
#' library(dplyr)
#' library(tibble)
#'
#' datain <- tibble::tribble(
#' datain <- tribble(
#' ~TRTSDTM, ~ASTDTM, ~AENDT,
#' "2014-01-17T23:59:59", "2014-01-18T13:09:O9", "2014-01-20"
#' ) %>%
Expand Down Expand Up @@ -329,7 +330,7 @@ Any newly added variable(-s) should be mentioned here.
* `@examples`: A fully self-contained example of how to use the function.
Self-contained means that, if this code is executed in a new R session, it will run without errors.
That means any packages need to be loaded with `library()` and any datasets needed either to be created directly inside the example code or loaded using `data()`.
If a dataset is created in the example, it should be done so using the function `tibble::tribble()`.
If a dataset is created in the example, it should be done so using the function `tribble()` (specify `library(tibble)` before calling this function).
Make sure to align columns as this ensures quick code readability.

Copying descriptions should be avoided as it makes the documentation hard to
Expand Down
10 changes: 7 additions & 3 deletions vignettes/unit_test_guidance.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ the testing framework used is testthat and has the following format :

```
test_that("<function_name> Test 1: <Explanation of the test>", {
input <- tibble::tribble(
library(tibble)
input <- tribble(
~inputvar1, ~inputvar2, ...
<Add Test Data Scenarios>
...
Expand All @@ -158,7 +160,9 @@ Open the newly created file "test-all_funcs.R" and use the following format:

```
test_that("my_new_func Test 1: <Explanation of the test>", {
input <- tibble::tribble(
library(tibble)
input <- tribble(
~inputvar1, ~inputvar2, ...
<Add Test Data Scenarios>
...
Expand All @@ -177,7 +181,7 @@ The input and expected output for the unit tests must follow the following rules
* Values should be hard-coded whenever possible.
* If values need to be derived, only unit tested functions can be used.

If a dataset needs to be created for testing purpose, it should be done so using the function `tibble::tribble()`.
If a dataset needs to be created for testing purpose, it should be done so using the function `tribble()` (specify `library(tibble)` before calling this function).
Make sure to align columns as well. This ensures quick code readability.

Ensure you give a meaningful explanation of the test in the testthat call, as
Expand Down

0 comments on commit 322c749

Please sign in to comment.