all(adj1 == adj2) is not FALSE

`actual`:   TRUE 
`expected`: FALSE

test_that("combining within- and between-block edgelists while removing duplicated edges works", {
edgelist_within <- matrix(c(1, 1, 2, 3, 2, 3, 4, 5), nrow = 4, ncol = 2)
edgelist_between <- matrix(c(1, 2, 3, 4, 3, 5), nrow = 3, ncol = 2)
edgelist <- combine_within_between_edges(edgelist_within, edgelist_between, use_fast_between_simulation = FALSE)
expect_equal(true_edgelist, unclass(edgelist), check.attributes = FALSE)
test_that("correctly attaching vertex ids, block memberships, and vertex features to the simulated network works", {
# Prepare ingredients for simulating a network
formula <- g ~ edges + nodematch("x") + nodematch("y") + triangle + kstar(2)
memb <- sample(1:K, size = N, replace = TRUE)
vertex_id <- as.character(11:(11 + N - 1))
x <- sample(1:20, size = N, replace = TRUE)
y <- sample(LETTERS, size = N, replace = TRUE)
# Check if vertex ids, block memberships, and vertex features are stored correctly in the network object.
expect_equal(df_sorted$id, network::get.vertex.attribute(g_sim, "vertex.names"), check.attributes = FALSE)
expect_equal(df_sorted$memb, network::get.vertex.attribute(g_sim, "block"), check.attributes = FALSE)
expect_equal(df_sorted$x, network::get.vertex.attribute(g_sim, "x"), check.attributes = FALSE)
expect_equal(df_sorted$y, network::get.vertex.attribute(g_sim, "y"), check.attributes = FALSE)
test_that("simulating a network from a given edgelist works", {
# Simulate a network from a given edgelist
# These settings should result on the exact same network being returned
# Check if the network is correctly generated
test_that("The simulation begins from an empty network by default", {
test_that("generating multiple networks works", {
test_that("generating stats and avoiding generating within-block links while simulating a between-block network works", {
ergm_control = ergm::control.simulate.formula(MCMC.burnin = 100, MCMC.interval = 100),
# Check whether network stats are generated.
expect_equal(c("edges", "nodematch.x", "nodematch.y", "triangle", "kstar2"), colnames(g_sim[[1]]))
expect_equal(c("edges", "nodematch.x", "nodematch.y", "nodematch.block"), colnames(g_sim[[2]]))
# Check whether no within-block links are generated in the between-block network.
test_that("simulating between-block networks using the cpp function works", {
# Prepare a list of feature adjacency matrices
# When use_fast_between_simulation = TRUE but list_feature_matrices is not given, it should yield an error.
# Check if multiple networks can be generated.
# Check if the function works when output = "stats" and use_fast_between_simulation = TRUE.
ergm_control = ergm::control.simulate.formula(MCMC.burnin = 10000, MCMC.interval = 10000),
test_that("Yielding the same between-block network using the cpp function when the seed is fixed works", {
x <- sample(1:10, size = N, replace = TRUE)
y <- sample(1:10, size = N, replace = TRUE)
z <- sample(1:10, size = N, replace = TRUE)
G <- Matrix::sparseMatrix(i = {}, j = {}, dims = c(N, N))
# Simulate three between-block networks.
adj1 <- simulate_between_network(N, list_feature_adjmat, coef_between, block, directed = FALSE)
adj2 <- simulate_between_network(N, list_feature_adjmat, coef_between, block, directed = FALSE)
adj3 <- simulate_between_network(N, list_feature_adjmat, coef_between, block, directed = FALSE)
# Check if all the adjacency matrices are identical.
expect_equal(adj1, adj2, check.attributes = FALSE)
expect_equal(adj1, adj3, check.attributes = FALSE)
expect_equal(adj2, adj3, check.attributes = FALSE)
# If seed is not given, different adjacency matrices must be generated.
test_that("Simulating networks using formula without externality terms works", {
x <- sample(c(1, 2), size = N, replace = TRUE)
block <- sample(1:K, size = N, replace = TRUE)
tibble::tibble(x = x, node_id = as.character(1:N), block = block)
test_that("Simulating networks using formula without covariates works", {
test_that("Setting output = 'edgelist' returns a single edgelist for the full
# Shuffle the vertex names because we want to check whether the IDs are in the correct order
network::network.vertex.names(net) <- as.character(sample(401:600, size = 200, replace = FALSE))
dplyr::select(vertex.names, x, y, block) %>%
net ~ edges + nodematch('x') + nodematch('y') + triangle + kstar(2)
# The class of the returned object should be `network`
# Convert the network to an edgelist for comparison
# The class of the returned object should be `edgelist`
# Both should have the same number of nodes
expect_true(attr(sim_net_edgelist, 'n') == attr(sim_edgelist, 'n'))
expect_true(all(attr(sim_net_edgelist, 'vnames') == attr(sim_edgelist, 'vnames')))
test_that("Setting output = 'edgelist' returns a list of full-network edgelists", {
# The returned object should be a list of networks
# The class of the returned object should be `list`
expect_true(attr(sim_nets_edgelists[[i]], 'n') == attr(sim_edgelists[[i]], 'n'))
expect_true(all(attr(sim_nets_edgelists[[i]], 'vnames') == attr(sim_edgelists[[i]], 'vnames')))