From 0df4c0b83c50cd418a20d06e3720212b52034a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Mon, 23 Sep 2024 11:36:55 +0200 Subject: [PATCH 1/6] test: add tests for `graph_from_biadjacency_matrix()` --- tests/testthat/_snaps/incidence.md | 50 ++++++++++ tests/testthat/test-incidence.R | 141 +++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 tests/testthat/_snaps/incidence.md create mode 100644 tests/testthat/test-incidence.R diff --git a/tests/testthat/_snaps/incidence.md b/tests/testthat/_snaps/incidence.md new file mode 100644 index 0000000000..f9f885bcab --- /dev/null +++ b/tests/testthat/_snaps/incidence.md @@ -0,0 +1,50 @@ +# graph_from_biadjacency_matrix() works -- dense + + Code + (g <- graph_from_biadjacency_matrix(inc)) + Output + IGRAPH UN-B 8 7 -- + + attr: type (v/l), name (v/c) + + edges (vertex names): + [1] A--c A--d B--b B--c B--e C--b C--d + +--- + + Code + (weighted_g <- graph_from_biadjacency_matrix(inc, weighted = TRUE)) + Output + IGRAPH UNWB 8 7 -- + + attr: type (v/l), name (v/c), weight (e/n) + + edges (vertex names): + [1] A--c A--d B--b B--c B--e C--b C--d + +# graph_from_biadjacency_matrix() works -- sparse + + Code + (g <- graph_from_biadjacency_matrix(inc)) + Output + IGRAPH UN-B 8 7 -- + + attr: type (v/l), name (v/c) + + edges (vertex names): + [1] B--b C--b A--c B--c A--d C--d B--e + +--- + + Code + (weighted_g <- graph_from_biadjacency_matrix(inc, weighted = TRUE)) + Output + IGRAPH UNWB 8 7 -- + + attr: type (v/l), name (v/c), weight (e/n) + + edges (vertex names): + [1] B--b C--b A--c B--c A--d C--d B--e + +# graph_from_biadjacency_matrix() works -- sparse + multiple + + Code + (g <- graph_from_biadjacency_matrix(inc, multiple = TRUE)) + Output + IGRAPH UN-B 8 10 -- + + attr: type (v/l), name (v/c) + + edges (vertex names): + [1] B--b C--b A--c C--c C--c A--d A--d A--e B--e C--e + diff --git a/tests/testthat/test-incidence.R b/tests/testthat/test-incidence.R new file mode 100644 index 0000000000..a16b4a65d9 --- /dev/null +++ b/tests/testthat/test-incidence.R @@ -0,0 +1,141 @@ +test_that("graph_from_biadjacency_matrix() works -- dense", { + local_igraph_options(print.id = FALSE) + withr::local_seed(42) + + inc <- matrix(sample(0:1, 15, repl = TRUE), 3, 5) + colnames(inc) <- letters[1:5] + rownames(inc) <- LETTERS[1:3] + + expect_snapshot((g <- graph_from_biadjacency_matrix(inc))) + expect_false(is_weighted(g)) + + expect_snapshot((weighted_g <- graph_from_biadjacency_matrix(inc, weighted = TRUE))) + expect_true(is_weighted(weighted_g)) +}) + +test_that("graph_from_biadjacency_matrix() works - dense, modes", { + local_igraph_options(print.id = FALSE) + withr::local_seed(42) + + inc <- matrix(sample(0:1, 15, repl = TRUE), 3, 5) + colnames(inc) <- letters[1:5] + rownames(inc) <- LETTERS[1:3] + + out_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "out") + expect_true(is_directed(out_g)) + expect_length(E(out_g), 7) + expect_equal(as_adj_list(out_g, mode = "out")$A %>% as.numeric(), c(6, 7)) + + in_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "in") + expect_true(is_directed(in_g)) + expect_length(E(in_g), 7) + expect_equal(as_adj_list(in_g, mode = "in")$A %>% as.numeric(), c(6, 7)) + + total_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "total") + expect_true(is_directed(total_g)) + expect_length(E(total_g), 14) + expect_equal(as_adj_list(total_g, mode = "all")$A %>% as.numeric(), c(6, 6, 7, 7)) +}) + +test_that("graph_from_biadjacency_matrix() works - dense, modes, weighted", { + local_igraph_options(print.id = FALSE) + withr::local_seed(42) + + inc <- matrix(sample(0:1, 15, repl = TRUE), 3, 5) + colnames(inc) <- letters[1:5] + rownames(inc) <- LETTERS[1:3] + + out_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "out", weighted = TRUE) + expect_true(is_directed(out_g)) + expect_length(E(out_g), 7) + expect_equal(as_adj_list(out_g, mode = "out")$A %>% as.numeric(), c(6, 7)) + + in_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "in", weighted = TRUE) + expect_true(is_directed(in_g)) + expect_length(E(in_g), 7) + expect_equal(as_adj_list(in_g, mode = "in")$A %>% as.numeric(), c(6, 7)) + + total_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "total", weighted = TRUE) + expect_true(is_directed(total_g)) + expect_length(E(total_g), 14) + expect_equal(as_adj_list(total_g, mode = "all")$A %>% as.numeric(), c(6, 6, 7, 7)) +}) + +test_that("graph_from_biadjacency_matrix() works -- sparse", { + local_igraph_options(print.id = FALSE) + withr::local_seed(42) + + inc <- matrix(sample(0:1, 15, repl = TRUE), 3, 5) + inc <- Matrix::Matrix(inc, sparse = TRUE) + colnames(inc) <- letters[1:5] + rownames(inc) <- LETTERS[1:3] + + expect_snapshot((g <- graph_from_biadjacency_matrix(inc))) + expect_false(is_weighted(g)) + + expect_snapshot((weighted_g <- graph_from_biadjacency_matrix(inc, weighted = TRUE))) + expect_true(is_weighted(weighted_g)) +}) + +test_that("graph_from_biadjacency_matrix() works -- sparse + multiple", { + local_igraph_options(print.id = FALSE) + withr::local_seed(42) + + inc <- matrix(sample(0:2, 15, repl = TRUE), 3, 5) + inc <- Matrix::Matrix(inc, sparse = TRUE) + colnames(inc) <- letters[1:5] + rownames(inc) <- LETTERS[1:3] + + expect_snapshot((g <- graph_from_biadjacency_matrix(inc, multiple = TRUE))) + expect_false(is_weighted(g)) +}) + +test_that("graph_from_biadjacency_matrix() works - sparse, modes", { + local_igraph_options(print.id = FALSE) + withr::local_seed(42) + + inc <- matrix(sample(0:1, 15, repl = TRUE), 3, 5) + inc <- Matrix::Matrix(inc, sparse = TRUE) + colnames(inc) <- letters[1:5] + rownames(inc) <- LETTERS[1:3] + + out_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "out") + expect_true(is_directed(out_g)) + expect_length(E(out_g), 7) + expect_equal(as_adj_list(out_g, mode = "out")$A %>% as.numeric(), c(6, 7)) + + in_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "in") + expect_true(is_directed(in_g)) + expect_length(E(in_g), 7) + expect_equal(as_adj_list(in_g, mode = "in")$A %>% as.numeric(), c(6, 7)) + + total_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "total") + expect_true(is_directed(total_g)) + expect_length(E(total_g), 14) + expect_equal(as_adj_list(total_g, mode = "all")$A %>% as.numeric(), c(6, 6, 7, 7)) +}) + +test_that("graph_from_biadjacency_matrix() works - sparse, modes, weighted", { + local_igraph_options(print.id = FALSE) + withr::local_seed(42) + + inc <- matrix(sample(0:1, 15, repl = TRUE), 3, 5) + inc <- Matrix::Matrix(inc, sparse = TRUE) + colnames(inc) <- letters[1:5] + rownames(inc) <- LETTERS[1:3] + + out_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "out", weighted= TRUE) + expect_true(is_directed(out_g)) + expect_length(E(out_g), 7) + expect_equal(as_adj_list(out_g, mode = "out")$A %>% as.numeric(), c(6, 7)) + + in_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "in", weighted= TRUE) + expect_true(is_directed(in_g)) + expect_length(E(in_g), 7) + expect_equal(as_adj_list(in_g, mode = "in")$A %>% as.numeric(), c(6, 7)) + + total_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "total", weighted= TRUE) + expect_true(is_directed(total_g)) + expect_length(E(total_g), 14) + expect_equal(as_adj_list(total_g, mode = "all")$A %>% as.numeric(), c(6, 6, 7, 7)) +}) From 5268956bdc1a93aac4ace9b0f2620441e698f738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Mon, 30 Sep 2024 14:56:53 +0200 Subject: [PATCH 2/6] refactor: move weighted argument handling to graph_from_biadjacency_matrix() + improve error message --- R/incidence.R | 30 ++++++++++++++++++------------ tests/testthat/_snaps/incidence.md | 18 ++++++++++++++++++ tests/testthat/test-incidence.R | 13 +++++++++++++ 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/R/incidence.R b/R/incidence.R index 0cc7716b93..6471af0a38 100644 --- a/R/incidence.R +++ b/R/incidence.R @@ -45,12 +45,6 @@ graph.incidence.sparse <- function(incidence, directed, mode, multiple, el[, 2] <- el[, 2] + n1 if (!is.null(weighted)) { - if (is.logical(weighted) && weighted) { - weighted <- "weight" - } - if (!is.character(weighted)) { - stop("invalid value supplied for `weighted' argument, please see docs.") - } if (!directed || mode == 1) { ## nothing do to @@ -92,12 +86,6 @@ graph.incidence.sparse <- function(incidence, directed, mode, multiple, graph.incidence.dense <- function(incidence, directed, mode, multiple, weighted) { if (!is.null(weighted)) { - if (is.logical(weighted) && weighted) { - weighted <- "weight" - } - if (!is.character(weighted)) { - stop("invalid value supplied for `weighted' argument, please see docs.") - } n1 <- nrow(incidence) n2 <- ncol(incidence) @@ -228,6 +216,24 @@ graph_from_biadjacency_matrix <- function(incidence, directed = FALSE, ) multiple <- as.logical(multiple) + if (!is.null(weighted)) { + if (is.logical(weighted) && weighted) { + weighted <- "weight" + } + if (is.logical(weighted) && !weighted) { + cli::cli_abort(c( + "{.arg weighted} can't be {.code FALSE}.", + i = "See {.help graph_from_biadjacency_matrix}'s manual page." + )) + } + if (!is.character(weighted)) { + cli::cli_abort(c( + "{.arg weighted} can't be {.obj_type_friendly {weighted}}.", + i = "See {.help graph_from_biadjacency_matrix}'s manual page." + )) + } + } + if (inherits(incidence, "Matrix")) { res <- graph.incidence.sparse(incidence, directed = directed, diff --git a/tests/testthat/_snaps/incidence.md b/tests/testthat/_snaps/incidence.md index f9f885bcab..5422ec0170 100644 --- a/tests/testthat/_snaps/incidence.md +++ b/tests/testthat/_snaps/incidence.md @@ -48,3 +48,21 @@ + edges (vertex names): [1] B--b C--b A--c C--c C--c A--d A--d A--e B--e C--e +# graph_from_biadjacency_matrix() errors well + + Code + (g <- graph_from_biadjacency_matrix(inc, weight = FALSE)) + Condition + Error in `graph_from_biadjacency_matrix()`: + ! `weighted` can't be `FALSE`. + i See `?graph_from_biadjacency_matrix()`'s manual page. + +--- + + Code + (g <- graph_from_biadjacency_matrix(inc, weight = 42)) + Condition + Error in `graph_from_biadjacency_matrix()`: + ! `weighted` can't be a number. + i See `?graph_from_biadjacency_matrix()`'s manual page. + diff --git a/tests/testthat/test-incidence.R b/tests/testthat/test-incidence.R index a16b4a65d9..6842f45887 100644 --- a/tests/testthat/test-incidence.R +++ b/tests/testthat/test-incidence.R @@ -139,3 +139,16 @@ test_that("graph_from_biadjacency_matrix() works - sparse, modes, weighted", { expect_length(E(total_g), 14) expect_equal(as_adj_list(total_g, mode = "all")$A %>% as.numeric(), c(6, 6, 7, 7)) }) + +test_that("graph_from_biadjacency_matrix() errors well", { + inc <- matrix(sample(0:1, 15, repl = TRUE), 3, 5) + colnames(inc) <- letters[1:5] + rownames(inc) <- LETTERS[1:3] + + expect_snapshot(error= TRUE, { + (g <- graph_from_biadjacency_matrix(inc, weight = FALSE)) + }) + expect_snapshot(error = TRUE, { + (g <- graph_from_biadjacency_matrix(inc, weight = 42)) + }) +}) From b03e24a1d7e0f775ad0f05c347856bfa0530b0fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 1 Oct 2024 13:50:38 +0200 Subject: [PATCH 3/6] test: use naming and argument value as advised by @szhorvat --- tests/testthat/test-incidence.R | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/testthat/test-incidence.R b/tests/testthat/test-incidence.R index 6842f45887..3fb67b274d 100644 --- a/tests/testthat/test-incidence.R +++ b/tests/testthat/test-incidence.R @@ -31,10 +31,10 @@ test_that("graph_from_biadjacency_matrix() works - dense, modes", { expect_length(E(in_g), 7) expect_equal(as_adj_list(in_g, mode = "in")$A %>% as.numeric(), c(6, 7)) - total_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "total") - expect_true(is_directed(total_g)) - expect_length(E(total_g), 14) - expect_equal(as_adj_list(total_g, mode = "all")$A %>% as.numeric(), c(6, 6, 7, 7)) + mutual_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "all") + expect_true(is_directed(mutual_g)) + expect_length(E(mutual_g), 14) + expect_equal(as_adj_list(mutual_g, mode = "all")$A %>% as.numeric(), c(6, 6, 7, 7)) }) test_that("graph_from_biadjacency_matrix() works - dense, modes, weighted", { @@ -55,10 +55,10 @@ test_that("graph_from_biadjacency_matrix() works - dense, modes, weighted", { expect_length(E(in_g), 7) expect_equal(as_adj_list(in_g, mode = "in")$A %>% as.numeric(), c(6, 7)) - total_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "total", weighted = TRUE) - expect_true(is_directed(total_g)) - expect_length(E(total_g), 14) - expect_equal(as_adj_list(total_g, mode = "all")$A %>% as.numeric(), c(6, 6, 7, 7)) + mutual_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "all", weighted = TRUE) + expect_true(is_directed(mutual_g)) + expect_length(E(mutual_g), 14) + expect_equal(as_adj_list(mutual_g, mode = "all")$A %>% as.numeric(), c(6, 6, 7, 7)) }) test_that("graph_from_biadjacency_matrix() works -- sparse", { @@ -109,10 +109,10 @@ test_that("graph_from_biadjacency_matrix() works - sparse, modes", { expect_length(E(in_g), 7) expect_equal(as_adj_list(in_g, mode = "in")$A %>% as.numeric(), c(6, 7)) - total_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "total") - expect_true(is_directed(total_g)) - expect_length(E(total_g), 14) - expect_equal(as_adj_list(total_g, mode = "all")$A %>% as.numeric(), c(6, 6, 7, 7)) + mutual_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "all") + expect_true(is_directed(mutual_g)) + expect_length(E(mutual_g), 14) + expect_equal(as_adj_list(mutual_g, mode = "all")$A %>% as.numeric(), c(6, 6, 7, 7)) }) test_that("graph_from_biadjacency_matrix() works - sparse, modes, weighted", { @@ -134,10 +134,10 @@ test_that("graph_from_biadjacency_matrix() works - sparse, modes, weighted", { expect_length(E(in_g), 7) expect_equal(as_adj_list(in_g, mode = "in")$A %>% as.numeric(), c(6, 7)) - total_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "total", weighted= TRUE) - expect_true(is_directed(total_g)) - expect_length(E(total_g), 14) - expect_equal(as_adj_list(total_g, mode = "all")$A %>% as.numeric(), c(6, 6, 7, 7)) + mutual_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "all", weighted= TRUE) + expect_true(is_directed(mutual_g)) + expect_length(E(mutual_g), 14) + expect_equal(as_adj_list(mutual_g, mode = "all")$A %>% as.numeric(), c(6, 6, 7, 7)) }) test_that("graph_from_biadjacency_matrix() errors well", { From ce249b217f7ff263c741fd6d85992a486c331e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 1 Oct 2024 13:54:12 +0200 Subject: [PATCH 4/6] test: use more diverse weights as advised by @szhorvat --- tests/testthat/test-incidence.R | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/testthat/test-incidence.R b/tests/testthat/test-incidence.R index 3fb67b274d..2bfbbf6f7b 100644 --- a/tests/testthat/test-incidence.R +++ b/tests/testthat/test-incidence.R @@ -41,24 +41,24 @@ test_that("graph_from_biadjacency_matrix() works - dense, modes, weighted", { local_igraph_options(print.id = FALSE) withr::local_seed(42) - inc <- matrix(sample(0:1, 15, repl = TRUE), 3, 5) + inc <- matrix(sample(0:2, 15, repl = TRUE), 3, 5) colnames(inc) <- letters[1:5] rownames(inc) <- LETTERS[1:3] out_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "out", weighted = TRUE) expect_true(is_directed(out_g)) - expect_length(E(out_g), 7) - expect_equal(as_adj_list(out_g, mode = "out")$A %>% as.numeric(), c(6, 7)) + expect_length(E(out_g), 8) + expect_equal(as_adj_list(out_g, mode = "out")$A %>% as.numeric(), c(6, 7, 8)) in_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "in", weighted = TRUE) expect_true(is_directed(in_g)) - expect_length(E(in_g), 7) - expect_equal(as_adj_list(in_g, mode = "in")$A %>% as.numeric(), c(6, 7)) + expect_length(E(in_g), 8) + expect_equal(as_adj_list(in_g, mode = "in")$A %>% as.numeric(), c(6, 7, 8)) mutual_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "all", weighted = TRUE) expect_true(is_directed(mutual_g)) - expect_length(E(mutual_g), 14) - expect_equal(as_adj_list(mutual_g, mode = "all")$A %>% as.numeric(), c(6, 6, 7, 7)) + expect_length(E(mutual_g), 16) + expect_equal(as_adj_list(mutual_g, mode = "all")$A %>% as.numeric(), c(6, 6, 7, 7, 8, 8)) }) test_that("graph_from_biadjacency_matrix() works -- sparse", { From 44bd8f4a4a9cf340b217161d824a3098eac57f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 1 Oct 2024 13:58:37 +0200 Subject: [PATCH 5/6] test: add test case for dense+multiple --- tests/testthat/_snaps/incidence.md | 10 ++++++++++ tests/testthat/test-incidence.R | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/tests/testthat/_snaps/incidence.md b/tests/testthat/_snaps/incidence.md index 5422ec0170..ed8636ccef 100644 --- a/tests/testthat/_snaps/incidence.md +++ b/tests/testthat/_snaps/incidence.md @@ -18,6 +18,16 @@ + edges (vertex names): [1] A--c A--d B--b B--c B--e C--b C--d +# graph_from_biadjacency_matrix() works -- dense + multiple + + Code + (g <- graph_from_biadjacency_matrix(inc, multiple = TRUE)) + Output + IGRAPH UN-B 8 10 -- + + attr: type (v/l), name (v/c) + + edges (vertex names): + [1] A--c A--d A--d A--e B--b B--e C--b C--c C--c C--e + # graph_from_biadjacency_matrix() works -- sparse Code diff --git a/tests/testthat/test-incidence.R b/tests/testthat/test-incidence.R index 2bfbbf6f7b..73d0efaff5 100644 --- a/tests/testthat/test-incidence.R +++ b/tests/testthat/test-incidence.R @@ -13,6 +13,20 @@ test_that("graph_from_biadjacency_matrix() works -- dense", { expect_true(is_weighted(weighted_g)) }) + +test_that("graph_from_biadjacency_matrix() works -- dense + multiple", { + local_igraph_options(print.id = FALSE) + withr::local_seed(42) + + inc <- matrix(sample(0:2, 15, repl = TRUE), 3, 5) + colnames(inc) <- letters[1:5] + rownames(inc) <- LETTERS[1:3] + + expect_snapshot((g <- graph_from_biadjacency_matrix(inc, multiple = TRUE))) + expect_false(is_weighted(g)) +}) + + test_that("graph_from_biadjacency_matrix() works - dense, modes", { local_igraph_options(print.id = FALSE) withr::local_seed(42) From be6845beaa503b06a192f7275c39a48454221781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 1 Oct 2024 14:28:12 +0200 Subject: [PATCH 6/6] feat: add error when both `graph_from_biadjacency()`'s arguments `multiple` and `weighted` are TRUE --- R/incidence.R | 7 +++++++ tests/testthat/_snaps/incidence.md | 9 +++++++++ tests/testthat/test-incidence.R | 3 +++ 3 files changed, 19 insertions(+) diff --git a/R/incidence.R b/R/incidence.R index 6471af0a38..49120ba4dd 100644 --- a/R/incidence.R +++ b/R/incidence.R @@ -218,6 +218,13 @@ graph_from_biadjacency_matrix <- function(incidence, directed = FALSE, if (!is.null(weighted)) { if (is.logical(weighted) && weighted) { + + if (multiple) { + cli::cli_abort(c( + "{.arg multiple} and {.arg weighted} cannot be both {.code TRUE}.", + "igraph either interprets numbers larger than 1 as weights or as multiplicities, but it cannot be both." + )) + } weighted <- "weight" } if (is.logical(weighted) && !weighted) { diff --git a/tests/testthat/_snaps/incidence.md b/tests/testthat/_snaps/incidence.md index ed8636ccef..b15badd95f 100644 --- a/tests/testthat/_snaps/incidence.md +++ b/tests/testthat/_snaps/incidence.md @@ -76,3 +76,12 @@ ! `weighted` can't be a number. i See `?graph_from_biadjacency_matrix()`'s manual page. +--- + + Code + (g <- graph_from_biadjacency_matrix(inc, multiple = TRUE, weighted = TRUE)) + Condition + Error in `graph_from_biadjacency_matrix()`: + ! `multiple` and `weighted` cannot be both `TRUE`. + igraph either interprets numbers larger than 1 as weights or as multiplicities, but it cannot be both. + diff --git a/tests/testthat/test-incidence.R b/tests/testthat/test-incidence.R index 73d0efaff5..7b871739e1 100644 --- a/tests/testthat/test-incidence.R +++ b/tests/testthat/test-incidence.R @@ -165,4 +165,7 @@ test_that("graph_from_biadjacency_matrix() errors well", { expect_snapshot(error = TRUE, { (g <- graph_from_biadjacency_matrix(inc, weight = 42)) }) + expect_snapshot(error = TRUE, { + (g <- graph_from_biadjacency_matrix(inc, multiple = TRUE, weighted = TRUE)) + }) })