File: test_as.directed.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 (35 lines) | stat: -rw-r--r-- 1,105 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
28
29
30
31
32
33
34
35

context("as.directed")

test_that("as.directed works", {
  library(igraph)
  
  g <- sample_gnp(100, 2/100)
  g2 <- as.directed(g, mode="mutual")
  g3 <- as.directed(g, mode="arbitrary")

  expect_that(degree(g), equals(degree(g3)))
  expect_that(degree(g), equals(degree(g2) / 2))  

  expect_that(graph.isomorphic(g, as.undirected(g2)), is_true())
  expect_that(graph.isomorphic(g, as.undirected(g3)), is_true())
})

test_that("as.directed keeps attributes", {
  library(igraph)
  g <- graph_from_literal( A-B-C, D-A, E )
  g$name <- "Small graph"
  g2 <- as.directed(g, mode="mutual")
  g3 <- as.directed(g, mode="arbitrary")
  expect_that(g2$name, equals(g$name))
  expect_that(V(g2)$name, equals(V(g)$name))
  expect_that(g3$name, equals(g$name))
  expect_that(V(g3)$name, equals(V(g)$name))

  E(g)$weight <- seq_len(ecount(g))
  g4 <- as.directed(g, "mutual") ; df4 <- as_data_frame(g4)  
  g5 <- as.directed(g, "arbitrary") ; df5 <- as_data_frame(g5)
  expect_that(df4[order(df4[,1], df4[,2]),]$weight, equals(c(1,2,1,3,3,2)))
  expect_that(df5[order(df5[,1], df5[,2]),]$weight, equals(1:3))
})