File: test_contract.vertices.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 (24 lines) | stat: -rw-r--r-- 732 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

context("contract")

test_that("contract works", {
  library(igraph)
  set.seed(42)

  g <- make_ring(10)
  g$name <- "Ring"
  V(g)$name <- letters[1:vcount(g)]
  E(g)$weight <- sample(ecount(g))

  g2 <- contract(g, rep(1:5, each=2),
                          vertex.attr.comb=toString)

  ## graph and edge attributes are kept, vertex attributes are
  ## combined using the 'toString' function.
  expect_that(g2$name, equals(g$name))
  expect_that(V(g2)$name, equals(c("a, b", "c, d", "e, f", "g, h", "i, j")))
  expect_that(as.matrix(g2[]),
              is_equivalent_to(cbind(c(10,9,0,0,7), c(9,3,6,0,0),
                                     c(0,6,4,8,0), c(0,0,8,5,1),
                                     c(7,0,0,1,2))))
})