|
| 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