Repository navigation
Add tests for untested code paths and model invariants - #60
Draft
alexpghayes wants to merge 7 commits into
Draft
alexpghayes wants to merge 7 commits into
alexpghayes wants to merge 7 commits into
Conversation
Check that z, X, theta, pi and S agree after construction for dcsbm(), sbm(), planted_partition(), chung_lu(), mmsbm(), overlapping_sbm() and directed_dcsbm(), across sort_nodes, force_identifiability, poisson_edges, allow_self_loops, shared_blocks / shared_theta, k = 1 and k > 1, block sizes with zeros and pi with zeros. Also cover argument validation and the random theta / B messages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every print method runs and reports expected edges, degrees and density that match the model. All four samplers describe the same graph for a common seed, across undirected, directed square and directed rectangular models, with and without self-loops and Poisson edges. Also check seed reproducibility of samplers and constructors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pearson chi-squared tests of the entrywise totals of sampled adjacency matrices against exact Poisson / Binomial distributions, for undirected, directed square and directed rectangular models, Poisson and Bernoulli edges, with and without self-loops. Also check expected_degrees() and directed in/out degrees node by node with exact Poisson z-scores, and the density of very dense Bernoulli graphs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
eigs_sym() and svds() agree with eigen() and svd() of expectation() for undirected models (including an indefinite mixing matrix) and for square and rectangular directed models. Models built from dgeMatrix, dgCMatrix, dsyMatrix and ddiMatrix inputs match those built from base matrices, and non-symmetric S is symmetrized. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
expected_degree / expected_density for every undirected constructor, with and without self-loops; expected_in_degree / expected_out_degree / expected_density for every directed constructor, square and rectangular, including shared blocks. Bernoulli blockmodels hit the target on the probability scale. Also cover the scaling argument validation in undirected_factor_model() and directed_factor_model(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cover plot_dense_matrix(), plot_expectation() and plot_sparse_matrix(), which were almost entirely untested. Add tests for tiny graphs (n = 1, 2), models with no edges, empty and zero-probability blocks, balanced default block sizes, rank one models of every kind, planted_partition() validation and calling sample_edgelist() directly on matrices. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Skip the two largest combination loops on CRAN, pair allow_self_loops with poisson_edges in the dcsbm() loop since it does not affect construction, and cover the 'not arranged by block' print branches and the k-and-B error in dcsbm(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 17, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds tests only. No changes to
R/,NEWS.mdorvignettes/.Coverage
Overall line coverage (
covr::package_coverage()) goes from 74.76% to 92.58%.R/plotting.RR/undirected_chung_lu.RR/undirected_sbm.RR/undirected_mmsbm.RR/undirected_factor_model.RR/undirected_dcsbm.RR/directed_factor_model.RR/undirected_overlapping_sbm.RR/undirected_planted_partition.RR/directed_dcsbm.RR/directed_planted_partition.RR/directed_erdos_renyi.RR/undirected_erdos_renyi.RR/utils.RR/expected-*.R,R/sample_*.RMost of the lines still uncovered are validator branches that the public constructors can't reach, because an earlier check always fails first.
What is now covered
Model consistency (
test-model-consistency.R): after construction,z,X,theta,piandSagree with each other and with the arguments. This is checked fordcsbm(),sbm(),planted_partition(),chung_lu(),mmsbm(),overlapping_sbm()anddirected_dcsbm(), across these combinations:sort_nodes,force_identifiability,poisson_edgesandallow_self_loops;shared_blocksandshared_theta;k = 1andk > 1, withnnot divisible byk;piwith zeros;B.The file also covers argument validation and the random
theta/Bmessages.Print methods (
test-print-methods.R): every print method runs. The expected edges, degrees, density, dimensions and sorted / unsorted status it prints match the model.Sampler agreement (
test-sampler-agreement.R):sample_edgelist(),sample_sparse(),sample_igraph()andsample_tidygraph()agree on edge counts, degrees, vertex counts andmultigraph = FALSEweights. This covers undirected, directed square and directed rectangular models.from <= to.allow_self_loops = FALSEthere are no self-loops, and withpoisson_edges = FALSEthere are no multi-edges.E[A] = expectation(model) (
test-expectation-monte-carlo.R):Poisson(reps P)for Poisson edges,Binomial(reps, 1 - exp(-P))for Bernoulli edges. These cover undirected and directed models, with and without self-loops, and several constructors.expected_degrees()and directed in- and out-degrees are checked node by node, with exact Poisson z-scores and a Bonferroni bound.Spectra and Matrix classes (
test-spectra-and-matrix-classes.R):eigs_sym()andsvds()agree with denseeigen()andsvd()ofexpectation(), including an indefinite mixing matrix and rectangular directed models.dgeMatrix,dgCMatrix,dsyMatrixandddiMatrixinputs give the same model and the same samples as base matrices.Sis symmetrized.Scaling (
test-scaling-targets.R):expected_degreeandexpected_densityhit their targets for every undirected constructor.expected_in_degree,expected_out_degreeandexpected_densityhit their targets for every directed constructor, square and rectangular, including shared blocks.Plot helpers (
test-plotting.R):plot_dense_matrix(),plot_expectation()andplot_sparse_matrix()were previously almost untested.Boundary cases (
test-edge-cases.R):n = 1,n = 2) and graphs with no edges, across every sampler;planted_partition()validation;sample_edgelist()called directly on matrices.Shared helpers are in
tests/testthat/helper-invariants.R. Statistical checks use exact distributional bounds, followingtest-expected-edges-density.R. The Monte Carlo tests and the two largest combination loops are markedskip_on_cran().testthat::test_local()passes in about 60s withNOT_CRAN=trueand about 30s on CRAN.🤖 Generated with Claude Code