From bce4ecfc9709e7263409d0e281653242ee0eecae Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 1 Dec 2024 09:11:05 +0000 Subject: [PATCH 1/4] Update CITATION.cff --- CITATION.cff | 1 + 1 file changed, 1 insertion(+) diff --git a/CITATION.cff b/CITATION.cff index 0e81598159..b6aa529c41 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -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' From 9d8ffd10275f24540f8e60e173cf50f494c3ce79 Mon Sep 17 00:00:00 2001 From: stibu81 Date: Sun, 1 Dec 2024 10:33:12 +0100 Subject: [PATCH 2/4] test as_adj_list() also for fix_return.vs.es = FALSE --- tests/testthat/test-get.adjlist.R | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/testthat/test-get.adjlist.R b/tests/testthat/test-get.adjlist.R index 7c569726e1..91b79ac666 100644 --- a/tests/testthat/test-get.adjlist.R +++ b/tests/testthat/test-get.adjlist.R @@ -31,3 +31,42 @@ test_that("as_adj_list works", { 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) + 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) + 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) + } +}) From b66ef95cdcdc0d08547de0c543c4576db5d988c4 Mon Sep 17 00:00:00 2001 From: stibu81 Date: Sun, 1 Dec 2024 10:59:07 +0100 Subject: [PATCH 3/4] fix: incident_edges() is now correct if the "return.vs.es" option is FALSE (#1606) --- R/interface.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/interface.R b/R/interface.R index e6b029bc0e..fdae8dcf45 100644 --- a/R/interface.R +++ b/R/interface.R @@ -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)) } From 8ec1c6c70711f8f672ac53c27b49bca509b9574a Mon Sep 17 00:00:00 2001 From: stibu81 Date: Sun, 1 Dec 2024 11:15:45 +0100 Subject: [PATCH 4/4] add/extend tests for neighbors(), adjacent_vertices() and incident_edges() --- tests/testthat/test-get.adjlist.R | 3 ++ tests/testthat/test-interface.R | 61 +++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/tests/testthat/test-get.adjlist.R b/tests/testthat/test-get.adjlist.R index 91b79ac666..f1d1c4b1d3 100644 --- a/tests/testthat/test-get.adjlist.R +++ b/tests/testthat/test-get.adjlist.R @@ -1,6 +1,7 @@ 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, @@ -11,6 +12,7 @@ test_that("as_adj_list works", { #### 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) @@ -40,6 +42,7 @@ test_that("as_adj_list works when return.vs.es is 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, diff --git a/tests/testthat/test-interface.R b/tests/testthat/test-interface.R index 4c60565226..6b0463a1c5 100644 --- a/tests/testthat/test-interface.R +++ b/tests/testthat/test-interface.R @@ -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")))