Skip to content

Commit 16a8de8

Browse files
Copilotosorensen
andcommitted
Add documentation and tests for print method
Co-authored-by: osorensen <21175639+osorensen@users.noreply.github.com>
1 parent 59115fe commit 16a8de8

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

man/print.BayesMallowsSMC2.Rd

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-print.R

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
test_that("print method works for BayesMallowsSMC2 objects", {
2+
set.seed(123)
3+
mod <- compute_sequentially(
4+
complete_rankings,
5+
hyperparameters = set_hyperparameters(n_items = 5),
6+
smc_options = set_smc_options(n_particles = 100, n_particle_filters = 1)
7+
)
8+
9+
# Test that print method runs without error
10+
expect_error(print(mod), NA)
11+
12+
# Test that print returns the object invisibly
13+
expect_identical(print(mod), mod)
14+
15+
# Capture output and verify it contains expected content
16+
output <- capture.output(print(mod))
17+
expect_true(any(grepl("BayesMallowsSMC2 Model", output)))
18+
expect_true(any(grepl("Number of particles:", output)))
19+
expect_true(any(grepl("Number of timepoints:", output)))
20+
expect_true(any(grepl("Number of items:", output)))
21+
expect_true(any(grepl("Number of clusters:", output)))
22+
expect_true(any(grepl("Log marginal likelihood:", output)))
23+
expect_true(any(grepl("Final ESS:", output)))
24+
expect_true(any(grepl("Resampling events:", output)))
25+
})
26+
27+
test_that("print method works with partial rankings", {
28+
set.seed(456)
29+
mod <- compute_sequentially(
30+
partial_rankings,
31+
hyperparameters = set_hyperparameters(n_items = 5),
32+
smc_options = set_smc_options(n_particles = 50, n_particle_filters = 1)
33+
)
34+
35+
# Test that print method runs without error
36+
expect_error(print(mod), NA)
37+
38+
# Capture output and verify it contains expected content
39+
output <- capture.output(print(mod))
40+
expect_true(any(grepl("BayesMallowsSMC2 Model", output)))
41+
})

0 commit comments

Comments
 (0)