diff --git a/tests/testthat/test-plot.R b/tests/testthat/test-plot.R new file mode 100644 index 0000000..6a6263f --- /dev/null +++ b/tests/testthat/test-plot.R @@ -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") +}) \ No newline at end of file diff --git a/tests/testthat/test-print.R b/tests/testthat/test-print.R new file mode 100644 index 0000000..ef3a604 --- /dev/null +++ b/tests/testthat/test-print.R @@ -0,0 +1,28 @@ + +test_that("ANSI handler converts R code to HTML tagged version", { + output <- ansi_aware_handler("test") + expect_equal(output, "
test
")
+})
+
+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")
+})
\ No newline at end of file