tests/testthat/test-multilevel.community.R

test_that("cluster_louvain works", {
  withr::local_seed(20231029)

  g <- make_graph("Zachary")
  mc <- cluster_louvain(g)

  expect_true(all(as.vector(membership(mc)) %in% 1:4))
  expect_equal(modularity(g, mc$membership), max(mc$modularity))
  # 3   4
  # 2 998
  expect_true(length(mc) %in% 3:4)
  expect_true(all(as.vector(membership(mc)) %in% seq_len(length(mc))))
  expect_s3_class(sizes(mc), "table")
  expect_equal(sum(sizes(mc)), vcount(g))
  expect_identical(sizes(mc), table(membership(mc), dnn = "Community sizes"))
})

Try the igraph package in your browser

Any scripts or data that you put into this service are public.

igraph documentation built on Oct. 20, 2024, 1:06 a.m.