@@ -25,3 +25,92 @@ test_that("gs_bound_summary() uses correct HR label", {
25
25
expect_identical(x_wlr_bound $ Value [5 ], " P(Cross) if wAHR=0.8" )
26
26
27
27
})
28
+
29
+ test_that(" gs_bound_summary() uses correct column names" , {
30
+ # column names for single implicit alpha
31
+ col_expected <- c(" Analysis" , " Value" , " Efficacy" , " Futility" )
32
+ x <- gs_design_ahr(info_frac = c(.25 , .75 , 1 ), analysis_time = c(12 , 25 , 36 ))
33
+ x_bound <- gs_bound_summary(x )
34
+ expect_equal(colnames(x_bound ), col_expected )
35
+
36
+ # column names for multiple alpha values
37
+ col_expected <- c(" Analysis" , " Value" , " α=0.0125" , " α=0.025" , " α=0.05" , " Futility" )
38
+ x <- gs_design_ahr(analysis_time = 1 : 3 * 12 , alpha = 0.0125 )
39
+ x_bound <- gs_bound_summary(x , alpha = c(0.025 , 0.05 ))
40
+ expect_identical(colnames(x_bound ), col_expected )
41
+ })
42
+
43
+ test_that(" gs_bound_summary() supports multiple alpha values" , {
44
+ # gs_design_ahr()
45
+ x_0125 <- gs_design_ahr(analysis_time = 1 : 3 * 12 , alpha = 0.0125 )
46
+ x_0250 <- gs_update_ahr(x_0125 , alpha = 0.0250 )
47
+ x_0500 <- gs_update_ahr(x_0125 , alpha = 0.0500 )
48
+
49
+ x_0125_bound <- gs_bound_summary(x_0125 )
50
+ x_0250_bound <- gs_bound_summary(x_0250 )
51
+ x_0500_bound <- gs_bound_summary(x_0500 )
52
+
53
+ expected <- cbind(
54
+ x_0125_bound [, c(" Analysis" , " Value" )],
55
+ `α=0.0125` = x_0125_bound [, " Efficacy" ],
56
+ `α=0.025` = x_0250_bound [, " Efficacy" ],
57
+ `α=0.05` = x_0500_bound [, " Efficacy" ],
58
+ x_0125_bound [, " Futility" , drop = FALSE ]
59
+ )
60
+ x_bound <- gs_bound_summary(x_0125 , alpha = c(0.025 , 0.05 ))
61
+ expect_equal(x_bound , expected )
62
+
63
+ # gs_power_ahr()
64
+ x_0250 <- gs_power_ahr(lpar = list (sf = gsDesign :: sfLDOF , total_spend = 0.1 ))
65
+ expect_equal(x_0250 [[" input" ]][[" alpha" ]], 0.0250 )
66
+ expect_equal(x_0250 [[" input" ]][[" upar" ]][[" total_spend" ]], 0.0250 )
67
+ x_0125 <- gs_update_ahr(x_0250 , alpha = 0.0125 )
68
+ x_0500 <- gs_update_ahr(x_0250 , alpha = 0.0500 )
69
+
70
+ x_0125_bound <- gs_bound_summary(x_0125 )
71
+ x_0250_bound <- gs_bound_summary(x_0250 )
72
+ x_0500_bound <- gs_bound_summary(x_0500 )
73
+
74
+ expected <- cbind(
75
+ x_0250_bound [, c(" Analysis" , " Value" )],
76
+ `α=0.0125` = x_0125_bound [, " Efficacy" ],
77
+ `α=0.025` = x_0250_bound [, " Efficacy" ],
78
+ `α=0.05` = x_0500_bound [, " Efficacy" ],
79
+ x_0250_bound [, " Futility" , drop = FALSE ]
80
+ )
81
+ x_bound <- gs_bound_summary(x_0250 , alpha = c(0.0125 , 0.05 ))
82
+ expect_equal(x_bound , expected )
83
+ })
84
+
85
+ test_that(" The arg `alpha` is only supported for AHR design objects" , {
86
+ x_wlr <- gs_design_wlr(info_frac = c(.25 , .75 , 1 ), analysis_time = c(12 , 25 , 36 ))
87
+
88
+ expect_error(
89
+ gs_bound_summary(x_wlr , alpha = 0.5 ),
90
+ " The argument `alpha` is only supported for AHR design objects"
91
+ )
92
+ })
93
+
94
+ test_that(" The arg `alpha` is required to be a numeric vector" , {
95
+ x <- gs_design_ahr(info_frac = c(.25 , .75 , 1 ), analysis_time = c(12 , 25 , 36 ))
96
+
97
+ expect_error(
98
+ gs_bound_summary(x , alpha = " alternative" ),
99
+ " The argument `alpha` must be a numeric vector"
100
+ )
101
+ })
102
+
103
+ test_that(" Edge case: when arg `alpha` matches original alpha" , {
104
+ # Redundantly specifying the original alpha does not affect results
105
+ x <- gs_design_ahr(analysis_time = 1 : 3 * 12 , alpha = 0.0125 )
106
+
107
+ x_bound <- gs_bound_summary(x , alpha = c(0.025 , 0.05 ))
108
+ x_bound_redundant <- gs_bound_summary(x , alpha = c(0.0125 , 0.025 , 0.05 ))
109
+ expect_equal(x_bound_redundant , x_bound )
110
+
111
+ # Only specifying the original alpha only affects the column name
112
+ x_bound <- gs_bound_summary(x )
113
+ x_bound_same <- gs_bound_summary(x , alpha = 0.0125 )
114
+ expect_equal(colnames(x_bound_same )[3 ], " α=0.0125" )
115
+ expect_equal(unname(x_bound_same ), unname(x_bound ))
116
+ })
0 commit comments