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
|
context("get_diameter")
test_that("get_diameter works", {
library(igraph)
g <- make_ring(10)
E(g)$weight <- sample(seq_len(ecount(g)))
d <- diameter(g)
gd <- get_diameter(g)
sp <- distances(g)
expect_that(d, equals(max(sp)))
expect_that(sp[ gd[1], gd[length(gd)] ], equals(d))
d <- diameter(g, weights=NA)
gd <- get_diameter(g, weights=NA)
sp <- distances(g, weights=NA)
expect_that(d, equals(max(sp)))
length(gd) == d + 1
expect_that(sp[ gd[1], gd[length(gd)] ], equals(d))
})
|