Skip to content

Commit

Permalink
fix: bfs() no longer pads order with zeros with `igraph_options(r…
Browse files Browse the repository at this point in the history
…eturn.vs.es = FALSE)` (#1124)
  • Loading branch information
aviator-app[bot] authored Jan 20, 2024
2 parents f425694 + 0c07f63 commit ba56d83
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion R/interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ get.edge.ids <- function(
multi = NULL) {
ensure_igraph(graph)

if (lifecycle::is_present(multi)) {
# FIXME: Change to lifecycle::is_present() when using deprecated
if (!is.null(multi)) {
if (isTRUE(multi)) {
lifecycle::deprecate_stop("2.0.0", "get.edge.ids(multi = )")
}
Expand Down
2 changes: 2 additions & 0 deletions R/structural.properties.R
Original file line number Diff line number Diff line change
Expand Up @@ -2149,6 +2149,8 @@ bfs <- function(
if (father) res$father <- create_vs(graph, res$father, na_ok = TRUE)
if (pred) res$pred <- create_vs(graph, res$pred, na_ok = TRUE)
if (succ) res$succ <- create_vs(graph, res$succ, na_ok = TRUE)
} else {
if (order) res$order <- res$order[res$order != 0]
}

if (igraph_opt("add.vertex.names") && is_named(graph)) {
Expand Down
2 changes: 1 addition & 1 deletion man/get.edge.ids.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tests/testthat/test-graph.bfs.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,11 @@ test_that("snapshot test", {
)
})
})

test_that("BFS does not pad order", {
g <- make_star(3)
expect_equal(as.numeric(bfs(g, root = 2, unreachable = FALSE)$order), c(2, 1))

local_igraph_options(return.vs.es = FALSE)
expect_equal(as.numeric(bfs(g, root = 2, unreachable = FALSE)$order), c(2, 1))
})
3 changes: 3 additions & 0 deletions tests/testthat/test-graph.dfs.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ test_that("DFS uses 1-based root vertex index", {
test_that("DFS does not pad order", {
g <- make_star(3)
expect_equal(as.numeric(dfs(g, root = 2, unreachable = FALSE)$order), c(2, 1))

local_igraph_options(return.vs.es = FALSE)
expect_equal(as.numeric(bfs(g, root = 2, unreachable = FALSE)$order), c(2, 1))
})
2 changes: 1 addition & 1 deletion tests/testthat/test-graphNEL.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test_that("graphNEL conversion works", {
if (!requireNamespace("graph", quietly = TRUE)) skip("No graph package")

library(graph, warn.conflicts = FALSE)
suppressPackageStartupMessages(library(graph, warn.conflicts = FALSE))

g <- sample_gnp(100, 5 / 100)
N <- as_graphnel(g)
Expand Down

0 comments on commit ba56d83

Please sign in to comment.