Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ references:
email: dadler@dyncall.org
year: '2024'
doi: 10.32614/CRAN.package.rgl
version: '>= 1.3.14'
- type: software
title: rmarkdown
abstract: 'rmarkdown: Dynamic Documents for R'
Expand Down
2 changes: 1 addition & 1 deletion R/interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,9 @@ incident_edges <- function(graph, v,
on.exit(.Call(R_igraph_finalizer))

res <- .Call(R_igraph_incident_edges, graph, vv, mode)
res <- lapply(res, `+`, 1)

if (igraph_opt("return.vs.es")) {
res <- lapply(res, `+`, 1)
res <- lapply(res, unsafe_create_es, graph = graph, es = E(graph))
}

Expand Down
42 changes: 42 additions & 0 deletions tests/testthat/test-get.adjlist.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
test_that("as_adj_list works", {
g <- sample_gnp(50, 2 / 50)
al <- as_adj_list(g)
expect_s3_class(al[[1]], "igraph.vs")
g2 <- graph_from_adj_list(al, mode = "all")
expect_isomorphic(g, g2)
expect_true(graph.isomorphic.vf2(g, g2,
vertex.color1 = 1:vcount(g),
vertex.color2 = 1:vcount(g2)
)$iso)

####

el <- as_adj_edge_list(g)
expect_s3_class(el[[1]], "igraph.es")
for (i in 1:vcount(g)) {
a <- E(g)[.inc(i)]
expect_equal(length(a), length(el[[i]]), ignore_attr = TRUE)
expect_equal(sort(el[[i]]), sort(a), ignore_attr = TRUE)
}

g <- sample_gnp(50, 4 / 50, directed = TRUE)
el1 <- as_adj_edge_list(g, mode = "out")
el2 <- as_adj_edge_list(g, mode = "in")
for (i in 1:vcount(g)) {
a <- E(g)[.from(i)]
expect_equal(length(a), length(el1[[i]]), ignore_attr = TRUE)
expect_equal(sort(el1[[i]]), sort(a), ignore_attr = TRUE)
}
for (i in 1:vcount(g)) {
a <- E(g)[.to(i)]
expect_equal(length(a), length(el2[[i]]), ignore_attr = TRUE)
expect_equal(sort(el2[[i]]), sort(a), ignore_attr = TRUE)
}
})



test_that("as_adj_list works when return.vs.es is FALSE", {
on.exit(try(igraph_options(old)), add = TRUE)
old <- igraph_options(return.vs.es = FALSE)

g <- sample_gnp(50, 2 / 50)
al <- as_adj_list(g)
expect_s3_class(al[[1]], NA)
g2 <- graph_from_adj_list(al, mode = "all")
expect_isomorphic(g, g2)
expect_true(graph.isomorphic.vf2(g, g2,
Expand Down
61 changes: 61 additions & 0 deletions tests/testthat/test-interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,79 @@ test_that("delete_vertices works", {
test_that("neighbors works", {
g <- sample_gnp(100, 20 / 100)
al <- as_adj_list(g, mode = "all")
expect_s3_class(neighbors(g, v = 1, mode = "out"), "igraph.vs")
for (i in seq_along(al)) {
n <- neighbors(g, v = i, mode = "out")
expect_setequal(sort(n), al[[i]])
}

# test with return.vs.es = FALSE
on.exit(try(igraph_options(old)), add = TRUE)
old <- igraph_options(return.vs.es = FALSE)

al <- as_adj_list(g, mode = "all")
expect_s3_class(neighbors(g, v = 1, mode = "out"), NA)
for (i in seq_along(al)) {
n <- neighbors(g, v = i, mode = "out")
expect_setequal(sort(n), 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")
})


test_that("adjacent_vertices works", {
g <- sample_gnp(100, 20 / 100)
al <- as_adj_list(g, mode = "all")
test_vertices <- c(1, 7, 38, 75, 99)
adj_vertices <- adjacent_vertices(g, v = test_vertices)
expect_s3_class(adj_vertices[[1]], "igraph.vs")
for (i in seq_along(test_vertices)) {
expect_setequal(adj_vertices[[i]], al[[test_vertices[i]]])
}

# test with return.vs.es = FALSE
on.exit(try(igraph_options(old)), add = TRUE)
old <- igraph_options(return.vs.es = FALSE)

al <- as_adj_list(g, mode = "all")
test_vertices <- c(1, 7, 38, 75, 99)
adj_vertices <- adjacent_vertices(g, v = test_vertices)
expect_s3_class(adj_vertices[[1]], NA)
for (i in seq_along(test_vertices)) {
expect_setequal(adj_vertices[[i]], al[[test_vertices[i]]])
}

})


test_that("incident_edges works", {
g <- sample_gnp(100, 20 / 100)
el <- as_adj_edge_list(g, mode = "all")
test_vertices <- c(1, 7, 38, 75, 99)
inc_edges <- incident_edges(g, v = test_vertices)
expect_s3_class(inc_edges[[1]], "igraph.es")
for (i in seq_along(test_vertices)) {
expect_setequal(inc_edges[[i]], el[[test_vertices[i]]])
}

# test with return.vs.es = FALSE
on.exit(try(igraph_options(old)), add = TRUE)
old <- igraph_options(return.vs.es = FALSE)

el <- as_adj_edge_list(g, mode = "all")
test_vertices <- c(1, 7, 38, 75, 99)
inc_edges <- incident_edges(g, v = test_vertices)
expect_s3_class(inc_edges[[1]], NA)
for (i in seq_along(test_vertices)) {
expect_setequal(inc_edges[[i]], el[[test_vertices[i]]])
}
})

test_that("delete_edges works", {
g <- graph_from_literal(A:B:C - D:E:F, D - E - F)
g2 <- delete_edges(g, E(g, P = c("D", "E")))
Expand Down