From 458538c6dac7ef3cfa06784edcee9ba5550a27c4 Mon Sep 17 00:00:00 2001 From: jimrothstein Date: Thu, 12 Dec 2024 15:09:28 -0800 Subject: [PATCH 1/5] 2581 - enhance test coverage: derive_var_trtemfl.R --- tests/testthat/_snaps/compute_scale.md | 2 +- tests/testthat/test-derive_var_trtemfl.R | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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/test-derive_var_trtemfl.R b/tests/testthat/test-derive_var_trtemfl.R index c110da5730..59b5520a0c 100644 --- a/tests/testthat/test-derive_var_trtemfl.R +++ b/tests/testthat/test-derive_var_trtemfl.R @@ -204,3 +204,13 @@ 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_error( + derive_var_trtemfl( + adae, + group_var = AEGRPID, + subject_keys = NULL) + ) +}) From 1256ebb38983ec65bc3bdb4fb716077a2ff1b772 Mon Sep 17 00:00:00 2001 From: jimrothstein Date: Thu, 12 Dec 2024 15:24:42 -0800 Subject: [PATCH 2/5] 2581 fix styler error --- tests/testthat/test-derive_var_trtemfl.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-derive_var_trtemfl.R b/tests/testthat/test-derive_var_trtemfl.R index 59b5520a0c..bbad533f7f 100644 --- a/tests/testthat/test-derive_var_trtemfl.R +++ b/tests/testthat/test-derive_var_trtemfl.R @@ -211,6 +211,7 @@ test_that("derive_var_trtemfl Test 11: error if `group_var` without `subject_key derive_var_trtemfl( adae, group_var = AEGRPID, - subject_keys = NULL) + subject_keys = NULL + ) ) }) From e975ef4232d151bbca41609f6871efcb0ae99949 Mon Sep 17 00:00:00 2001 From: jimrothstein Date: Thu, 12 Dec 2024 15:48:18 -0800 Subject: [PATCH 3/5] 2521 - typo in Test #10 for derive_var_trtemfl --- tests/testthat/test-derive_var_trtemfl.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-derive_var_trtemfl.R b/tests/testthat/test-derive_var_trtemfl.R index bbad533f7f..5f34bd9cfa 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, From b24b935177b7073ac4a596e28e6d6931a2e5e473 Mon Sep 17 00:00:00 2001 From: jimrothstein Date: Fri, 13 Dec 2024 15:06:22 -0800 Subject: [PATCH 4/5] # 2581 Test #9, fix typo --- tests/testthat/test-derive_var_trtemfl.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-derive_var_trtemfl.R b/tests/testthat/test-derive_var_trtemfl.R index c110da5730..bdf3a36310 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, From 78fa32a2f6692707c0aa05bc5257041ec46e943b Mon Sep 17 00:00:00 2001 From: jimrothstein Date: Fri, 13 Dec 2024 15:22:40 -0800 Subject: [PATCH 5/5] 2581 derive_var_trtemfl() - correct Test 11 to use `expect_snapshot` so exact error msg is caught --- tests/testthat/_snaps/derive_var_trtemfl.md | 9 +++++++++ tests/testthat/test-derive_var_trtemfl.R | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) 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 5f34bd9cfa..a91348d630 100644 --- a/tests/testthat/test-derive_var_trtemfl.R +++ b/tests/testthat/test-derive_var_trtemfl.R @@ -207,11 +207,12 @@ test_that("derive_var_trtemfl Test 10: error if `intensity` without `initial_int ## 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_error( + expect_snapshot( derive_var_trtemfl( adae, group_var = AEGRPID, subject_keys = NULL - ) + ), + error = TRUE ) })