tests/testthat/test-add.vertices.R

test_that("add_vertices works", {
  g <- graph_from_literal(A - B - C - D - E)
  g2 <- add_vertices(g, (nv <- 4))
  expect_that(vcount(g2), equals(vcount(g) + nv))
  expect_that(ecount(g2), equals(ecount(g)))
  expect_that(as_edgelist(g2), equals(as_edgelist(g)))
})

test_that("add_vertices handles attributes properly", {
  g <- graph_from_literal(A - B - C - D - E)
  g3 <- add_vertices(g, (nv <- 3),
    attr = list(
      name = (names <- c("F", "G", "H")),
      weight = weights <- 1:3
    )
  )
  expect_that(V(g3)$name, equals(c(V(g)$name, names)))
  expect_that(V(g3)$weight, equals(c(rep(NA, vcount(g)), weights)))
})

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.