From 982faf89ee333ac725fb3cea14f5da1a9739cba0 Mon Sep 17 00:00:00 2001 From: jim Date: Fri, 20 Dec 2024 07:28:22 -0800 Subject: [PATCH] Closes #2581 - enhance test coverage: derive_var_trtemfl.R (#2608) * 2581 - enhance test coverage: derive_var_trtemfl.R * 2581 fix styler error * 2521 - typo in Test #10 for derive_var_trtemfl * # 2581 Test #9, fix typo * 2581 derive_var_trtemfl() - correct Test 11 to use `expect_snapshot` so exact error msg is caught --------- Co-authored-by: Stefan Bundfuss <80953585+bundfussr@users.noreply.github.com> --- tests/testthat/_snaps/compute_scale.md | 2 +- tests/testthat/_snaps/derive_var_trtemfl.md | 9 +++++++++ tests/testthat/test-derive_var_trtemfl.R | 14 +++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/tests/testthat/_snaps/compute_scale.md b/tests/testthat/_snaps/compute_scale.md index a95fd8c969..b7bc57c65d 100644 --- a/tests/testthat/_snaps/compute_scale.md +++ b/tests/testthat/_snaps/compute_scale.md @@ -7,7 +7,7 @@ ! Argument `target_range` is missing with no default and `source_range` is not missing. i Either both or neither arguments should be specified. ---- +# compute_scale Test 7: error if target_range is supplied, but not source_range Code compute_scale(input, target_range = c(0, 100), min_n = 2) diff --git a/tests/testthat/_snaps/derive_var_trtemfl.md b/tests/testthat/_snaps/derive_var_trtemfl.md index 2c3c488096..0c1282965f 100644 --- a/tests/testthat/_snaps/derive_var_trtemfl.md +++ b/tests/testthat/_snaps/derive_var_trtemfl.md @@ -34,3 +34,12 @@ ! `intensity` argument was specified but not `initial_intensity` Either both or none of them must be specified. +# derive_var_trtemfl Test 11: error if `group_var` without `subject_keys` + + Code + derive_var_trtemfl(adae, group_var = AEGRPID, subject_keys = NULL) + Condition + Error in `derive_var_trtemfl()`: + ! `group_var` argument was specified but not `subject_keys` + `subject_keys` argument must be provided when `group_var` is specified. + diff --git a/tests/testthat/test-derive_var_trtemfl.R b/tests/testthat/test-derive_var_trtemfl.R index c110da5730..a91348d630 100644 --- a/tests/testthat/test-derive_var_trtemfl.R +++ b/tests/testthat/test-derive_var_trtemfl.R @@ -194,7 +194,7 @@ test_that("derive_var_trtemfl Test 9: error if `intensity` without `initial_inte }) ## Test 10: warning if both `initial_intensity` and `group_var` are specified ---- -test_that("derive_var_trtemfl Test 9: error if `intensity` without `initial_intensity`", { +test_that("derive_var_trtemfl Test 10: error if `intensity` without `initial_intensity`", { expect_warning( derive_var_trtemfl( adae2, @@ -204,3 +204,15 @@ test_that("derive_var_trtemfl Test 9: error if `intensity` without `initial_inte "`initial_intensity` argument is ignored when `group_var` is specified" ) }) + +## Test 11: error if `group_var` are specified without `subject_keys` ---- +test_that("derive_var_trtemfl Test 11: error if `group_var` without `subject_keys`", { + expect_snapshot( + derive_var_trtemfl( + adae, + group_var = AEGRPID, + subject_keys = NULL + ), + error = TRUE + ) +})