File: test-efficiency.R

package info (click to toggle)
r-cran-igraph 2.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 27,772 kB
  • sloc: ansic: 206,420; cpp: 21,827; fortran: 4,090; yacc: 1,229; lex: 518; sh: 52; makefile: 8
file content (30 lines) | stat: -rw-r--r-- 1,115 bytes parent folder | download
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
test_that("global_efficiency works", {
  g <- graph_from_literal(A - B - C - D - A)
  expect_equal(global_efficiency(g), 5 / 6)

  g <- graph_from_literal(A -+ B -+ C -+ D -+ A)
  expect_equal(global_efficiency(g), 11 / 18)
  expect_equal(global_efficiency(g, directed = F), 5 / 6)
})

test_that("local_efficiency works", {
  g <- graph_from_literal(A - B - C - D - A)
  expect_equal(as.vector(local_efficiency(g)), rep(0.5, vcount(g)))
  expect_equal(average_local_efficiency(g), mean(local_efficiency(g)))

  g <- graph_from_literal(A -+ B -+ C -+ D -+ A)
  expect_equal(as.vector(local_efficiency(g)), rep(0.25, vcount(g)))
  expect_equal(average_local_efficiency(g), mean(local_efficiency(g)))

  g <- graph_from_literal(A -+ B -+ C -+ D -+ A)
  expect_equal(
    as.vector(local_efficiency(g, directed = F)),
    rep(0.5, vcount(g))
  )
  expect_equal(
    average_local_efficiency(g, directed = F),
    mean(local_efficiency(g, directed = F))
  )
  expect_equal(as.vector(local_efficiency(g, mode = "in")), rep(0, vcount(g)))
  expect_equal(as.vector(local_efficiency(g, mode = "out")), rep(0, vcount(g)))
})