File: test_layout.mds.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 (40 lines) | stat: -rw-r--r-- 798 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

context("layout_with_mds")

test_that("layout_with_mds works", {

  library(igraph)

  ## A tree

  g <- make_tree(10, 2, "undirected")

  mymds <- function(g) { 
    sp <- distances(g)
    sp <- sp * sp
    sp <- sp - rowMeans(sp) - rep(rowMeans(sp), each=nrow(sp)) + mean(sp)
    sp <- sp / -2
    ei <- eigen(sp)
    va <- sqrt(abs(ei$values[1:2]))
    ei$vectors[,1:2] * rep(va, each=nrow(sp))
  }

  expect_that(mymds(g), equals(layout_with_mds(g)))

  ## plot(g, layout=ll)

  ## A graph with multiple components, just test that it runs

  set.seed(42)
  g <- make_ring(10) + make_ring(3)
  expect_that(ncol(layout_with_mds(g)), equals(2))
  
  ## Small stress test

  for (i in 1:10) {
    g <- sample_gnp(100, 2/100)
    l <- layout_with_mds(g)
    expect_that(ncol(l), equals(2))
  }

})