File: test_fastgreedy.community.R

package info (click to toggle)
r-cran-igraph 1.0.1-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 18,232 kB
  • sloc: ansic: 173,538; cpp: 19,365; fortran: 4,550; yacc: 1,164; tcl: 931; lex: 484; makefile: 149; sh: 9
file content (30 lines) | stat: -rw-r--r-- 983 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

context("cluster_fast_greedy")

test_that("cluster_fast_greedy works", {

  library(igraph)
  set.seed(42)

  g <- make_graph("Zachary")
  fc <- cluster_fast_greedy(g)

  expect_that(modularity(g, fc$membership), equals(max(fc$modularity)))
  expect_that(as.vector(membership(fc)),
              equals(c(1, 3, 3, 3, 1, 1, 1, 3, 2, 3,
                       1, 1, 3, 3, 2, 2, 1, 3, 2, 1,
                       2, 3, 2, 2, 2, 2, 2, 2, 2, 2,
                       2, 2, 2, 2)))
  expect_that(length(fc), equals(3))
  expect_that(as.numeric(sizes(fc)), equals(c(8, 17, 9)))

  d <- as.dendrogram(fc)
  expect_that(print(d), prints_text("2 branches.*34 members.*height 33"))
  expect_that(print(d[[1]]),
              prints_text("2 branches.*17 members.*height 32"))
  expect_that(print(d[[2]]),
              prints_text("2 branches.*17 members.*height 30"))
  m2 <- cut_at(fc, no=3)
  expect_that(modularity(g, m2),
              equals(fc$modularity[length(fc$modularity)-2]))
})