Skip to content

Commit 9fb5485

Browse files
queeliusclaude
andcommitted
Remove unused imports and add tests for 100% coverage
- Remove unused stats::pf and stats::qt imports - Add tests for print.hypothesis_test() output and invisible return - Add test for fisher_combine() bad-input error path - 92 tests, 100% line coverage Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 1aa8e06 commit 9fb5485

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

NAMESPACE

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,5 @@ export(wald_test)
2020
export(z_test)
2121
importFrom(stats,p.adjust)
2222
importFrom(stats,pchisq)
23-
importFrom(stats,pf)
2423
importFrom(stats,pnorm)
2524
importFrom(stats,qnorm)
26-
importFrom(stats,qt)

R/hypothesize.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
#'
7272
#' @seealso [lrt()], [wald_test()], [z_test()] for specific test constructors;
7373
#' [pval()], [test_stat()], [dof()], [is_significant_at()] for accessors
74-
#' @importFrom stats pf pchisq qt qnorm
74+
#' @importFrom stats pchisq qnorm
7575
#' @export
7676
hypothesis_test <- function(stat, p.value, dof, superclasses = NULL, ...) {
7777
res <- list(stat = stat, p.value = p.value, dof = dof, ...)

tests/testthat/test-hypothesis-tests.R

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,33 @@ test_that("adjusted tests can be combined with fisher_combine", {
363363
expect_equal(test_stat(combined), expected_stat)
364364
})
365365

366+
# =============================================================================
367+
# print method
368+
# =============================================================================
369+
370+
test_that("print.hypothesis_test prints expected output", {
371+
ht <- hypothesis_test(stat = 2.0, p.value = 0.05, dof = 1,
372+
superclasses = "my_test")
373+
expect_output(print(ht), "Hypothesis test")
374+
expect_output(print(ht), "my_test")
375+
expect_output(print(ht), "Test statistic:")
376+
expect_output(print(ht), "P-value:")
377+
expect_output(print(ht), "Degrees of freedom:")
378+
expect_output(print(ht), "Significant at 5% level:")
379+
})
380+
381+
test_that("print.hypothesis_test returns x invisibly", {
382+
ht <- hypothesis_test(stat = 2.0, p.value = 0.05, dof = 1)
383+
result <- withVisible(print(ht))
384+
expect_false(result$visible)
385+
expect_identical(result$value, ht)
386+
})
387+
388+
test_that("fisher_combine rejects non-numeric non-test inputs", {
389+
expect_error(fisher_combine("not_a_pvalue"),
390+
"must be hypothesis_test objects or numeric")
391+
})
392+
366393
test_that("all test types work with is_significant_at", {
367394
z <- z_test(rnorm(30, mean = 1), mu0 = 0, sigma = 1)
368395
w <- wald_test(estimate = 2, se = 1)

0 commit comments

Comments
 (0)