From 46a7d756f05a41a9553eda79255e797ee5908603 Mon Sep 17 00:00:00 2001 From: Kris Sankaran Date: Tue, 3 Sep 2024 19:05:40 -0500 Subject: [PATCH] some more tests --- tests/testthat/test-plot.R | 20 ++++++++++++++++++++ tests/testthat/test-print.R | 28 ++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/testthat/test-plot.R create mode 100644 tests/testthat/test-print.R 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