Skip to content

Commit

Permalink
test: improve add_vertices() tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle authored and aviator-bot committed May 20, 2024
1 parent d070baf commit fd83087
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions tests/testthat/test-add.vertices.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
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)))
nv <- 4
g2 <- add_vertices(g, nv = nv)

expect_equal(vcount(g2), vcount(g) + nv)
expect_equal(ecount(g2), ecount(g))
expect_equal(as_edgelist(g2), 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)))
nv <- 3
names <- c("F", "G", "H")
weights <- 1:3
g3 <- add_vertices(g, nv = nv, attr = list(name = names, weight = weights))

expect_equal(V(g3)$name, c(V(g)$name, names))
expect_equal(V(g3)$weight, c(rep(NA, vcount(g)), weights))
})

0 comments on commit fd83087

Please sign in to comment.