Skip to content

Commit

Permalink
some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krisrs1128 committed Sep 4, 2024
1 parent adaf6be commit 46a7d75
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/testthat/test-plot.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


exper <- demo_joy() |>
mediation_data("PHQ", "treatment", starts_with("ASV"))
ie <- multimedia(exper) |>
estimate(exper) |>
indirect_pathwise() |>
effect_summary()

test_that("Plot mediators returns on standard pathwise output.", {
g <- plot_mediators(ie, exper)
expect_s3_class(g, "patchwork")
})

test_that("Can customize number of digits in plot_mediators output.", {
g <- plot_mediators(ie, exper, n_digit = 1)
expect_s3_class(g, "patchwork")
g <- plot_mediators(ie, exper, n_digit = 3)
expect_s3_class(g, "patchwork")
})
28 changes: 28 additions & 0 deletions tests/testthat/test-print.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

test_that("ANSI handler converts R code to HTML tagged version", {
output <- ansi_aware_handler("test")
expect_equal(output, "<pre class=\"r-output\"><code>test</code></pre>")
})

test_that("Show methods give expected output for mediation data object.", {
exper <- mediation_data(demo_joy(), "PHQ", "treatment", starts_with("ASV"))
expect_output(print(exper), "\\[Mediation Data\\]")
expect_output(print(exper), "100 samples with measurements for,")
})

test_that("vec_sub correctly truncates long outputs", {
expect_equal(multimedia:::vec_sub(LETTERS[1:10]), "A, B, ...")
expect_equal(multimedia:::vec_sub(1:10), "1, 2, ...")
})

test_that("Show methods give expected output for a fitted multimedia object.", {
exper <- mediation_data(demo_joy(), "PHQ", "treatment", starts_with("ASV"))
model <- multimedia(exper) |>
estimate(exper)
expect_output(print(model), "\\[Multimedia Analysis\\]")
expect_output(print(model), "Treatments: treatment")
expect_output(print(model), "Mediators: ASV1, ASV2, ...")
expect_output(print(model), "\\[Models\\]")
expect_output(print(model), "mediation: A fitted")
expect_output(print(model), "outcome: A fitted")
})

0 comments on commit 46a7d75

Please sign in to comment.