tests/testthat/test-neighbors.R

test_that("neighbors works", {
  g <- sample_gnp(100, 20 / 100)
  al <- as_adj_list(g, mode = "all")
  for (i in 1:length(al)) {
    n <- neighbors(g, i, mode = "out")
    expect_that(sort(n), is_equivalent_to(al[[i]]))
  }
})

test_that("neighbors prints an error for an empty input vector", {
  g <- make_tree(10)
  expect_error(neighbors(g, numeric()), "No vertex was specified")
})

Try the igraph package in your browser

Any scripts or data that you put into this service are public.

igraph documentation built on Aug. 10, 2023, 9:08 a.m.