File: test_decompose.graph.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 (44 lines) | stat: -rw-r--r-- 1,229 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44

context("decompose")

test_that("decompose works", {
  library(igraph)
  g <- sample_gnp(1000, 1/1500)
  G <- decompose(g)
  clu <- components(g)
  Gsizes <- sapply(G, vcount)
  expect_that(sort(clu$csize), equals(sort(Gsizes)))
})

test_that("decompose works for many components", {
  library(igraph)
  g <- make_empty_graph(50001)
  tmp <- decompose(g)
  expect_that(1, equals(1))
})

test_that("decompose works for many components and attributes", {
  library(igraph)
  g <- make_empty_graph(50001)
  V(g)$name <- 1:vcount(g)
  tmp <- decompose(g)
  expect_that(1, equals(1))
})

test_that("decompose keeps attributes", {
  library(igraph)
  g <- make_ring(10) + make_ring(5)
  V(g)$name <- letters[1:(10+5)]
  E(g)$name <- apply(as_edgelist(g), 1, paste, collapse="-")
  d <- decompose(g)
  d <- d[order(sapply(d, vcount))]

  expect_that(length(d), equals(2))
  expect_that(sapply(d, vcount), equals(c(5,10)))
  expect_that(V(d[[1]])$name, equals(letters[1:5+10]))
  expect_that(V(d[[2]])$name, equals(letters[1:10]))
  e1 <- apply(as_edgelist(d[[1]]), 1, paste, collapse="-")
  e2 <- apply(as_edgelist(d[[2]]), 1, paste, collapse="-")
  expect_that(E(d[[1]])$name, equals(e1))
  expect_that(E(d[[2]])$name, equals(e2))
})