Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/testthat/test-community.R
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ test_that("cluster_leading_eigen is deterministic", {

skip_if(getRversion() < "3.6")

withr::local_seed(42)

for (i in 1:100) {
g_rand <- sample_gnm(20, sample(5:40, 1))
lec1 <- cluster_leading_eigen(g_rand)
Expand Down
25 changes: 21 additions & 4 deletions tests/testthat/test-games.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
test_that("sample_degseq() works -- 'configuration' generator", {
withr::local_seed(42)
degrees <- rep(2, 100)
undirected_graph <- sample_degseq(degrees, method = "configuration")
expect_equal(degree(undirected_graph), degrees)
Expand All @@ -9,6 +10,7 @@ test_that("sample_degseq() works -- 'configuration' generator", {
})

test_that("sample_degseq() works -- sample_gnp()", {
withr::local_seed(42)
erdos_renyi <- sample_gnp(1000, 1 / 1000)
new_graph <- sample_degseq(degree(erdos_renyi), method = "configuration")
expect_equal(degree(new_graph), degree(erdos_renyi))
Expand All @@ -30,6 +32,7 @@ test_that("sample_degseq() works -- sample_gnp()", {
})

test_that("sample_degseq() works -- 'configuration' generator, connected", {
withr::local_seed(42)
original_graph <- largest_component(sample_gnp(1000, 2 / 1000))

simple_graph <- sample_degseq(
Expand All @@ -45,6 +48,7 @@ test_that("sample_degseq() works -- 'configuration' generator, connected", {
})

test_that("sample_degseq() works -- vl generator", {
withr::local_seed(42)
degrees <- rep(2, 100)
vl_graph <- sample_degseq(degrees, method = "vl")
expect_equal(degree(vl_graph), degrees)
Expand Down Expand Up @@ -93,6 +97,7 @@ test_that("sample_degseq() works -- Power-law degree error", {
})

test_that("sample_degseq() works -- fast.heur.simple", {
withr::local_seed(42)
g <- sample_gnp(1000, 1 / 1000)

simple_nm_graph <- sample_degseq(
Expand All @@ -105,6 +110,7 @@ test_that("sample_degseq() works -- fast.heur.simple", {
})

test_that("sample_degseq() works -- configuration.simple", {
withr::local_seed(42)
g <- sample_gnp(1000, 1 / 1000)
simple_nmu_graph <- sample_degseq(
degree(g, mode = "out"),
Expand All @@ -116,6 +122,7 @@ test_that("sample_degseq() works -- configuration.simple", {
})

test_that("sample_degseq() works -- edge.switching.simple directed", {
withr::local_seed(42)
g <- sample_gnp(1000, 1 / 1000, directed = TRUE)
simple_switch_graph <- sample_degseq(
degree(g, mode = "out"),
Expand All @@ -130,6 +137,7 @@ test_that("sample_degseq() works -- edge.switching.simple directed", {
})

test_that("sample_degseq() works -- edge.switching.simple undirected", {
withr::local_seed(42)
g <- sample_gnp(1000, 1 / 1000, directed = FALSE)
simple_switch_graph <- sample_degseq(
degree(g, mode = "all"),
Expand All @@ -142,6 +150,7 @@ test_that("sample_degseq() works -- edge.switching.simple undirected", {
})

test_that("sample_degseq supports the sample_(...) syntax", {
withr::local_seed(42)
degs <- rep(4, 20)
g1 <- sample_(degseq(degs))
g2 <- sample_(degseq(degs))
Expand Down Expand Up @@ -172,6 +181,7 @@ test_that("sample_degseq works() -- old method names", {
})

test_that("sample_chung_lu works", {
withr::local_seed(42)
chung_lu_small <- sample_chung_lu(c(3, 3, 2, 2, 1, 1))
expect_false(any_multiple(chung_lu_small))

Expand Down Expand Up @@ -233,6 +243,7 @@ test_that("sample_forestfire() works -- dense", {
})

test_that("Generating stochastic block models works", {
withr::local_seed(42)
pm <- matrix(1, nrow = 2, ncol = 2)
bs <- c(4, 6)
sbm_small <- sample_sbm(
Expand Down Expand Up @@ -285,6 +296,7 @@ test_that("Generating stochastic block models works", {
})

test_that("sample_smallworld works", {
withr::local_seed(42)
for (i in 1:50) {
p <- runif(1)
d <- sample(1:3, 1)
Expand Down Expand Up @@ -393,12 +405,14 @@ test_that("sample_bipartite works -- undirected gnp", {
})

test_that("sample_bipartite works -- directed gnp", {
withr::local_seed(42)

g_rand_bip_dir <- sample_bipartite_gnp(10, 5, p = 0.1, directed = TRUE)
expect_vcount(g_rand_bip_dir, 15)
expect_ecount(g_rand_bip_dir, 6)
expect_ecount(g_rand_bip_dir, 7)
expect_true(bipartite_mapping(g_rand_bip_dir)$res)
expect_true(is_directed(g_rand_bip_dir))
expect_output(print_all(g_rand_bip_dir), "5->11")
expect_output(print_all(g_rand_bip_dir), "5->12")

g_rand_bip_in <- sample_bipartite_gnp(
10,
Expand All @@ -407,17 +421,19 @@ test_that("sample_bipartite works -- directed gnp", {
directed = TRUE,
mode = "in"
)
expect_output(print_all(g_rand_bip_in), "11->3")
expect_output(print_all(g_rand_bip_in), "15->10")
})

test_that("sample_bipartite works -- undirected gnm", {
withr::local_seed(42)
g_rand_bip_gnm <- sample_bipartite_gnm(10, 5, m = 8)
expect_vcount(g_rand_bip_gnm, 15)
expect_ecount(g_rand_bip_gnm, 8)
expect_true(bipartite_mapping(g_rand_bip_gnm)$res)
expect_false(is_directed(g_rand_bip_gnm))
})
test_that("sample_bipartite works -- directed gnm", {
withr::local_seed(42)
g_rand_bip_gnm_dir <- sample_bipartite_gnm(10, 5, m = 8, directed = TRUE)
expect_vcount(g_rand_bip_gnm_dir, 15)
expect_ecount(g_rand_bip_gnm_dir, 8)
Expand All @@ -436,7 +452,7 @@ test_that("sample_bipartite works -- directed gnm", {
expect_ecount(g_rand_bip_gnm_in, 8)
expect_true(bipartite_mapping(g_rand_bip_gnm_in)$res)
expect_true(is_directed(g_rand_bip_gnm_in))
expect_output(print_all(g_rand_bip_gnm_in), "12->10")
expect_output(print_all(g_rand_bip_gnm_in), "12->8")

g_rand_bip_full <- sample_bipartite_gnp(
10,
Expand Down Expand Up @@ -819,6 +835,7 @@ test_that("sample_dot_product generates edges with correct probabilities", {
})

test_that("Dot product rng gives warnings", {
withr::local_seed(42)
vecs <- cbind(c(1, 1, 1) / 3, -c(1, 1, 1) / 3)
expect_warning(
g <- sample_dot_product(vecs),
Expand Down
Loading