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))))
})
|