1
2context("get_diameter")
3
4test_that("get_diameter works", {
5
6  library(igraph)
7
8  g <- make_ring(10)
9  E(g)$weight <- sample(seq_len(ecount(g)))
10  d <- diameter(g)
11  gd <- get_diameter(g)
12  sp <- distances(g)
13
14  expect_that(d, equals(max(sp)))
15  expect_that(sp[ gd[1], gd[length(gd)] ], equals(d))
16
17  d <- diameter(g, weights=NA)
18  gd <- get_diameter(g, weights=NA)
19  sp <- distances(g, weights=NA)
20
21  expect_that(d, equals(max(sp)))
22  length(gd) == d + 1
23  expect_that(sp[ gd[1], gd[length(gd)] ], equals(d))
24})
25
26