Skip to content

Commit 0d48ddd

Browse files
committed
Add unit tests for extrapolation-factor and fix existing visual tests
1 parent e5221f0 commit 0d48ddd

File tree

6 files changed

+152
-129
lines changed

6 files changed

+152
-129
lines changed

R/ppc-censoring.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ ppc_km_overlay_grouped <- function(
204204
status_y,
205205
left_truncation_y = NULL,
206206
size = 0.25,
207-
alpha = 0.7
207+
alpha = 0.7,
208+
extrapolation_factor = 1.2
208209
) {
209210
check_ignored_arguments(...)
210211

@@ -216,7 +217,8 @@ ppc_km_overlay_grouped <- function(
216217
status_y = status_y,
217218
left_truncation_y = left_truncation_y,
218219
size = size,
219-
alpha = alpha
220+
alpha = alpha,
221+
extrapolation_factor = extrapolation_factor
220222
)
221223

222224
p_overlay +

tests/testthat/_snaps/ppc-censoring/ppc-km-overlay-default-2.svg

Lines changed: 23 additions & 21 deletions
Loading

tests/testthat/_snaps/ppc-censoring/ppc-km-overlay-grouped-default-2.svg

Lines changed: 46 additions & 42 deletions
Loading

tests/testthat/_snaps/ppc-censoring/ppc-km-overlay-grouped-left-truncation-y.svg

Lines changed: 46 additions & 42 deletions
Loading

tests/testthat/_snaps/ppc-censoring/ppc-km-overlay-left-truncation-y.svg

Lines changed: 23 additions & 21 deletions
Loading

tests/testthat/test-ppc-censoring.R

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ source(test_path("data-for-ppc-tests.R"))
55

66
test_that("ppc_km_overlay returns a ggplot object", {
77
skip_if_not_installed("ggfortify")
8-
expect_gg(ppc_km_overlay(y, yrep, status_y = status_y, left_truncation_y = left_truncation_y, size = 0.5, alpha = 0.2))
8+
expect_gg(ppc_km_overlay(y, yrep, status_y = status_y, left_truncation_y = left_truncation_y, size = 0.5, alpha = 0.2, extrapolation_factor = Inf))
9+
expect_gg(ppc_km_overlay(y, yrep, status_y = status_y, left_truncation_y = left_truncation_y, size = 0.5, alpha = 0.2, extrapolation_factor = 1))
910
expect_gg(ppc_km_overlay(y2, yrep2, status_y = status_y2))
1011
})
1112

@@ -60,6 +61,14 @@ test_that("ppc_km_overlay errors if bad left_truncation_y value", {
6061
)
6162
})
6263

64+
test_that("ppc_km_overlay errors if bad extrapolation_factor value", {
65+
skip_if_not_installed("ggfortify")
66+
expect_error(
67+
ppc_km_overlay(y, yrep, status_y = status_y, extrapolation_factor = 0.99),
68+
"`extrapolation_factor` must be greater than or equal to 1."
69+
)
70+
})
71+
6372
# Visual tests -----------------------------------------------------------------
6473

6574
test_that("ppc_km_overlay renders correctly", {

0 commit comments

Comments
 (0)