File: test_degree.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 (27 lines) | stat: -rw-r--r-- 886 bytes parent folder | download | duplicates (4)
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

context("degree")

test_that("degree works", {
  library(igraph)
  
  g <- sample_gnp(100, 1/100)
  d <- degree(g)
  el <- as_edgelist(g)
  expect_that(as.numeric(table(el)), equals(d[d!=0]))

  expect_that(degree(g) / (vcount(g)-1), equals(degree(g, normalized=TRUE)))

  g2 <- sample_gnp(100, 2/100, dir=TRUE)
  din <- degree(g2, mode="in")
  dout <- degree(g2, mode="out")
  el2 <- as_edgelist(g2)
  expect_that(as.numeric(table(el2[,1])), equals(dout[dout!=0]))
  expect_that(as.numeric(table(el2[,2])), equals(din[din!=0]))

  expect_that(degree(g2, mode="in") / (vcount(g2)-1),
              equals(degree(g2, mode="in", normalized=TRUE)))
  expect_that(degree(g2, mode="out") / (vcount(g2)-1),
              equals(degree(g2, mode="out", normalized=TRUE)))
  expect_that(degree(g2, mode="all") / (vcount(g2)-1),
              equals(degree(g2, mode="all", normalized=TRUE)))
})