diff --git a/R/undirected_sbm.R b/R/undirected_sbm.R index 46a5459..2841e71 100644 --- a/R/undirected_sbm.R +++ b/R/undirected_sbm.R @@ -13,7 +13,7 @@ validate_undirected_sbm <- function(x) { function(x) length(unique(x)) ) - if (any(distinct_theta_by_block) > 1) { + if (any(distinct_theta_by_block > 1)) { stop( "`theta` must be equal for all nodes in a given block.", call. = FALSE @@ -140,8 +140,7 @@ print.undirected_sbm <- function(x, ...) { cat("Traditional SBM parameterization:\n\n") cat("Block memberships (z):", dim_and_class(x$z), "\n") - cat("Block probabilities (pi):", dim_and_class(x$pi), "\n") - cat(glue("Edge distribution: {x$edge_distribution}\n\n", .trim = FALSE)) + cat("Block probabilities (pi):", dim_and_class(x$pi), "\n\n") cat("Factor model parameterization:\n\n") cat("X:", dim_and_class(x$X), "\n") diff --git a/tests/testthat/test-undirected-sbms.R b/tests/testthat/test-undirected-sbms.R index 21328ae..cc7eba2 100644 --- a/tests/testthat/test-undirected-sbms.R +++ b/tests/testthat/test-undirected-sbms.R @@ -28,3 +28,30 @@ test_that("rank 1 sbms sample", { expect_silent(A <- sample_sparse(sbm)) }) + +test_that("validate_undirected_sbm() rejects theta that varies within a block", { + set.seed(1) + m <- sbm(n = 10, B = diag(2) * 0.5 + 0.1) + expect_identical(validate_undirected_sbm(m), m) + + m$theta <- 1:10 + 0 + expect_error( + validate_undirected_sbm(m), + "`theta` must be equal for all nodes in a given block.", + fixed = TRUE + ) +}) + +test_that("print.undirected_sbm() separates its sections", { + set.seed(1) + m <- sbm(n = 10, B = diag(2) * 0.5 + 0.1) + out <- paste(capture.output(print(m)), collapse = "\n") + + expect_match( + out, + "Block probabilities (pi): 2 [numeric] \n\nFactor model parameterization:", + fixed = TRUE + ) + expect_match(out, "Poisson edges: TRUE", fixed = TRUE) + expect_match(out, "Allow self loops: TRUE", fixed = TRUE) +})