File: test_get.shortest.paths.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 (34 lines) | stat: -rw-r--r-- 946 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

context("shortest_paths")

test_that("shortest_paths works", {

  library(igraph)

  edges <- matrix(c("s", "a", 2,
                    "s", "b", 4,
                    "a", "t", 4,
                    "b", "t", 2,
                    "a", "1", 1,
                    "a", "2", 1,
                    "a", "3", 2,
                    "1", "b", 1,
                    "2", "b", 2,
                    "3", "b", 1),
                  byrow=TRUE, ncol=3,
                  dimnames=list(NULL, c("from", "to", "weight")))
  edges <- as.data.frame(edges)
  edges[[3]] <- as.numeric(as.character(edges[[3]]))

  g <- graph_from_data_frame(as.data.frame(edges))

  all1 <- all_shortest_paths(g, "s", "t", weights=NA)$res
  all2 <- all_shortest_paths(g, "s", "t")$res

  s1 <- shortest_paths(g, "s", "t", weights=NA)
  s2 <- get.shortest.paths(g, "s", "t")

  expect_that(s1$vpath %in% all1, is_true()) 
  expect_that(s2$vpath %in% all2, is_true())

})